6

I use pdflatex to create a bunch of personalised documents. From a list of names I generate tex files for each John and Jane Doe of the form:

\newcommand{\firstname}{John}
\newcommand{\lastname}{Doe}
\input{thedocument.tex}

and then simply run pdflatex on each resulting tex file.

However, I'm experiencing encoding problems with this approach if the people are for example Jöhn and Jäne and their names will come out as Jhn and Jne, respectively.

I don't know how to fix this.

  • file johndoe.tex says TeX document, ISO-8859 text, with no line terminators
  • file thedocument.tex says LaTeX 2e document, ISO-8859 text

In thedocument.tex I have a line \usepackage[latin1]{inputenc}. I tried it with the utf8 option but then pdflatex fails at the first not ascii character in thedocument.tex. I tried a few other options; every latinN results in broken names and everything else results in pdflatex failing.

As all the other special characters in thedocument.tex work and the file types seem identical, I'm guessing that my problem has to do with \firstname and \lastname being specified before \documentclass. Could that be the case? How can I fix this?

  • 2
    Generate \documentclass and \usepackage[latin1]{inputenc} in the beginning of johndoe.tex and remove them from thedocument.tex. – Stephan Lehmke Nov 19 '13 at 13:57
11
\RequirePackage[utf8]{inputenc}
\newcommand{\firstname}{Jöhn}
\newcommand{\lastname}{Jäne }
\input{thedocument.tex}

where utf8 has to match the encoding used. Use latin1 if the file is in ISO-8859-1.

Then don't load \usepackage{inputenc} in the main document, or load it with the same option.

  • Works, thanks! Painfully obvious solution. :-( – Bananguin Nov 19 '13 at 18:07

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.