# LaTeX letter: undefined control sequence on \opening command

I'm trying to use the \opening{} command in a LaTeX letter but getting an undefined control sequence error on it for some obscure reason.

Minimal working example:

\documentclass[11pt]{letter}
\begin{document}

Dear John,

%Letter goes here

\end{document}


And minimal not-working example:

\documentclass[11pt]{letter}
\begin{document}

\opening{Dear John,}

%Letter goes here

\end{document}


Note that for some reason the \closing{} command (not included above) works just fine. I'm using TexMaker and compiling with PdfLaTeX (but LaTeX + dvips + ps2pdf doesn't work any better).

Any clue what's going on?

• You have to enclose the letter text in the environment letter that takes as argument the addressee. – egreg Jul 9 '17 at 10:49
• Well that was quick an on point, thank you! – Alexko Jul 9 '17 at 10:51
• I got the same error compiling a rather complex template with scrlttr2 on a freshly installed machine. It turned out, that I had undefined commands in the document structure (I commented out a package I thought which was unused, but it was actually in use). Long story short, please be aware that this error message can be misleading and not really related to the \opening, but rather to contents of the cascade that is triggered by the \opening command. – MP Felder Jan 28 at 8:16

Many thanks to egreg for the quick answer, which is that the letter needs to be enclosed in a \begin{letter} … \end{letter} block, that I stupidly missed. Here's the working code:

\documentclass[11pt]{letter}

\begin{document}

\begin{letter}{}
\opening{Dear Johnny,}

%Letter goes here

\end{letter}
\end{document}