TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 8 down vote accepted

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>

share|improve this answer
Thank you. It's very nice solution. – skymountain Feb 14 '12 at 16:02
@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
@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

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


share|improve this answer
Great, thank you! – skymountain Feb 14 '12 at 15:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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