0

The answer 969/29410 showed that it is possible to use optional arguments in environment definitions:

\documentclass{article}
\newenvironment{hello}[1][world]{\noindent Hello #1, }{Bye now!\\}
\begin{document}
\begin{hello}[Bob]\end{hello}
\end{document}

This works fine and produces

Hello Bob, Bye now!

Why is it that the optional argument cannot be used in the closing statement?

\documentclass{article}
\newenvironment{hello}[1][world]{\noindent Hello, }{Bye now, #1!\\}
\begin{document}
\begin{hello}[Bob]\end{hello}
\end{document}

line 2: Illegal parameter number in definition of \endhello. ...][world]{\noindent Hello, }{Bye now, #1!\}

line 4: You can't use `macro parameter character #' in horizontal mode. \begin{hello}[Bob]\end{hello}

line 4: Underfull \hbox (badness 10000) in paragraph

Betohaku
  • 1,637

0 Answers0