26

The (n)german language option of the babel package provides various shorthands related to hyphenation, e.g. "-: "an explicit hyphen sign, allowing hyphenation in the rest of the word" (manual, section 22). At least some of these shorthands are also useful for English texts -- e.g., typing zoning-facil"-itated results in the following legal breakpoints (assuming English hyphenation patterns): zoning-facil-i-tated. (Note: hyphenation before "- is disabled in this case because of the explicit hyphen after "zoning".)

When using ngerman as the main document language and switching to english within the document body, \addto allows to carry over language shorthands:

\documentclass{article}

\usepackage[english,ngerman]{babel}
\addto\extrasenglish{\languageshorthands{ngerman}}

\begin{document}

\selectlanguage{english}

Adding \textsf{ngerman} language shorthands to \textsf{english}: zoning-facil"-itated.

\end{document}

However, this doesn't work with english as the main document language (and ngerman still specified as additional option):

\documentclass{article}

\usepackage[ngerman,english]{babel}
\addto\extrasenglish{\languageshorthands{ngerman}}

\begin{document}

Adding \textsf{ngerman} language shorthands to \textsf{english}: zoning-facil"-itated.

\end{document}

How can I add ngermans language shorthands to english while using english as the main document language?

2 Answers 2

28
\documentclass{article}
\usepackage[ngerman,english]{babel}
\useshorthands{"}
\addto\extrasenglish{\languageshorthands{ngerman}}
\begin{document}

\minipage{1cm}\hrulefill

\hspace{0pt}zoning-facilitated

\hspace{0pt}zoning"=facil"-itated
\endminipage
\end{document}

enter image description here

With lualatex you do not need the \hspace{0pt} (LuaTeX hyphenates the first word of a paragraph, which TeX doesn't)

4
  • Okay, that's the new winner. :-)
    – lockstep
    Commented Sep 1, 2011 at 18:13
  • Funny thing: It fails if you load babel with \usepackage[ngerman,main=english]{babel} in combination with hyperref's \autoref.
    – Skillmon
    Commented Jan 31, 2018 at 21:33
  • Give an example!
    – user2478
    Commented Feb 1, 2018 at 6:12
  • @Herbert would have been great, if you'd pinged me. Now I saw it just now by chance and don't remember the use case where I encountered this...
    – Skillmon
    Commented Feb 23, 2019 at 12:09
12

One has to define the language specific shorthands; I've left only the hyphenation related ones:

\documentclass[a4paper]{article}
\usepackage[english]{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}
\makeatother

\begin{document}

\hsize=3pt

\hskip0pt zoning-facilitated

\hskip0pt zoning-facil"-itated

\end{document}

It's quite easy also to import the ngerman shorthands:

\documentclass[a4paper]{article}
\usepackage[ngerman,english]{babel}

\makeatletter
\initiate@active@char{"}
\addto\extrasenglish{\languageshorthands{ngerman}\bbl@activate{"}}
\addto\noextrasenglish{\bbl@deactivate{"}}
\makeatother

\begin{document}

\hsize=3pt

\hskip0pt zoning-facilitated

\hskip0pt zoning-facil"-itated

\end{document}

Of course, ngerman has to be loaded, otherwise the shorthands would not be known; so the first alternative seems better.

6
  • 1
    +1 -- however, explicitly cloning ngermans shorthand definitions is a somewhat "brute-force" solution. Let's see if someone figures out a solution based on the fact that my first example works.
    – lockstep
    Commented Sep 1, 2011 at 17:33
  • I've added how to import the ngerman shorthands.
    – egreg
    Commented Sep 1, 2011 at 17:56
  • Sorry for revoking my (premature) acceptance, but Herbert's answer is exactly what I was looking for.
    – lockstep
    Commented Sep 1, 2011 at 18:15
  • Neat; but I believe that the "brute force" approach has its merits
    – egreg
    Commented Sep 1, 2011 at 18:19
  • 1
    You still have my upvote. :-)
    – lockstep
    Commented Sep 1, 2011 at 18:20

You must log in to answer this question.

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