Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Under certain conditions (triggered by selection of a package option) I would like to change specific environments into margin notes. However marginnote is not itself an environment, but a command that takes its contents as an argument. So what I want to do is replace

\begin{someenvironment}
...
\end{someenvironment}

with

\marginnote{
...
}

but I clearly cannot do this with something like

\renewenvironment{someenvironment}
    {\marginnote{ }
    { }}

What is the correct way to replace an environment with a command that takes the environment's contents as an argument?

share|improve this question

1 Answer 1

up vote 10 down vote accepted

The environ package may be of help here. You define an environment using

\NewEnviron{<env>}{%
  % environment contents
}

and the contents of the environment is available in the macro \BODY. Here's a minimal example:

enter image description here

\documentclass{article}
\usepackage{marginnote}% http://ctan.org/pkg/marginnote
\usepackage{environ}% http://ctan.org/pkg/environ
\NewEnviron{someenvironment}{%
  \marginnote{\BODY}% Place contents of <someenvironment> in a \marginnote
}
\begin{document}
Here is some text with a margin note.
\begin{someenvironment}
This is a margin note.
\end{someenvironment}
\end{document}
​

\NewEnviron has a macro-like look to it, so the usage should be fairly intuitive.

share|improve this answer
    
Thanks, that worked, thigh it ended up begin a bit more complicated in my case. I'm redefining an already defined environment, and end up with a lot of floats, so I had to \usepackage[maxfloats=36]{morefloats} and \let\existingenv ... \NewEnviron{existingenv}.... –  raxacoricofallapatorius Feb 21 '12 at 22:25

Your Answer

 
discard

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.