4

I am trying o typeset a few of the fairy tales my daughter likes so much. Since they aren't copyrighted anymore, I am reproducing a short one here. Suppose I have the following source file:

\documentclass[paper=A5]{scrbook}
\usepackage{fontspec}
\usepackage[german]{babel}
\usepackage{csquotes}

\defaultfontfeatures{Ligatures=TeX}
\setmainfont{UnifrakturMaguntia}
\renewcommand\emshape{\addfontfeature{LetterSpace=20.0,Ligatures=Required,Ligatures=NoCommon}}
\begin{document}

\section*{Der ſüße Brei}

Es war einmal ein armes, frommes Mädchen, das lebte mit ſeiner Mutter
allein, und ſie hatten nichts mehr zu eſſen. Da ging das Kind hinaus
in den Wald, und begegnete ihm da eine alte Frau, die wußte ſeinen
Jammer ſchon und ſchenkte ihm ein Töpfchen, zu dem ſollt es ſagen:
\enquote{Töpfchen, koche}, ſo kochte es guten, ſüßen Hirſenbrei, und
wenn es ſagte: \enquote{Töpfchen, ſteh}, ſo hörte es wieder auf zu
kochen. Das Mädchen brachte den Topf ſeiner Mutter heim, und nun waren
ſie ihrer Armut und ihres Hungers ledig und aßen ſüßen Brei, ſooft
ſie wollten. Auf eine Zeit war das Mädchen ausgegangen, da ſprach die
Mutter \enquote{Töpfchen, koche}, da kocht es, und ſie ißt ſich ſatt;
nun will ſie, daß das Töpfchen wieder aufhören ſoll, aber ſie weiß das
Wort nicht. Alſo kocht es fort, und der Brei ſteigt über den Rand
hinaus und kocht immerzu, die Küche und das ganze Haus voll, und das
zweite Haus und dann die Straße, als wollts die ganze Welt ſatt machen,
und iſt die größte Not, und kein Mensch weiß ſich da zu helfen.
Endlich, wie nur noch ein einziges Haus übrig iſt, da kommt das Kind
heim und ſpricht nur: \enquote{Töpfchen, ſteh}, da ſteht es und hört
auf zu kochen; und wer wieder in die Stadt wollte, der mußte  ſich
durcheſſen.
\end{document}

... which currently renders as:

Der süße Brei, blackletter

How can I force a version that uses a modern font to render the long ſ as contemporary standard s? The issue is already demonstrated in the above rendering in the heading, but it's very obvious when removing (commenting out) the \setmainfont line of the document:

Der süße Brei, serifs

So is there a way to force the Unicode code point for ſ, which seemingly most editors consider to be identical to s (Vim even got confused), to re-map to the glyph s whenever I build the document in a particular way?

PS: there's one glitch in the rendered version which I removed, so it's not 100% identical to what you would get. I replaced an accidental .; by ; in the above.

  • 5
    you could do it in luatex but why not simply do a one-off replace of ſ to s in your editor? – David Carlisle May 03 '20 at 17:16
  • 2
    @DavidCarlisle hah! Excellent question. For starters because none of my editors will abide by my attempt to do that?! How's that for a good argument? Turns out the long ſ is also being matched when you are searching for s. And awkwardly - in Vim - trying %s/ſ/s/g led to all sorts of blank space between words getting removed and so on. I then tried to search for ſ and noticed that more than merely the ſ got highlighted. But you're right insofar as that's my backup plan. But it feels awkward to use an outside tool when I have such a sophisticated tool in use already. – 0xC0000022L May 03 '20 at 18:06
  • 6
    as I have used emacs every day since the 1980s I refuse to talk to a vim user:-) – David Carlisle May 03 '20 at 19:32
  • 1

3 Answers3

12
\documentclass{article}
\directlua
{
 fonts.handlers.otf.addfeature
  {
    name = "longssub",
    type = "substituation",
    data =
      {
           ["ſ"] = {"s"}
      },
  }
}

\usepackage{fontspec}

\begin{document}
 \setmainfont{Times New Roman}
 und ſie hatten nichts mehr zu eſſen.

 \setmainfont{Times New Roman}[RawFeature=+longssub]
 und ſie hatten nichts mehr zu eſſen.
\end{document}

enter image description here

Ulrike Fischer
  • 327,261
7

There are multiple options how to do this, I'll show you two candidates:

(Virtual) Font features

This variant does not change the underlying text as far as TeX is concerned and only swaps the glyphs when actually shaping the line, so it is quite robust. A disadvantage is though that e.g. hyphenation treat the character still as a long s:

\documentclass[paper=A5]{scrbook}
\usepackage{fontspec}
\usepackage[german]{babel}
\usepackage{csquotes}

