I have a quite complex code where I need to repeat a few lines (consisting of commands, for simplification here in MWE only a few words). In the MWE for printing the same as above in italic. The number of lines to be repeated changes from case to case, so the command should use two other commands (here \begin{document}
and \newpage
) as parameters for guidance. Can someone help me with this? Thanks a lot already!
\documentclass{article}
\begin{document}
\LaTeX
Hi
Ciao
Bonjour
Hallo
Servus
\LaTeX
\newpage
\textit{
%Here should be a command to reapeat everything between \begin{document} and \newpage to be printed in italic
}
\end{document}
Best Answer
You can use
NewEnviron
to capture the content with the\BODY
macro and reuse it. The two pages appear as:There is also
\NewDocumentEnvironment
fromxparse
, but that is currently marked as experimental:This is yielding "Argument of \environment MyRepeatingEnvironment has an extra }", but don't exactly know why.
Code: