8

I am aware that similar questions have been asked a few times. However, none of the answers solved my problem. This Answer says that it is a bug in luaotfload. But I'm already using a newer version (2.80001).

I'm trying to supress ligatures via selnolig package. It works great, but not for text that was set in capitals. Using microtypes \DisableLigatures or selnolig package \breaklig also has no effect. See MWE:

% !TeX program = lualatex
% !TeX encoding = UTF-8 Unicode
\documentclass[%
    a4paper,
    DIV=9,
    fontsize=14pt,
    parskip=half-
]{scrartcl}

\usepackage[ngerman]{babel}

\usepackage{fontspec}
\setmainfont{TeX Gyre Termes}[%
    Ligatures=Common,
    SmallCapsFeatures={Letters=UppercaseSmallCaps},
]

\setkomafont{disposition}{\rmfamily}

\usepackage[tracking=true]{microtype}
\SetTracking{encoding=*,shape=sc}{160}
\usepackage[ngerman]{selnolig}

\RedeclareSectionCommand[%
    font={\scshape\mdseries\Large}
]{section}

\RedeclareSectionCommand[%
    font={\mdseries\Large}
]{subsection}

\begin{document}
% Heading set in caps => ligature still present
\section{Berufliche Praxis}
Berufliche Praxis\par
ff fl fi

% Using \breaklig command => ligature still present
\section{Beruf\breaklig liche Praxis}

% Disabling selnolig => works as expected
\selnoligoff
\section{Berufliche Praxis}
\selnoligon

% No caps => works as expected
\subsection{Berufliche Praxis}

\end{document}

(very high tracking to make it clearer)

So the selnolig package takes care that ligatures in Berufliche gets suppressed. This is correct. But it does not work for headings with small caps. Adding \selnoligoff right before the \section seems to be the only way to supress ligatures in headings with small caps? Or have I missed a setting? I'm wondering which package is responsible for this bug.

maaattes
  • 495
  • 3
    \section{Beruf\kern0ptliche Praxis} – Steven B. Segletes Apr 03 '19 at 11:11
  • Okay, \kern0pt works. Although this is rather inconvenient because it must be applied separately to each and every occurrence of all words that contain unwanted ligatures. The shortcut "|(provided by babel) does not work. – maaattes Apr 03 '19 at 11:46
  • 1
    Is \kern0pt any more inconvenient that the attempted \breaklig? – Steven B. Segletes Apr 03 '19 at 11:48
  • No by any means. I was just looking for a more global approach. – maaattes Apr 03 '19 at 11:55
  • Okay, I think that's coming over wrong. I did not want to blame any package for this problem. I apologize, that was not really my intention. I am glad that there is a package that allows such accurate settings for ligatures. It really is a great help, especially for very long texts, where a manual check is not possible. To be honest, I only noticed it after adjusting the tracking using microtype. Since microtype with lualatex does not support interword spacing (which should also be adjusted when changing the tracking) I guess I have to cut corners anyway. – maaattes Apr 03 '19 at 13:47
  • I'm also of the opinion that ligatures in letterspaced settings should always be turned off. Ulrikes approach (using SmallCapsFeatures={Ligatures=CommonOff}) actually was my first approach. However, it has no effect in headings. – maaattes Apr 03 '19 at 13:53
  • 1
    I added an issue here https://github.com/u-fischer/luaotfload/issues/53. – Ulrike Fischer Apr 03 '19 at 15:28
  • 1
    The next luaotfload version will resolve the problem (for the automatic case, not for \breaklig which inserts a 0pt space). – Ulrike Fischer Apr 05 '19 at 18:58

2 Answers2

8

With a current luaotfload (version 2.96) you can disable the ligatures in the SmallCapsFeatures:

\documentclass[%
    a4paper,
    DIV=9,
    fontsize=14pt,
    parskip=half-
]{scrartcl}

\usepackage[ngerman]{babel}

\usepackage{fontspec}
\setmainfont{TeX Gyre Termes}[%
    Ligatures=Common,
    SmallCapsFeatures=
      {Letters=UppercaseSmallCaps,
       Ligatures=CommonOff}, %disable ligatures
]

\setkomafont{disposition}{\rmfamily}

\usepackage[tracking=true]{microtype}
\SetTracking{encoding=*,shape=sc}{160}

\RedeclareSectionCommand[%
    font={\scshape\mdseries\Large}
]{section}

\RedeclareSectionCommand[%
    font={\mdseries\Large}
]{subsection}

\begin{document}

\section{Berufliche Praxis}
Berufliche Praxis\par
ff fl fi

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • 1
    I still get the FL ligature though when I load selnolig. As in the OP selnolig has to be turned off explicitly to get rid of the ligature. – moewe Apr 03 '19 at 11:23
  • @moewe Ah yes, selnolig interferes. – Ulrike Fischer Apr 03 '19 at 11:27
  • 3
    @moewe and \selnoligoff works by paragraph and doesn't respect tex grouping, so you can add it simply to the font commands ;-(. – Ulrike Fischer Apr 03 '19 at 11:37
  • I guess you meant “so you can't add…”? So selnolig is the one to “blame”? Maybe https://tex.stackexchange.com/users/5001/mico could comment on that? – maaattes Apr 03 '19 at 11:53
  • 4
    Yes I meant "can't", and selnolig is not really to blame, but you need a more complicated setup to reset the setting after the section. – Ulrike Fischer Apr 03 '19 at 11:59
6

Here is an automated approach that reconditions the arguments of \section to look for specified ligatures, such as fl and to replace them with, for example, f\kern0ptl.

In the MWE, look for the lines between \makeatletter and \makeatother for the approach.

As an aside, I actually used the same method to also increase the default kern of the space character in small-caps section titles.

Shown for ligatures fl and ff. Can easily add more as needed.

EDITED to handle star sections/toc.

% !TeX program = lualatex
% !TeX encoding = UTF-8 Unicode
\documentclass[%
    a4paper,
    DIV=9,
    fontsize=14pt,
    parskip=half-
]{scrartcl}

\usepackage[ngerman]{babel}

\usepackage{fontspec}
\setmainfont{TeX Gyre Termes}[%
    Ligatures=Common,
    SmallCapsFeatures={Letters=UppercaseSmallCaps},
]

\setkomafont{disposition}{\rmfamily}

\usepackage[tracking=true]{microtype}
\SetTracking{encoding=*,shape=sc}{160}
\usepackage[ngerman]{selnolig}

\RedeclareSectionCommand[%
    font={\scshape\mdseries\Large}
]{section}

\RedeclareSectionCommand[%
    font={\mdseries\Large}
]{subsection}

\makeatletter
\usepackage{listofitems}
\expandafter\def\csname{fl}lig\endcsname{f\kern0ptl}% fl
\expandafter\def\csname{ff}lig\endcsname{f\kern0ptf}% ff
\expandafter\def\csname{ }lig\endcsname{\hspace{11pt}}% INCREASE SPACE KERN
\setsepchar{fl||ff|| }% CONCATENATE THE DESIRED LIGATURES WITH || "OR"
\let\svsection\section
\renewcommand\section{\@ifstar{\starsection}{\nostarsection}}
\newcommand\starsection[1]{%
  \tmptitle{#1}%
  \svsection*{\tmp}%
}
\newcommand\nostarsection[2][\relax]{%
  \tmptitle{#2}%
  \if\relax#1\relax\svsection[#2]{\tmp}\else%
    \svsection[#1]{\tmp}%
  \fi%
}
\newcommand\tmptitle[1]{%
  \readlist\myligs{#1}%
  \def\tmp{}%
    \foreachitem\x\in\myligs{%
      \expandafter\g@addto@macro\expandafter\tmp\expandafter{\x}%
      \ifnum\xcnt<\listlen\myligs[]\relax
        \expandafter\expandafter\expandafter\g@addto@macro
        \expandafter\expandafter\expandafter\tmp
        \expandafter\expandafter\expandafter{%
        \csname{\myligssep[\xcnt]}lig\endcsname}%
      \fi
    }%
}
\makeatother
\begin{document}
\tableofcontents

\hrulefill
\section[blah Berufliche]{Berufliche Praxis}

\section{Hoffähige Praxis}

\subsection{Berufliche Praxis}
\end{document}

enter image description here

Of course, I shouldn't mention the crazy stuff you can do with this approach. But I will. Adding these lines (and the xcolor package):

\expandafter\def\csname{e}lig\endcsname{\kern3pt\textcolor{red}{e}\kern1pt}
\setsepchar{fl||ff|| ||e}% CONCATENATE THE DESIRED LIGATURES WITH || "OR"

produces this result:

enter image description here