3

Let's say we want to typeset long two-language compounds. We prefer to break such words right after the first-language word is over and before the second-language words starts; if the results get ugly (say, overfull boxes), we wish to allow for breaking also within the single-language parts.

Consider, e.g., Pipes-and-Filters-Architektur, Map/Reduce-Konzept, Assume/Guarantee-Spezifikation, and Quicksortprinzip — all of the kind English+German.

Here are our attempts so far:

\documentclass{article}
\usepackage[USenglish,ngerman]{babel}
\babelprovide[hyphenrules=ngerman-x-latest]{ngerman}%%% according to the documentation of dehyph-exptl.
%\showoutput
\begin{document}
\showhyphens{
\foreignlanguage{USenglish}{Pipes\penalty10000-\penalty2\hskip0pt and\penalty10000-\penalty2\hskip0pt Filters}\penalty10000-\penalty1\hskip0pt Architektur % Pipes-and-Filters-Architektur

\foreignlanguage{USenglish}{Map\penalty10000/\penalty2\hskip0pt Reduce}\penalty10000-\penalty1\hskip0pt Konzept % Map/Reduce-Konzept

\foreignlanguage{USenglish}{Assume\penalty10000/\penalty2\hskip0pt Guarantee}\penalty10000-\penalty1\hskip0pt Spezifikation % Assume/Guarantee-Spezifikation

\foreignlanguage{USenglish}{Quicksort}"-prinzip % Quicksortprinzip
}
\end{document}
  1. Would this rock? We get the output (hyphens with \showhyphens and penalties with \showoutput) which seems right, but I am still not sure.

  2. The above typesetting seems quite cumbersome; is there an easier way to reach the same goal? Is \penalty10000 really necessary between a word and a slash or a dash?

  3. How to say in \foreignlanguage{USenglish}{Quicksort}"-prinzip that we prefer breaking between the English part and the German part rather than breaking inside any of the two parts?

4
  • 2
    Whatever else you do, I'd be sure to rewrite Map/Reduce-Konzept and Assume/Guarantee-Spezifikation as Map\slash Reduce-Konzept and Assume\slash Guarantee-Spezifikation, respectively. By using the macro \slash rather than by hard-coding the / symbol, you're indicating to TeX that it's ok to insert a line break after the / symbol (without inserting a hyphen symbol, of course).
    – Mico
    Aug 30, 2022 at 10:39
  • 1
    @Mico Got it; thanks! But isn't \slash simply /\penalty\exhyphenpenalty (line 597 of latex.ltx)? If we wish to tweak penalties, we should probably say /\penalty something_else anyway (as /\penalty2 in my example), don't we?
    – user224332
    Aug 30, 2022 at 10:49
  • Please say a bit more about the language-related structure of your document. E.g., is it almost entirely in German, with a few choice words derived from English (the (in)famous "Neudeutsch"?) strewn in? Or does the document contain passages that are genuinely in English?
    – Mico
    Aug 30, 2022 at 10:52
  • 1
    @Mico It's a book written in German. The only English parts are a few English (compound or simple) words, a few English abbreviations, a few short English phrases, a few mixed English-German compounds, and some full English sentences in the bibliography (e.g., the titles of certain cited literature). I also use a few other languages in the same way as English.
    – user224332
    Aug 30, 2022 at 10:57

1 Answer 1

1

You've told us that your document is almost entirely in German, apart from "a few English (compound or simple) words, a few English abbreviations, a few short English phrases, a few mixed English-German compounds, and some full English sentences". I take it that you know how how to deal effectively (within the babel framework) with short English-language phrases. Abbreviations and acronyms should not (ever?) be allowed to be hyphenated, right? The main issue, then, is how to deal with the mixed English-German compound words, of which you've provided four choice examples: Quicksortprinzip, Pipes-and-Filters-Architektur, Map/Reduce-Konzept, and Assume/Guarantee-Spezifikation.

My view is to treat these cases as if they were (mostly) German-language constructs. Thus, do use \slash instead of / to allow line-breaking, and do make use of the babel-german "= shortcut to allow hyphenation of the components of compound hyphenated words. Finally, use \babelhyphenation[ngerman]{....} to indicate where not to hyphenate certain words. E.g., left to its own devices, babel-german "finds" tso hyphenation points in both assume and reduce; I suggest suppressing hyphenation entirely for these two words.

enter image description here

I've used LuaLaTeX to compile this test document, mainly so that the hyphenation of the first word in a paragraph is enabled .

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage[english,ngerman]{babel}
%% suppress hyphenation for selected English words in a German-language context
\babelhyphenation[ngerman]{guarantee filters reduce assume}

\setlength\parindent{0pt}
\setlength\textwidth{1sp}

\let\oldslash\slash
\renewcommand\slash{\oldslash\hspace{0pt}}
\begin{document}

Quicksortprinzip

\smallskip
Pipes"=and"=Filters"=Architektur

\smallskip
Map\slash Reduce"=Konzept

\smallskip
Assume\slash Guarantee"=Spezifikation
\end{document}
3
  • 1
    It's possible to define \hyph similarly to \slash to allow what follows to be hyphenated. That's often done for TUGboat. Aug 30, 2022 at 20:40
  • First, thanks! Second, any way to provide a stronger preference for breaking “Pipes-and-Filters-Architektur” before “Architektur” than before and after “and-”? Third, won't all these compounds be internally treated as German the way you wrote them?
    – user224332
    Aug 31, 2022 at 12:37
  • You ask a really important question: Is it possible to indicate that not all possible break points are created equal and that, instead, to indicate a preference for line breaking to occur at only a subset of all possible breakpoints? Probably unsurprisingly for you, German authors are particularly interested in this topic, since long compound words -- e.g., Donauschifffahrtskapitän, which has 6 possible hyphation points, of which 2 (Donau-schiffahrts-kapitän) should be preferred quite strongly -- are quite common. Sadly, AFAICT, no ideas on this topic have reached implementation stage to date.
    – Mico
    Aug 31, 2022 at 13:51

You must log in to answer this question.