1

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{"}
\addto\extrasenglish{\languageshorthands{english}\bbl@activate{"}}
\addto\noextrasenglish{\bbl@deactivate{"}}
\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{"}
\addto\extrasamerican{\languageshorthands{american}\bbl@activate{"}}
\addto\noextrasamerican{\bbl@deactivate{"}}
\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{"}
\addto\extrasusenglish{\languageshorthands{usenglish}\bbl@activate{"}}
\addto\noextrasusenglish{\bbl@deactivate{"}}
\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{"}
\addto\extrasenglish{\languageshorthands{english}\bbl@activate{"}}
\addto\noextrasenglish{\bbl@deactivate{"}}
\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{"}
\addto\extrasamerican{\languageshorthands{american}\bbl@activate{"}}
\addto\noextrasamerican{\bbl@deactivate{"}}
\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{"}
\addto\extrasusenglish{\languageshorthands{usenglish}\bbl@activate{"}}
\addto\noextrasusenglish{\bbl@deactivate{"}}
\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}
1
  • Better use the 'public' interface to define shorthands, with \defineshorthand. See sec. 1.10 in the manual. Apr 11, 2019 at 17:01

1 Answer 1

2

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}


\addto\extrasUSenglish{\languageshorthands{ngerman}\useshorthands{"}}

\begin{document}

\begin{frame}

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

\end{frame}

\end{document}
3
  • 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, 2019 at 11:26
  • @egreg you are right, I hadn't checked if \noextrasngerman deactivates shorthands`. How do we sort this? I don't want the wrong answer to stay as it is. Should I correct it, or do you want to add an answer and I delete mine? Jul 9, 2019 at 10:52
  • @UlrikeFischer Oh sorry, we had a concurrency problem here. I took the liberty and have already corrected the answer. IMHO, the answer should be corrected to avoid spreading erroneous solutions. (You cannot see the correction yet, as it is still under peer-review.)
    – nagmat84
    Jul 9, 2019 at 11:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .