# ſ (long s) and hyphenation

I'm using UTF-8 so it is – if one is using the right font – no problem to implement the different types of s in older German texts (s, ſ, ß). Unfortunately the hyphenation breaks because LaTeX does not know that ſ has to be dealt with just the same as it would do when dealing with "s".

MWE:

\documentclass{article}
\usepackage[ngerman]{babel}

\begin{document}
XXX Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft

XXX Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft

\hyphenation{Ge-ſell-ſchaft}

XXX Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft

\end{document}


As one can see at the end of the line, I have to add the correct hyphenation manually. Any idea how I can solve this?

• you could make this work automatically in luatex or xetex but in pdftex the best you could do is define ſ to always allow a hyphenation after it, it can not take part in \patterns or \hyphenation – David Carlisle Aug 6 '18 at 14:45
• your choices would be essentially to (a) use \hyphenation as you have done for all necessary words or (b) copy the hyphenation patterns adding patterns for long s to match those for s and rebuild the xelatex format (lulatex does not need to be rebuilt) or (c) use s in the original markup and then set up font features (perhaps...) so that some s get typeset using the long form. Which would you prefer? (the last probably depends on the font you use) – David Carlisle Aug 6 '18 at 15:29
• I use XeLaTeX, so copying the patterns is definitely the way to go. I'll look it up, right now I'm not sure how it works. (c) is a creative solution but does not work as I have parts where I want the long s and parts were I don't as I have to stay true to the source – Martin Mueller Aug 6 '18 at 15:37
• oh or if you are using luatex then (d) implement a Lua hyphenation callback that hyphenates using s, then switches to long s and re-inserts the hyphenation points, – David Carlisle Aug 6 '18 at 15:37
• If the list of problematic patterns is short, in luatex you can also add them with \babelpatterns in the document itself. – Javier Bezos Aug 6 '18 at 17:38

For LuaTeX here is an implementation of David Carlisles idea to create a hypenate callback. It works by replacing every ſ with a marked s before hyphenation and then recovering the original characters after hyphenation:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{luacode}
\begin{luacode*}
local sattr = luatexbase.new_attribute("longsattr")
local disc = node.id'disc'
print('DISC', disc)

if n == tail then break end
if n.id == disc then
print(n)
long_to_s(n.pre)
long_to_s(n.post)
long_to_s(n.replace)
end
if n.char == 383 then
n.char = 115
node.set_attribute(n, sattr, 383)
end
end
end
if n == tail then break end
if n.id == disc then
s_to_long(n.pre)
s_to_long(n.post)
s_to_long(n.replace)
end
local a = node.get_attribute(n, sattr)
if a then
n.char = a
node.unset_attribute(n, sattr)
end
end
end
end
\end{luacode*}
\begin{document}
XXX Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft

XXX Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft
\end{document}


LuaTeX also allows you to manipulate the hyphenation pattern during a run, so you can also use (this is an automated version of David Carlisles choice (b)):

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{luacode}
\begin{luacode*}
local l = lang.new(tex.language)
l:patterns(l:patterns():gsub('s', 'ſ'))
\end{luacode*}
\begin{document}
XXX Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft

XXX Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft Geſellſchaft
\end{document}


• I accept this answer as it seems a clever solution (even though, for other reasons, I stick to XeLaTeX) – Martin Mueller Aug 7 '18 at 8:37

A simple way to do this is to choose a font that supports ſ as an open type character variant, e.g., EB Garamond. Then you can just select that variant when you need it.

(Re-reading the comments above, I see this corresponds to option (c) from David Carlisle, which you said wasn't suitable, but this MWE shows you can have both kinds of s with this method.)

Update showing iſt and ſelbes.

\documentclass{article}
\usepackage[ngerman]{babel}
\babelfont{rm}{EB Garamond}
\begin{document}
XXX Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft Gesellschaft