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

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

so that when I do

My Text Here

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.

  • 1
    What do you want to go into the \marginnote? – StrongBad Feb 2 '16 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 '16 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 – Jon Warneke Feb 2 '16 at 22:50

You can capture the contents of an environment using environ:

enter image description here



  % <some stuff here>
  % <other stuff here>


Here is some text.
My Text Here.  
Here is some more text.

| improve this answer | |
  • 1
    \ignorespacesafterend shouldn't be necessary – egreg Feb 2 '16 at 23:21
  • @egreg: In this context, or in general? – Werner Feb 2 '16 at 23:31
  • 1
    With \NewEnviron. I believe it's explained in the manual. – egreg Feb 2 '16 at 23:35
  • @egreg: I see now; there is a default [<final code>] set. – Werner Feb 2 '16 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.