# babel: adding language shorthands to work inside glossaries

I added ngerman shorthands to my english babel as described here. But they do not work for glossaries, and probably in other macors as discussed here. I load all the acronyms as a separate file in the preamble.

Example:

\documentclass[a4paper,12pt]{report}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}

\makeatletter
\initiate@active@char{"}
\declare@shorthand{english}{"~}{\textormath{\leavevmode\hbox{-}}{-}}
\makeatother

\usepackage[acronym,shortcuts]{glossaries}
\makeglossaries
\newacronym{CP-OFDM}{CP"~OFDM}{Cyclic Prefix OFDM}

\begin{document}
CP"~OFDM \\
\acs{CP-OFDM}
\end{document}


How can I solve the problem for acronyms? One solution is to move them inside the main text, after \begin{document}.

-
Babel shorthands are enabled only after \begin{document}. Just say \AtBeginDocument{\input{file}} instead of \input{file} (where file.tex contains the acronym definitions). –  egreg Feb 19 '13 at 10:11
Thanks @egreg, it solves the problem. –  Aydin Feb 19 '13 at 10:48
If the only language is english, you can use "user shorthands" with \useshorthands{"} and \defineshorthand{"~}{...}, which is much simpler. –  Javier Bezos Feb 19 '13 at 15:49

There are other questions in the site that cover similar problems

but this one raises a different problem.

As explained in the second linked question, shorthands are enabled only after \begin{document} and babel has good reasons to do this.

However, a long list of acronyms after \begin{document} would pollute the document and you're right when thinking that they are best placed in the preamble.

A solution might be

\shorthandon{"}
<list of acronyms>
\shorthandoff{"}


and the list can also be put in a file myacronyms.tex so that the above becomes

\shorthandon{"}
\input{myacronyms}
\shorthandoff{"}


However, there's a better solution for this setup:

\AtBeginDocument{\input{myacronyms}}


will load the file after the shorthands are enabled, while the instruction is still in the preamble.

If you use the \shorthandon way, enable all shorthand prefixes you need. Here you find a list of shorthands for the various languages.

-
If you use the \AtBeginDocument approach, you'll need to put it before you load glossaries to avoid the generation of the .glsdefs file. (Otherwise the glossary/acronym definitions will occur after \newglossaryentry changes its behaviour.) –  Nicola Talbot Mar 14 '14 at 15:42