4

I'm trying to make a new environment that uses marginnote like so:

\newenvironment{myname}
{ <some stuff> \marginnote{ }
{ } <other stuff> }

so that when I do

\begin{myname}
My Text Here
\end{myname}

I will see "My Text Here" in a marginnote.

The code, written as I have it, won't work though, since we have these awkward open and close braces for marginnote inside of the open/close braces for the code to be executed at the beginning/end of the new environment. Thanks for the help.

3
  • 1
    What do you want to go into the \marginnote?
    – StrongBad
    Feb 2, 2016 at 21:28
  • What's the purpose of the environment at all? What is somestuff supposed to do? Grabbing the environment body is no option here, I think. Perhaps an argument to the environment is of more use
    – user31729
    Feb 2, 2016 at 21:29
  • I'd like to put into the margin some Python code using the minted package. I'll be doing this over and over again with custom options, hence the desire for a new environment Feb 2, 2016 at 22:50

1 Answer 1

4

You can capture the contents of an environment using environ:

enter image description here

\documentclass{article}

\usepackage{environ,marginnote}

\NewEnviron{myenv}{%
  % <some stuff here>
  \marginnote{\BODY}%
  % <other stuff here>
}

\begin{document}

Here is some text.
\begin{myenv}
My Text Here.  
\end{myenv}
Here is some more text.

\end{document}
4
  • 1
    \ignorespacesafterend shouldn't be necessary
    – egreg
    Feb 2, 2016 at 23:21
  • @egreg: In this context, or in general?
    – Werner
    Feb 2, 2016 at 23:31
  • 1
    With \NewEnviron. I believe it's explained in the manual.
    – egreg
    Feb 2, 2016 at 23:35
  • @egreg: I see now; there is a default [<final code>] set.
    – Werner
    Feb 2, 2016 at 23:59

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.