While playing around with TeX, I came across a strange error. This is my input file:

\def\hello{Hello World.\par}

\twice{\hello} % works
\twice{Hello World. } % works
\twice{Hello World.\par} % doesn't work

When I compile this with pdftex, I get this error:

Runaway argument?
{Hello World.
! Paragraph ended before \twice was complete.
<to be read again> 
l.6 \twice{Hello World.\par
                           } % doesn't work
!  ==> Fatal error occurred, no output PDF file produced!

If I remove the line \twice{Hello World.\par}, compilation succeeds and I get the expected output.

Why does \twice{\hello} work but \twice{Hello World.\par} not work?

Will the general technique of changing \someMacro{someText\par} to \def\defText{someText\par} \def\someMacro{\defText} always work? Is there an alternative that can help me not define a macro for every paragraph that I want to use as a parameter to some macro?

  • 4
    If you want to define a command which accepts a \par as argument, use \long\def. Sep 14 '20 at 20:42

To avoid a missing } causing your entire document to be swallowed searching for the end of an argument, buy default \par (or a blank line) is not allowed in a macro argument. If you want to define a command that allows multiple paragraphs in the argument, use \long\def rather than \def.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.