# babel + hyperref: »redefining shorthand« several times per page

consider the following code:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{hyperref}
\usepackage{blindtext}

\begin{document}
\Blindtext\Blindtext\Blindtext
\Blindtext\Blindtext\Blindtext
\end{document}


...and a small piece from its logfile.

[3]
Package babel Info: Redefining ngerman shorthand "|
(babel)             in language  on input line 7.
Package babel Info: Redefining ngerman shorthand "~
(babel)             in language  on input line 7.
Package babel Info: Redefining ngerman shorthand "|
(babel)             in language  on input line 7.
Package babel Info: Redefining ngerman shorthand "~
(babel)             in language  on input line 7.
Package babel Info: Redefining ngerman shorthand "|
(babel)             in language  on input line 7.
Package babel Info: Redefining ngerman shorthand "~
(babel)             in language  on input line 7.


babel seems to redefine these shorthands several times per page, even when there's nothing but plain text (why does it do so?). This happens only if hyperref is active. Half of that logfile consists of nothing but iterations of these lines. Obviously, it's even worse in the 350-page document that I'm currently working on, making troubleshooting a real pain in the neck. Is there a way to prevent this bloating?

• Unfortunately, the silence package doesn't provide for silencing Info messages. – egreg Jul 26 '14 at 12:58
• no even disabling hyperref'ing with draft mode silences it :( – Nils L Jul 26 '14 at 13:46

The info comes from \pdfstringdef, which is used to convert a TeX string to a PDF bookmark string. \pdfstringdef redefines many, many commands to disable them, to provide replacements. Thus hyperref also redefines some shorthands. For example, TeX's hyphenation is irrelevant for bookmarks, thus hyperref redefines the shorthands for ngerman regarding hyphenation:

\declare@shorthand{ngerman}{"|}{}%
\declare@shorthand{ngerman}{"~}{-}%


Two info messages are generated, each time \pdfstringdef is invoked with \usepackage[ngerman]{babel}. This happens for \section and friends and some other occasions (setting of PDF information entries).

• The babel shorthand macro "| is not so much about hyphenation as it is about ligature suppression. Does the disabling of this macro in PDF bookmarks mean that words such as auf"|fliegen will get typeset with an ffl ligature in the bookmarks? Or is it the case that ligatures are disabled anyway in bookmarks and hence that it's not necessary to suppress them in the first place? – Mico Jul 26 '14 at 13:27
• The TeX setting engine is not available for bookmarks. Ligatures are a property of the TFM (TeX Font Metrics) data. But the bookmark strings are just simple text strings without any font setting. If you want to have a ligature, you have to set it explicitly (with Unicode encoding). – Heiko Oberdiek Jul 26 '14 at 13:41
• @HeikoOberdiek Wouldn't disable \bbl@info when doing \pdfstringdef be a good idea? – egreg Jul 26 '14 at 14:07
• @NilsL This includes the page number, which is displayed as PDF page label, a plain PDF string without TeX typesetting. Regarding optimization: Some of hyperref's features can be disabled, use of package hyperref can be removed. Plain TeX instead of LaTeX can be used, At last, you get a very fast processing time without any text and contents. – Heiko Oberdiek Jul 28 '14 at 15:28
• > without any text and contents ...that's what I've been trying to convince my PhD supervisor of for ages! Good to hear I'm not the only one thinking that's a good idea :) – Nils L Jul 28 '14 at 19:11

Once you know that such information is irrelevant (and it is), you can use gentle manners (also known as “the sledgehammer”) to silence it:

\documentclass{article}
\usepackage[ngerman]{babel}

\usepackage{lipsum}
\usepackage{etoolbox}

\usepackage{hyperref}

\makeatletter
\patchcmd{\@decl@short}{\bbl@info}{\@gobble}{}{}
\patchcmd{\@decl@short}{\bbl@info}{\@gobble}{}{}
\makeatother

\begin{document}
\lipsum[1-40]
\end{document}


No more Redefining ngerman shorthand message.

A more delicate patch would be

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{lipsum}
\usepackage{etoolbox}

\usepackage{hyperref}

\makeatletter
\patchcmd{\pdfstringdef}
{\csname HyPsd@babel@}
{\let\bbl@info\@gobble\csname HyPsd@babel@}
{}{}
\makeatother

\begin{document}
\lipsum[1-40]

\end{document}


that would disable \bbl@info (when redefining shorthands) only in the context of \pdfstringdef.

• This is a relief! These messages were driving me crazy :-) – Thomas F. Sturm Jul 29 '14 at 8:03
• @ThomasF.Sturm Another strategy is giving up writing in German. ;-) – egreg Jul 29 '14 at 8:05
• With all that package documenting in English, I think I'm approximating to that final goal ;-) – Thomas F. Sturm Jul 29 '14 at 8:11
• works great; just reduced my log file from 10000 to 2000 lines. Thanks! – Nils L Jul 29 '14 at 8:42