# Runaway-argument error message when line break occurs inside argument of a macro

I'm having trouble with my \newcommand when I have a linebreak inside the argument, it is defined as:

\documentclass{report}
\newcommand{\noblablabla}[2]{\textbf{#1}-#2}
\begin{document}

\noblablabla{aaaabbbb}{xxxx} % this is OK

\noblablabla{aaaa

bbbb}{xxxx}
\end{document}


The first call is OK, the second call gives me the Runaway argument error and the result is the following:

 bbbb}{xxxx}
% ^^ up here "Runaway argument"


When I espected some thing like

• \textbf forwards its argument to \text@command, which is declared as a short macro, so it can't contain a \par in its argument. You can circumvent this by using \endgraf instead of the two consecutive newlines, but I don't think it is a good idea and you should change your macro if you want to have a newline there. – Skillmon Sep 18 at 7:36
• And welcome to TeX.SX! – Skillmon Sep 18 at 7:36
• Thanks Skillmon, kind of you. I am not used to 'low level' tricks like you are commenting. How should I change my macro to get the right result? Can you gime some directions to undestand its limitations? How can I start to study it? – LucasT Sep 18 at 7:38
• Change \textbf{#1} to {\bfseries #1}. Why? \bfseries can handle paragraph breaks -- recall that an all-blank input line generates a paragraph break -- in its scope, whereas \textbf can not. – Mico Sep 18 at 7:53
• @LucasT important to note is that there is a slight difference in {<fontswitch> #1} to <textcommand>{#1}, the former doesn't apply any italic correction whereas the latter would (though this shouldn't be an issue for \textbf, it could for \textit). – Skillmon Sep 18 at 8:10

As suggested in comments, \textbf is designed for short things --- not paragraphs. You can just change to a font-selection command:

\documentclass{report}
\newcommand{\noblablabla}[2]{{\bfseries #1\/}-#2}
\begin{document}

\noblablabla{aaaabbbb}{xxxx} % this is OK

\noblablabla{aaaa

bbbb}{xxxx}
% no more "Runaway argument"
\end{document}


...look carefully at the { placement ;-).

The \/ will perform italic correction if necessary (shouldn't be necessary with a bold typeface, but it is font-dependent); thanks to @Skillmon for pointing it out.

• @Mico sorry, I posted the answer before seeing your comment... – Rmano Sep 18 at 7:55
• No worries! Anyway, providing a standalone answer is considered better form anyway. – Mico Sep 18 at 8:10

When (La)TeX reads and tokenizes input under standard catcode-régime with standard-value for the integer-parameter \endlinechar, two consecutive endline-characters—in the .tex-input file they yield an empty line—get tokenized as the token \par which usually serves for ending the current paragraph (and having (La)TeX start a new paragraph in case material which triggers switching to horizontal mode follows).

In (La)TeX macros come in two flavours:

1. Macros where the token \par is allowed in the arguments. These are so-called "long macros" because when you wish to define such a macro by means of TeX primitives like \def or \edef or \gdef or \xdef, you need to add the prefix \long to the definition-primitive in use.
2. Macros where the token \par is not allowed in the arguments. Many people call them "short macros" because when defining them you omit the \long-prefix. When an argument of a short macro contains the token \par, then you get an error-message about "Runaway argument?... Paragraph ended before ... was complete".

\textbf is defined to call such a such a "short" macro whose name is \text@command, and to pass its argument as argument to that macro. Therefore the error message. You can easily circumvent that message by not having the token \par within the argument and instead having, e.g., the token sequence \csname par\endcsname in the argument, or the token \myparcopy after \let\myparcopy=\par:

\documentclass{report}
\newcommand{\noblablabla}[2]{\textbf{#1}-#2}
\begin{document}

\noblablabla{aaaabbbb}{xxxx} % this is OK

\noblablabla{aaaa\csname par\endcsname bbbb}{xxxx}
\end{document}

\documentclass{report}
\newcommand\myparcopy{}%
\newcommand{\noblablabla}[2]{\textbf{#1}-#2}
\begin{document}

\noblablabla{aaaabbbb}{xxxx} % this is OK

\let\myparcopy=\par
\noblablabla{aaaa\myparcopy bbbb}{xxxx}
\end{document}

• LaTeX and Plain already have a \myparcopy under the name \endgraf – Phelype Oleinik Sep 18 at 23:44
• @PhelypeOleinik The reason why I didn't suggest \endgraf is: \endgraf is intended to be a copy of the primitive \par while the \long-mechanism aims at the control word token token \par regardless its meaning. So \endgraf as \parcopy is possible only as long as \par still has the meaning of the primitive. You can redefine \par, e.g., to expand to "I should have my socks stuffed, but my UNIVAC has no app for that" and with a macro not defined in terms of \long you still get runaway argument errors in case of one of its arguments containing the token \par. – Ulrich Diez Sep 19 at 18:25
• Well, yes, you are right of course. However if a user redefines \par like that then they probably know what they're doing ;-) But yes, your reasoning is more cautious. – Phelype Oleinik Sep 19 at 18:55
• @PhelypeOleinik I should have placed the \myparcopy-assignment right before \noblablabla, not into the preamble. I don't know what I was thinking there. In any case I would redefine \par only in ways where the last thing carried out is \endgraf. ;-) – Ulrich Diez Sep 19 at 20:46