1

This does not compile, but I do not understand why:

\newenvironment{italicquote}{%
  \begin{quotation}\textit{%
}{%
  }\end{quotation}
}
2
  • Thanks, Don. I pasted the code as you edited it, but then it changed.
    – russ
    Commented Jun 2, 2021 at 5:22
  • You need to select the code and click the {} button to format it as a code block.
    – Don Hosek
    Commented Jun 2, 2021 at 5:42

1 Answer 1

1

The problem that you're running into is that your braces aren't matching correctly. Here's what you have if we rearrange things to show where the braces are:

\newenvironment{italicquote}
{%
  \begin{quotation}\textit{%
                          }
  {%
  }
  \end{quotation}
}

Oops, there's only two arguments being given to \newenvironment instead of three. That's why it doesn't compile.

So how do we fix this? There are two options:

One is that we can use \bgroup and \egroup which give us a mechanism for putting unbalanced braces into definitions. This makes your environment definition into:

\newenvironment{italicquote}{%
  \begin{quotation}\textit\bgroup
}{%
  \egroup\end{quotation}
}

Another option is to use \NewDocumentEnvironment¹ instead of \newenvironment to define the environment. With this, we can use the +bargument specifier to pass the entirety of theitalicquoteenvironment as an argument. The+indicates that we should allow it to have paragraphs in it. When we use+bwe usually leave the definition of the\end` command empty since everything can be done in the begin:

\NewDocumentEnvironment{italicquote}{ +b }{%
  \begin{quotation}
    \textit{#1}
  \end{quotation}
}{}

This does have the limitation that since we're taking the contents of the environment as an argument, we can't have, e.g., \verb inside the environment, although we couldn't do that with our first version either since the \verb would be passed in the argument to \textit.

So, what if we wanted to have the environment able to have \verb in it². Then we could use \itshape³ to select the italic shape. Since environments are in groups, the \itshape will go away at the end of the environment on its own. This gives us a clean definition of:

\NewDocumentEnvironment{italicquote}{}{%
  \begin{quotation}\itshape
}{%
  \end{quotation}%
}

I'm still not happy with this though. After all, italicquote isn't really a semantic markup concept and I probably would like to just have all my quotation environments in italic.

We could redefine quotation (and if you look through some of my other answers, you'll see some examination of how you could do that), but better still is to use LaTeX's hooks mechanism. We can use the env/quotation/begin hook to add the \itshape command to format the environment body. This would look like:

\AddToHook{env/quotation/begin}{\itshape}

and we get all of our quotation environments typeset in italics.


  1. In general, we should prefer \NewDocumentEnvironment over \newenvironment and \NewDocumentCommand over \newcommand.

  2. Or some other catcode-changing command. I'm not sure if the +b thing would break, e.g., \url. I suppose I could try it but it's late and I really should be sleeping instead of writing this.

  3. \textit{} is essentially the same as {\itshape\/} where \/ adds an italic correction at the end of the font change. Other than different semantics, the output is identical.

4
  • Adding \AddToHook{env/quotation/begin}{\itshape} to the .cls file causes an undefined control sequence error.
    – russ
    Commented Jun 2, 2021 at 19:29
  • \NewDocumentEnvironment{italicquote}{}{% \begin{quotation}\itshape }{% \end{quotation}% } solved the problem, when the empty set of {} are removed and newenvironment is used instead of NewDocumentEnvironment.
    – russ
    Commented Jun 2, 2021 at 20:09
  • Based on the errors that you report, it sounds like you have an older version of LaTeX on your system.
    – Don Hosek
    Commented Jun 3, 2021 at 3:01
  • TeXLive on Debian 10.
    – russ
    Commented Jun 3, 2021 at 4:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .