I want to obtain a text surrounded with begin and end commands, as the following.

Here any text is written.

\surroundedtext % this command is replaced with "Here any text is written."

Of course, the object is accomplished if I define \begincommand so that it takes an argument.

\begincommand{Here any text is written.}

But, I don't want to use braces. Please let me know if you have the solution.


Assuming Plain TeX, you can define

\long\def\begincommand#1 \endcommand{...}

but this will force you to write

Text to be stored

with \endcommand on a line by itself or

Text to be stored \endcommand

with a space between the last word and \endcommand (but no empty line before \encommand). Alternatively, you can define


and then do something about the possible final space when \endcommand is on a line by itself. One should know the context, in order to give better advice.

If you're using LaTeX, this is not good programming style. If what you're looking for is an environment form for a "definition", then the environ package suggested by Leo Liu is handy, but poses some challenges for defining a command that uses the environment's body to be used subsequently.



Thus the code

Text to be stored

will be equivalent to

\newcommand{\surroundedtext}{<pre>Text to be stored<post>}

Add whatever you need in place of <pre> and <post>

  • 1
    @skymountain: I think it's a bad LaTeX-style. Either you work with \begin{}..\end{} or a single command. – Marco Daniel Feb 14 '12 at 16:36
  • @MarcoDaniel That's why I said "Assuming Plain TeX". – egreg Feb 14 '12 at 16:39
  • 1
    @egreg: I wasn't able to interpret it in this way ;-) – Marco Daniel Feb 14 '12 at 18:37
  • @MacroDaniel Hmm... you mean that I should adopt Leo's solution "generally"? – skymountain Feb 14 '12 at 18:44
  • @skymountain MarcoDaniel is right. See edited version. – egreg Feb 14 '12 at 19:03

You can see the implementation of LaTeX package environ, or just use this package.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.