3

Consider the following LaTeX file:

\documentclass[12pt]{scrlttr2}
\begin{document}
\begin{letter}{}
  \opening{}
\closing{}
\end{letter}
\end{document}

I get the error

LaTeX Error: There's no line here to end.

Why does this error happen, exactly? It goes away if I add something, anything, to the address field, i.e. the second arg of \begin{letter}. For example \phantom{} makes the error go away.

I'm looking for a detailed analysis, which I hope I will learn something from.

2
  • 1
    If the address field should be empty use option addrfield=false: \begin{letter}[addrfield=false]{}. If all letters in the document should have empty address fields, then you could use \documentclass[addrfield=false]{scrlttr2} or \KOMAoptions{addrfield=false}. – esdd Jan 27 at 17:58
  • @esdd Thanks. That's very helpful. I didn't know there was such an option. – Faheem Mitha Jan 28 at 8:23
5

the error comes from \\ if there is no text before it ("no line to end") so presumably this class is using \\ after the address. \mbox{} probably the simplest thing that is an invisible text

To see more add

\errorcontextlines=100

then your document produces the error

! LaTeX Error: There's no line here to end.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
\GenericError  ...                                
                                                  \endgroup 
\\->\ifhmode \unskip \else \@nolnerr 
                                     \fi \par \@ifstar {\nobreak \@xcentercr...
<argument> ...font {toname}{\usekomavar {toname}\\
                                                  }}{\usekomafont {toaddress...

\\@savevbox ...4#5#6->\begingroup \vbox to #2{#1#3
                                                  }\if@savevbox@warning \@sa...

\rlap  #1->\hb@xt@ \z@ {#1
                          \hss }
<argument> ...MessageBreak \string \specialmail }}
                                                  }
\vb@t@z ...x \z@ \vbox to\z@ {\color@begingroup #1
                                                  \color@endgroup \vss }\set...

\@addrfield ...sageBreak \string \specialmail }}}}
                                                  \vskip -\useplength {toadd...

\opening ...arks \@firstheadfootfield \@addrfield 
                                                  \@locfield \ifdim \useplen...
l.5   \opening{}
                
? 

Within the error stack you see the call

\usekomavar {toname}\\

which is adding \\ after toname which will fail if that is empty.

2

The reason for the error message are explained in the other answers, so my answer is a bit off topic.

To avoid the error message you have to use option addressfield=false. For a single letter this option can be set for the letter environment itself

\begin{letter}[addrfield=false]{}

or using\KOMAoptions or \KOMAOption before \opening:

\begin{letter}{}
\KOMAoptions{addrfield=false}% or \KOMAoption{addrfield}{false}
\opening{}

If all letters in the document should have empty address fields, then you can set addrfield=false while loading the class

\documentclass[addrfield=false]{scrlttr2}

or using \KOMAoptions or \KOMAOption in the preamble.

You could also patch the letter environment to set addrfield=false automatically if the argument is empty (ie. no space etc.):

\documentclass[12pt]{scrlttr2}
\usepackage{xpatch}
\xpretocmd{\letter}{\IfArgIsEmpty{#2}{\KOMAoptions{addrfield=false}}{}}{}{\PatchFailed}

\begin{document}
\begin{letter}{}
%\setkomavar{toname}{Bar}
%\setkomavar{toaddress}{Bar Address}
  \opening{}
\closing{}
\end{letter}
\begin{letter}{Foo\\Foo Address}
  \opening{}
\closing{}
\end{letter}
\end{document}

But then there will be no address field even if the variables toname and toaddress are not empty. Note that these variables can be set in the preamble, outside the letter environment or between \begin{letter}{} and \opening.

1
  • Thank you, that's very useful information. – Faheem Mitha Feb 5 at 18:37

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.