16

Can you specify the natural language of a PDF compiled with pdflatex? This Tingtun Accessibility checker doesn't like my PDFs because this isn't set. This page calls it the " /Lang entry in the document catalog of a PDF" and describes how to change it in Adobe Acrobat. But it would be nice to set this automatically at compile time. I would imagine that there is a setting to pass to hyperref to set the natural language, but I haven't found it yet.

1
  • Interesting link! Thanks a lot. I tested my actual document and it had two errors. The natural language you mentioned and---surprise---inconsistent headers and footers. I used KOMA-Script scrbook and its default headers. I couldn't find any mistake. Quite stunning!
    – Jan
    Dec 4, 2019 at 8:08

2 Answers 2

21

The following document passes the test that you linked. It should be obvious from the example how to set the language.

\documentclass{article}

\usepackage{hyperref}
\hypersetup{
  pdftitle={Test},
  pdflang={en-US}, % PDF language identifier (RFC 3066)
}

\begin{document}

\section{foobar}

\end{document}

If for some reason you cannot use hyperref, you can also modify the PDF catalog by hand using

\pdfcatalog{/Lang (en-US)}

None of the above is sufficient if you want to generate truly accessible PDF. All it does it shutting up this particular checker.

2
  • Outdated answer. At least the second part needs clarification since it can have adverse effects.
    – tanGIS
    Jun 24, 2020 at 7:53
  • I suggested an edit to correct your answer. Since it got rejected I posted a new answer. After the edit it is not wrong anymore but still outdated so it does not deserve a high rank.
    – tanGIS
    Jun 24, 2020 at 18:07
4

The Answer of Henri Menke is outdated as of 2020.

There is now a more elegant way of setting the language through usage of package hyperxmp:

\documentclass{article}

\usepackage{hyperref}
\usepackage[english]{babel}
\usepackage{hyperxmp}[2020/06/15]

\title{Test}

\begin{document}

\section{foobar}

\end{document}

Instead of babel you can also use

\usepackage{polyglossia}
\setdefaultlanguage[variant=US]{english}

The advantage of the hyperxmp method is that it avoids a mismatch between the language in the metadata and the language used for formatting the text. Also since almost everybody uses either babel or polyglossia the code is shorter.

Do not use \pdfcatalog{/Lang (en-US)} since this method does not write XMP metadata. Some readers relying on it may not work properly. Furthermore, \pdfcatalog will only contain the main language whereas XMP will contain all major languages. If you do not want hyperlinks use the NoHyper environment.

9
  • ! Package babel Error: Unknown key for locale 'USenglish' with TeX Live 2020. Should I downvote now? Jun 24, 2020 at 8:35
  • @HenriMenke you shouldn't downvote because this babel/Texlive issue that has nothing to do with the answer. The example works well in MikTeX and it's how it's supposed to work according to the babel documentation. Just use another language to test.
    – tanGIS
    Jun 24, 2020 at 18:11
  • So outdated answers should be downvoted even though they were correct at the time of writing, but answers that are manifestly wrong because they produce errors deserve upvotes. Thanks for explaining the site to me. I'll go ahead and downvote 50% of TeX.SX now. Jun 24, 2020 at 23:07
  • 1
    @HenriMenke You are welcome. SE is about answers not about egos. For TeX Live users: There is a confirmed bug in babel. Use american instead or polyglossia. I am sure Javier from babel will resolve this quickly.
    – tanGIS
    Jun 25, 2020 at 13:59
  • The issue in babel is resolved in 3.46. So it should work with Linux as well now.
    – tanGIS
    Jul 13, 2020 at 5:52

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.