The glyph for the character "ß" differs considerably between Latin Modern and the CMU fonts (CMU Serif, CMU Sans Serif etc., which use the same glyphs for ß
as cm-super; see this answer):
I much prefer Latin Modern's version of ß
, but I would like to use the CMU fonts because of their Unicode capabilities (they provide a lot more characters than Latin Modern). I would like to avoid editing the font file (I don't want to maintain my own versions of fonts!).
Instead, I was wondering how one would replace a single character with another font in LuaLaTeX. I've seen XeTeX solutions (e.g. this question), but nothing that works with LuaTeX. So far, I've tried the following:
\documentclass{scrartcl}
\usepackage{fontspec}
\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}
\usepackage{newunicodechar}
\newunicodechar{ß}{{\fontspec{Latin Modern Roman}ß}}
\begin{document}
ß
\end{document}
However, I have two problems with this approach:
- In the
\newunicodechar
definition ofß
, I would need some way to detect if the font should be set in serif, sans-serif or typewriter (variants such as bold, italic etc. seem to work). - I'm having doubts whether making
ß
an active character is a good idea. I've heard that hyphenation/kerning/other details in TeX can have problems under these circumstances.
What would be the best way to implement this replacement?
Update: I have extended my first attempt to detect changes in the font family. Still, there is the question whether using active characters can cause any unwanted problems.
\documentclass{scrartcl}
\usepackage{fontspec}
\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}
\usepackage{newunicodechar}
\newfontfamily{\lmodernrm}{Latin Modern Roman}
\newfontfamily{\lmodernsf}{Latin Modern Sans}
\newfontfamily{\lmoderntt}{Latin Modern Mono}
\DeclareTextFontCommand{\textlmodernrm}{\lmodernrm}
\DeclareTextFontCommand{\textlmodernsf}{\lmodernsf}
\DeclareTextFontCommand{\textlmoderntt}{\lmoderntt}
\makeatletter
\newunicodechar{ß}{%
\ifx\f@family\rmdefault\textlmodernrm{ß}%
\else\ifx\f@family\sfdefault\textlmodernsf{ß}%
\else\ifx\f@family\ttdefault\textlmoderntt{ß}%
\fi\fi\fi}
\makeatother
\begin{document}
ß \textsl{ß} \textit{ß} \textbf{ß}
\sffamily
ß \textsl{ß} \textit{ß} \textbf{ß}
\ttfamily
ß \textsl{ß} \textit{ß}
\end{document}
ß
character! The question you refer to essentially uses the same solution as I did, but "the other way around". It still has the same problems/uncertainties (no detection of font families, uses active characters).