Runaway-argument error message when line break occurs inside argument of a macro
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.
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:
- 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. - 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}