[Tex/LaTex] Removing ligatures when using fontspec

fontspecligatures

This is a follow-up question to Currency symbol: French franc.

Consider the following code:

\documentclass{article}
\usepackage{fontspec}
\usepackage{siunitx}

\DeclareRobustCommand*{\myfranc}{%
  \begingroup
    \fontspec{FreeSerif.otf}%
    ^^^^20a3%
  \endgroup
}
\DeclareSIUnit{\franc}{\myfranc}

\begin{document}
Horse fififif \SI{123.45}{\franc}.
\end{document}

How do I remove the fi ligature to get a seperate f and i instead?

Update

A setup that works for me is the following:

\documentclass{article}

\usepackage{siunitx}
\DeclareRobustCommand*{\myfranc}{%
  \begingroup
    \fontspec{FreeSerif.otf}%
    ^^^^20a3%
  \endgroup
}
\DeclareSIUnit{\franc}{\myfranc}

\usepackage{fontspec}
\defaultfontfeatures{
  Ligatures={
    NoCommon,
    NoRequired,
    NoContextual,
    NoHistoric,
    NoDiscretionary,
    TeX
  }
}
\setmainfont[
  BoldFont=lmroman10-bold.otf,
  ItalicFont=lmroman10-italic.otf,
  BoldItalicFont=lmroman10-bolditalic.otf,
  SlantedFont=lmromanslant10-regular.otf,
  BoldSlantedFont=lmromanslant10-bold.otf,
  SmallCapsFont=lmromancaps10-regular.otf
]{lmroman10-regular.otf}

\begin{document}
\section{Horse}
off fit fly office baffle -- \SI{123.456}{\franc}
\end{document}

Best Answer

To suppress all typographic ligatures, you could issue the command

\defaultfontfeatures{Ligatures={NoCommon, NoDiscretionary, NoHistoric, NoRequired, NoContextual}}

after loading the fontspec package. This directive will apply to all fonts selected subsequently in your document.

Comments:

  • By far the most important option in the directive above is NoCommon. The so-called f-ligatures (ff, fi, fl, ffi, ffl, and possibly other f-ligatures as well) are generally assigned to the "Common" group.
  • "Required" and "Contextual" are the defaults. However, virtually all OpenType fonts I'm familiar with do not feature any "Required" or "Contextual" ligatures. Thus, it's probably not necessary to specify "NoRequired" and "NoContextual", unless you use some kind of special font.
  • "NoHistoric" and "NoDiscretionary" are the fontspec defaults. However, it doesn't hurt to specify these options explicitly to make your intentions clear, right? :-)

Addendum: Here's an MWE that illustrates the use of the \defaultfontfeatures command when used with XeLaTeX:

% !TEX TS-program = xelatex
\documentclass{article}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures={NoCommon, NoRequired, NoContextual, NoHistoric, NoDiscretionary}}
\setmainfont{Latin Modern Roman}
  % If your TeX distribution/Operating System doesn't recognize "logical" font names
  % such as "Latin Modern Roman", try using the name of the file that contains the 
  % font you're trying to load. In this case, try "\setmainfont{lmroman10-regular.otf}".

\begin{document}
off fit fly office baffle 
\end{document}

enter image description here

Related Question