4

I'm defining a command for placing figures in the margin. A simple version follows:

\documentclass{article}
\newcommand{\margin}[1]{\marginpar{#1}}
\begin{document}
\margin{Figure goes here}
\end{document}

However, I'd like to make this command an environment, like so:

\documentclass{article}
\newenvironment{margin}{\marginpar{}{}}
\begin{document}
\begin{margin}
Figure goes here
\end{margin}
\end{document}

Here I'm naïvely using marginpar{ as my start code and } as my end code. But these braces end up getting paired with the braces used to delimit newenvironment's arguments, so I get an error.

How should I make this environment?

  • 1
    See the environ package, it is made for gathering the contents of an env into a macro – daleif Oct 30 '15 at 19:03
7

You can use the environ package like this:

\documentclass{article}
\usepackage{environ}
\NewEnviron{margin}{\marginpar{\BODY}}
\begin{document}
\begin{margin}
Figure goes here
\end{margin}
\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.