Babel shorthands not working with beamer class (quotation mark not recognized as active character)

For the German language the babel package defines a set of shorthand commands that I use quite often. They all start with a quotation mark (") which is redefined as an active character. In detail, I'm talking about these commands:

1. - a visible hyphen that defines a break point and prohibits other break points. (This is the usual (La)TeX hyphen not a special from Babel.)
2. "= a visible hyphen that defines a break point and still allows other break points. (A very convinient alternative to 1.)
3. "~ a visible hyphen that must not be used as a break point, like in Mess"~, Schätz"~ und Testergebnisse
4. \- a conditional hyphen that defines a break point and prohibits other break points. (This is the usual conditional (La)TeX hyphen not a special from Babel.)
5. "- a conditional hyphen that defines a break point and still allows other break points. (A very convinient alternative to 4. and/or the \hyphentation-command.)
6. "" a zero-width space that defines a break point. Example: (Mess"~)""Ergebnis

As they are very handy, I also like to use them, if the document language is English. To this end I usually define these shorthands myself in the preamble:

\makeatletter
\initiate@active@char{"}
\declare@shorthand{english}{"-}{\nobreak\-\bbl@allowhyphens}
\declare@shorthand{english}{"|}{\textormath{\penalty\@M\discretionary{-}{}{\kern.03em}\allowhyphens}{}}
\declare@shorthand{english}{""}{\hskip\z@skip}
\declare@shorthand{english}{"~}{\textormath{\leavevmode\hbox{-}}{-}}
\declare@shorthand{english}{"=}{\penalty\@M-\hskip\z@skip}
\initiate@active@char{"}
\declare@shorthand{american}{"-}{\nobreak\-\bbl@allowhyphens}
\declare@shorthand{american}{"|}{\textormath{\penalty\@M\discretionary{-}{}{\kern.03em}\allowhyphens}{}}
\declare@shorthand{american}{""}{\hskip\z@skip}
\declare@shorthand{american}{"~}{\textormath{\leavevmode\hbox{-}}{-}}
\declare@shorthand{american}{"=}{\penalty\@M-\hskip\z@skip}
\initiate@active@char{"}
\declare@shorthand{usenglish}{"-}{\nobreak\-\bbl@allowhyphens}
\declare@shorthand{usenglish}{"|}{\textormath{\penalty\@M\discretionary{-}}{\kern.03em}\allowhyphens}{}}
\declare@shorthand{usenglish}{""}{\hskip\z@skip}
\declare@shorthand{usenglish}{"~}{\textormath{\leavevmode\hbox{-}}{-}}
\declare@shorthand{usenglish}{"=}{\penalty\@M-\hskip\z@skip}
\makeatother


The code above is essentially a copy of what Babel does for the German language. This works as expected if the document class is article, report, book and so on.

But it does not work with the beamer class. With beamer the quotation mark is not recognized as an active character but printed as is. Why?

MWE:

\documentclass[american]{beamer}

\usepackage[TS1,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,USenglish,main=USenglish]{babel}

\makeatletter
\initiate@active@char{"}
\declare@shorthand{english}{"-}{\nobreak\-\bbl@allowhyphens}
\declare@shorthand{english}{"|}{\textormath{\penalty\@M\discretionary{-}{}{\kern.03em}\allowhyphens}{}}
\declare@shorthand{english}{""}{\hskip\z@skip}
\declare@shorthand{english}{"~}{\textormath{\leavevmode\hbox{-}}{-}}
\declare@shorthand{english}{"=}{\penalty\@M-\hskip\z@skip}
\initiate@active@char{"}
\declare@shorthand{american}{"-}{\nobreak\-\bbl@allowhyphens}
\declare@shorthand{american}{"|}{\textormath{\penalty\@M\discretionary{-}{}{\kern.03em}\allowhyphens}{}}
\declare@shorthand{american}{""}{\hskip\z@skip}
\declare@shorthand{american}{"~}{\textormath{\leavevmode\hbox{-}}{-}}
\declare@shorthand{american}{"=}{\penalty\@M-\hskip\z@skip}
\initiate@active@char{"}
\declare@shorthand{usenglish}{"-}{\nobreak\-\bbl@allowhyphens}
\declare@shorthand{usenglish}{"|}{\textormath{\penalty\@M\discretionary{-}{}{\kern.03em}\allowhyphens}{}}
\declare@shorthand{usenglish}{""}{\hskip\z@skip}
\declare@shorthand{usenglish}{"~}{\textormath{\leavevmode\hbox{-}}{-}}
\declare@shorthand{usenglish}{"=}{\penalty\@M-\hskip\z@skip}
\makeatother

\begin{document}

\begin{frame}

\begin{itemize}
\item (sub"~)""protocols
\end{itemize}

\end{frame}

\end{document}

• Better use the 'public' interface to define shorthands, with \defineshorthand. See sec. 1.10 in the manual. – Javier Bezos Apr 11 at 17:01

If I change in your code to book it doesn't work either. Beside this: if you load the ngerman language too, you can simply add the shorthands with \languageshorthands:

\documentclass{beamer}

\usepackage[TS1,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman,english,main=USenglish]{babel}

\useshorthands{"}

\begin{document}

\begin{frame}

\begin{itemize}
\item (sub"~)""protocols
\end{itemize}

\end{frame}

\end{document}

• It does not explain the original problem, why the quotation mark (") is not recognized as an active character, but this answer solves the problem. In addition, it is much cleaner, needs less code and uses the "public" interface. – nagmat84 Apr 15 at 11:26