I have this document:
\documentclass{report}
\usepackage[english, spanish]{babel}
\begin{document}
\selectlanguage{english}
\section*{Hello, world!}
This is a document written in English.
\selectlanguage{spanish}
\section*{¡Hola, mundo!}
Este es un documento escrito en español.
\end{document}
And I execute this command to generate a PDF for Spanish:
pdflatex -jobname=manual-es "\AtBeginDocument{\selectlanguage{spanish}}" manual.tex
but I get the following error:
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (MiKTeX 22.10) (preloaded format=pdflatex.fmt)
restricted \write18 enabled.
entering extended mode
LaTeX2e <2022-06-01> patch level 5
L3 programming layer <2022-09-28>
! LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
<> \AtBeginDocument{\selectlanguage{spanish}} m
anual.tex
? return
OK, entering \nonstopmode...
Missing character: There is no m in font nullfont!
Missing character: There is no a in font nullfont!
Missing character: There is no n in font nullfont!
Missing character: There is no u in font nullfont!
Missing character: There is no a in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no . in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no x in font nullfont!
! Emergency stop.
<> ...cument{\selectlanguage{spanish}} manual.tex
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on manual-es.log.
pdflatex: major issue: So far, you have not checked for MiKTeX updates.
Does anyone know why this might happen?
Thank you in advance.
pdflatex -jobname=.\out\manual-english "\AtBeginDocument{\selectlanguage{english}}\input{manual}"
– Alex Segura Feb 17 '23 at 15:54