\directlua{
  fonts.handlers.otf.addfeature{
    type = 'substitution',
    data = {
      [0x017F] = string.byte's', % replce U+017F (long s) by a normal "s"
    },
    name = 'no_long_s',
    prepend = true,
  }
}
\defaultfontfeatures{Ligatures=TeX,RawFeature=no_long_s}
\setmainfont{UnifrakturMaguntia}
\setsansfont{Latin Modern Sans}
\begin{document}

\section*{Der ſüße Brei}

Es war einmal ein armes, frommes Mädchen, das lebte mit ſeiner Mutter
allein, und ſie hatten nichts mehr zu eſſen. Da ging das Kind hinaus
in den Wald, und begegnete ihm da eine alte Frau, die wußte ſeinen
Jammer ſchon und ſchenkte ihm ein Töpfchen, zu dem ſollt es ſagen:
\enquote{Töpfchen, koche}, ſo kochte es guten, ſüßen Hirſenbrei, und
wenn es ſagte: \enquote{Töpfchen, ſteh}, ſo hörte es wieder auf zu
kochen. Das Mädchen brachte den Topf ſeiner Mutter heim, und nun waren
ſie ihrer Armut und ihres Hungers ledig und aßen ſüßen Brei, ſooft
ſie wollten. Auf eine Zeit war das Mädchen ausgegangen, da ſprach die
Mutter \enquote{Töpfchen, koche}, da kocht es, und ſie ißt ſich ſatt;
nun will ſie, daß das Töpfchen wieder aufhören ſoll, aber ſie weiß das
Wort nicht. Alſo kocht es fort, und der Brei ſteigt über den Rand
hinaus und kocht immerzu, die Küche und das ganze Haus voll, und das
zweite Haus und dann die Straße, als wollts die ganze Welt ſatt machen,
und iſt die größte Not, und kein Mensch weiß ſich da zu helfen.
Endlich, wie nur noch ein einziges Haus übrig iſt, da kommt das Kind
heim und ſpricht nur: \enquote{Töpfchen, ſteh}, da ſteht es und hört
auf zu kochen; und wer wieder in die Stadt wollte, der mußte  ſich
durcheſſen.
\end{document}

If you want to avoid the effect on hyphenation,, you can adapt the code in https://tex.stackexchange.com/a/444880/80496 to omit the long_to_s function. Then the character gets replaced much earlier.

Active characters

A traditional TeX alternative are active characters:

\documentclass[paper=A5]{scrbook}
\usepackage{fontspec}
\usepackage[german]{babel}
\usepackage{csquotes}

\defaultfontfeatures{Ligatures=TeX}
\setmainfont{UnifrakturMaguntia}
\setsansfont{Latin Modern Sans}

\catcode`ſ=\active % Make ſ active
\newcommand ſ{s} % Now we can let it expand to s

\begin{document}

\section*{Der ſüße Brei}

Es war einmal ein armes, frommes Mädchen, das lebte mit ſeiner Mutter
allein, und ſie hatten nichts mehr zu eſſen. Da ging das Kind hinaus
in den Wald, und begegnete ihm da eine alte Frau, die wußte ſeinen
Jammer ſchon und ſchenkte ihm ein Töpfchen, zu dem ſollt es ſagen:
\enquote{Töpfchen, koche}, ſo kochte es guten, ſüßen Hirſenbrei, und
wenn es ſagte: \enquote{Töpfchen, ſteh}, ſo hörte es wieder auf zu
kochen. Das Mädchen brachte den Topf ſeiner Mutter heim, und nun waren
ſie ihrer Armut und ihres Hungers ledig und aßen ſüßen Brei, ſooft
ſie wollten. Auf eine Zeit war das Mädchen ausgegangen, da ſprach die
Mutter \enquote{Töpfchen, koche}, da kocht es, und ſie ißt ſich ſatt;
nun will ſie, daß das Töpfchen wieder aufhören ſoll, aber ſie weiß das
Wort nicht. Alſo kocht es fort, und der Brei ſteigt über den Rand
hinaus und kocht immerzu, die Küche und das ganze Haus voll, und das
zweite Haus und dann die Straße, als wollts die ganze Welt ſatt machen,
und iſt die größte Not, und kein Mensch weiß ſich da zu helfen.
Endlich, wie nur noch ein einziges Haus übrig iſt, da kommt das Kind
heim und ſpricht nur: \enquote{Töpfchen, ſteh}, da ſteht es und hört
auf zu kochen; und wer wieder in die Stadt wollte, der mußte  ſich
durcheſſen.
\end{document}
Ulrike Fischer
  • 327,261
4

Still another approach, which I wouldn't recommend in this particular case, but just for completeness:

\babelposthyphenation{german}{ſ}{ string = s }

The way to go is, imo, that proposed by Ulrike.

Javier Bezos
  • 10,003