6

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
  • 1
    See the environ package, it is made for gathering the contents of an env into a macro
    – daleif
    Oct 30, 2015 at 19:03

1 Answer 1

9

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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .