TransWikia.com

Using parameters in newenvironment

TeX - LaTeX Asked by cento18 on April 8, 2021

Is there any way to use parameters of the structure newenvironment{example}[]{}{} after the text between the begin{example} and the end{example}.
For example, how do I write a new environment that takes as a parameter the author of a text and write it AFTER the text written in the environment?

One Answer

EDIT: changed the formatting to match specification from comment.

There are two ways to do this, either, with the command newenvironment you can store the argument inside a temporary macro (using def or renewcommand, but initialising it beforehand with newcommand in either case). Or you use NewDocumentEnvironment, in which you can refer to the parameters in the end-part:

documentclass[]{article}

newcommand*exampleARG{}% to assert the name is free
newenvironment{example}[1]
  {%
    parmedskip
    defexampleARG{#1}%
    begingroup
      centering
      itshape
      footnotesize
  }
  {%
      par
    endgroup
    leavevmodehfillmbox{textsc{exampleARG}}par
    medskip
  }

NewDocumentEnvironment{Example}{m}
  {%
    parmedskip
    begingroup
      centering
      itshape
      footnotesize
  }
  {%
      par
    endgroup
    leavevmodehfillmbox{textsc{#1}}par
    medskip
  }

usepackage[]{duckuments}

begin{document}
begin{example}{a wise duck}
  blindduck
end{example}

begin{Example}{a wise duck}
  blindduck
end{Example}
end{document}

Answered by Skillmon on April 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP