4

I'm writing a German document, where I frequently cite works in English and other languages. Used to babel’s shorthands in ngerman for easily modifying hyphenation symbols in compound words or names (for example "= for an additional hyphen that should always be printed, and "" for a possible line break without a hyphen), I also activated those shorthands for english using the \addto\extrasenglish commands.

Inside otherlanguage environments in the main document’s text, everything works as expected.

biblatex, which I use for managing my bibliographies, offers the autolang option and the langid field for switching hyphenation rules for each bibliographic entry. When I set autolang to other, it puts an otherlanguage environment around the citations and bibliography entries, and therefore uses the shorthands. But it then also prints terms like and in English, which is not desireable in an overall German document. biblatex therefore offers the autolang=hyphen option to only activate the hyphenation rules for the language specified in the langid field, while falling back to the main document language for all other terms.

However, then the shorthands do not work anymore. How do I get them to work?

Here's an MWE:

\documentclass{scrartcl}

\usepackage{fontspec}
\usepackage[english,ngerman]{babel}
\addto\extrasenglish{\useshorthands{"}\languageshorthands{ngerman}}
\usepackage{csquotes}
\usepackage[backend=biber,autolang=hyphen,style=verbose]{biblatex}

\usepackage{filecontents}
\begin{filecontents}{bibliography.bib}
@collection{NMR,
  editor = {Wardrip"=Fruin, Noah and Montfort, Nick},
  title = {The New Media Reader},
  location = {Cambridge/""MA and London},
  publisher = {MIT Press},
  year = 2003,
  langid = {english}
}
\end{filecontents}

\addbibresource{bibliography.bib}

\begin{document}

\begin{otherlanguage}{english}
  Manually using babel shorthands inside an \texttt{otherlanguage}
  environment, everything works as expected: Wardrip"=Fruin.
  Cambridge/""MA.
\end{otherlanguage}

Yet, citing the work from the bibliography, where it was given a
\texttt{langid} field, the shorthands do not work.\autocite{NMR}

Neither do they work in the bibliography:
\printbibliography
\end{document}
3
  • I'm not sure what you are asking here - if you put langid=english in a bib entry, it will use "and" as this overrides the global lang setting.
    – PLK
    Feb 12, 2016 at 19:53
  • Only, if you give the autolang=other package option. Using the package option autolang=hyphen is exactly for using foreign hyphenrules for the actual field contents, but keeping terms like "and" or date formats in the main document language (i.e. don't translate them). Feb 12, 2016 at 22:01
  • 1
    See below answer - this is due the behaviour of babel's hyphenrule environment which disables shorthands.
    – PLK
    Feb 12, 2016 at 23:10

1 Answer 1

4

The hyphenrules environment actively deactivate all language shorthands. But babel offers generic commands which always work:

\documentclass{scrartcl}

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


\begin{document}

\begin{hyphenrules}{ngerman}
  Manually using babel shorthands inside an \texttt{hyphenrules}
  environment, doesn't: Wardrip"=Fruin.
  Cambridge/""MA.

  Use the babel commands: Wardrip\babelhyphen{hard}Fruin.
  Cambridge/\babelhyphen{empty}MA.
\end{hyphenrules}
\end{document}

enter image description here

biblatex has also the commands \hyphen and \hyphenate (but imho nothing for "").

Edit

Actually you can define the shortcut so that they work for all languages:

\documentclass{scrartcl}

\usepackage{fontspec}
\usepackage[english,ngerman]{babel}

\usepackage{csquotes}

\useshorthands*{"}
\defineshorthand{""}{\babelhyphen{empty}}
\defineshorthand{"=}{\babelhyphen{hard}}

\begin{document}
\begin{hyphenrules}{ngerman}
  Wardrip"=Fruin.
  Cambridge/""MA.

  \end{hyphenrules}

\selectlanguage{english}
  Wardrip"=Fruin.
  Cambridge/""MA.

\selectlanguage{ngerman}
  Wardrip"=Fruin.
  Cambridge/""MA.

\end{document}

enter image description here

2
  • 1
    For the time being, I will take this as a valid workaround. But why aren't babel language shorthands not valid inside hyphenrules environments? What is the rationale here? Can they be activated somehow? Feb 12, 2016 at 22:06
  • Well you can't activate language dependant shortcuts in hyphenrules, but you can create language independant shortcuts. I edited the answer. Feb 12, 2016 at 23:04

You must log in to answer this question.

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