5

The packages environ and newenviron both provide an alternative to the standard environment macros included with LaTeX. The main difference is that they make it possible to refer to the environment body using a macro, but another difference is that macro expansion is affected. If it weren't for this effect the only other thing these packages would seem to be good for is when you need to refer to an environment body multiple times. Are there any other uses for being able to refer to the environment body by macro?

  • 2
    Any time when you want to be able to manipulate the contents of the environment body or gain information about it before typesetting (cf align and friends and the measuring business for example) – clemens Jul 10 '15 at 8:28
  • Or want to apply something that is intrinsically taking an argument to the body of a macro: \uppercase for example. – Joseph Wright Jul 10 '15 at 9:21
  • Is this supposed to be a 'big-list'? – Ruben Jul 10 '15 at 10:13
2

You can for instance measure the environment body and perform different things depending on this measurments:

\documentclass{article}
\usepackage{newenviron,lipsum}
\newdimen\hkBstheight
\newenviron{hkBstEnv}{%
  \setbox0=\vbox{\hkBstEnvbody}
  \hkBstheight=\ht0
  \advance\hkBstheight by \dp0
  \ifdim\hkBstheight<200pt
    {\itshape\hkBstEnvbody}
  \else
    \hkBstEnvbody
  \fi
}

\begin{document}
\begin{hkBstEnv}
  \lipsum[1]
\end{hkBstEnv}

\begin{hkBstEnv}
  \lipsum[1-2]
\end{hkBstEnv}
\end{document}

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.