# How to avoid subsection recolouring in amsart?

In the amsart package the text after the subsection continues at the same line as the subsection title. I want to put some coloured text just after the subsection. Here is my example:

\documentclass{amsart}

\usepackage{xcolor}

\title{War and Peace}
\author{Leo Tolstoy}

\begin{document}
\maketitle
\section{Book One: 1805}

\subsection{Chapter 1}

{
\color{blue}
Well, Prince, so Genoa and Lucca are now just family estates of the
Buonapartes. But I warn you, if you don't tell me that this means war, if you
still try to defend the infamies and horrors perpetrated by that Antichrist --- I
really believe he is Antichrist --- I will have nothing more to do with you and you
are no longer my friend, no longer my faithful slave', as you call yourself!
But how do you do? I see I have frightened you --- sit down and tell me all the
news.''
}

It was in July, 1805, and the speaker was the well-known Anna Pavlovna Scherer,
maid of honor and favorite of the Empress Marya Fedorovna. With these words she
greeted Prince Vasili Kuragin, a man of high rank and importance, who was the
first to arrive at her reception. Anna Pavlovna had had a cough for some days.
She was, as she said, suffering from la grippe; grippe being then a new word in
St. Petersburg, used only by the elite.
\end{document}


I want first, some coloured text, and then switch back to normal one. However, the text in the braces is parsed as some additional argument of the \subsection command which implies that the subsection is also coloured. I tried putting additional braces before the coloured region but that doesn't help.

Does anyone know an elegant way to avoid this?

• Could you use \textcolor{blue}{…} instead? – David Purton Jul 26 '18 at 14:00
• This works, thank you! I didn't know about this command – Sergey Dovgal Jul 26 '18 at 14:01
• Does it work with other type of content (equations, tables) as well? – Sergey Dovgal Jul 26 '18 at 14:02
• I'm not exactly sure what you mean. But sometimes the LaTeX colour stack can get confused (for reasons I don't really understand), but using \textcolor often works when \color doesn't. – David Purton Jul 26 '18 at 14:04
• @DavidPurton do you want to post as an answer? basically it works as \textcolor does \leavevmode{\color.... so the section heading is inserted as the paragraph starts before the color, unlike with \color which starts blue before the heading is inserted into the paragraph – David Carlisle Jul 26 '18 at 14:07

Use \leavevmode. \textcolor works in your example too, but won't like if if there is a new paragraph in the argument.

\documentclass{amsart}

\usepackage{xcolor}

\title{War and Peace}
\author{Leo Tolstoy}

\begin{document}
\maketitle
\section{Book One: 1805}

\subsection{Chapter 1}

{\leavevmode\color{blue}%
Well, Prince, so Genoa and Lucca are now just family estates of the
Buonapartes. But I warn you, if you don't tell me that this means war, if you
still try to defend the infamies and horrors perpetrated by that Antichrist --- I
really believe he is Antichrist --- I will have nothing more to do with you and you
are no longer my friend, no longer my faithful slave', as you call yourself!
But how do you do? I see I have frightened you --- sit down and tell me all the
news.''
}

It was in July, 1805, and the speaker was the well-known Anna Pavlovna Scherer,
maid of honor and favorite of the Empress Marya Fedorovna. With these words she
greeted Prince Vasili Kuragin, a man of high rank and importance, who was the
first to arrive at her reception. Anna Pavlovna had had a cough for some days.
She was, as she said, suffering from la grippe; grippe being then a new word in
St. Petersburg, used only by the elite.
\end{document}


• I accept this answer, as it has a more complete explanation on how \leavevmode works. I don't completely understand what it is, but there also seems to be a discussion here about that – Sergey Dovgal Jul 27 '18 at 9:14

Using \textcolor{blue}{…} instead of \color{blue} produces the desired output:

\documentclass{amsart}
\usepackage{xcolor}
\begin{document}
\subsection{Chapter 1}

\textcolor{blue}{Blue text.}

Black text.
\end{document}


The reason is that inline section titles are not typeset immediately, but only when the next paragraph starts; the paragraph starts with

Well


where the first backquote is the trigger that's put momentarily aside; only at that time TeX inserts the remembered section title and typesets the paragraph starting again from the set aside backquote. When this happens, the color has already been set to blue, so also the title appears in blue. With \textcolor this doesn't happen because \textcolor issues \leavevmode that triggers the start of the paragraph before setting the current color to blue.