LaTeX forum ⇒ XeTeXligatures not forming with some fonts with XeLaTeX

Information and discussion about XeTeX, an alternative for pdfTeX based on e-Tex
event-horizon
Posts: 4
Joined: Sun Sep 26, 2021 12:13 pm

ligatures not forming with some fonts with XeLaTeX

Postby event-horizon » Sun Sep 26, 2021 12:26 pm

I have created fontspec files for various fonts and have been testing them with XeLaTeX. I have found that ligatures are not forming with certain fonts. Here is an example:

I have available to me Bitstream's Baskerville font. It is a truetype font and my font directory is as follows:

$ ls /usr/share/fonts/truetype/BaskervilleBT
BaskervilleBT-BoldItalic.ttf
BaskervilleBT-Bold.ttf
BaskervilleBT-Italic.ttf
BaskervilleBT-Regular.ttf


When using LibreOffice Writer, I am able to select the ligatures. See the attached PDF.

I set up the fontspec as follows:

\defaultfontfeatures[BaskervilleBT]{
  Path = /usr/share/fonts/truetype/BaskervilleBT/,
  Extension = .ttf,
  UprightFont = *-Regular,
  ItalicFont = *-Italic,
  BoldFont = *-Bold,
  BoldItalicFont = *-BoldItalic
}


Here is my test file:

% !TEX xelatex
\documentclass[12pt]{article}
\usepackage{mathspec}
\setmainfont{BaskervilleBT}
\begin{document}
34 first flood effect
\end{document}


I have attached the resulting PDF. The ligatures fi and fl are not formed. (There is no ff ligature available.)

I have setup the fontspec and test files with other fonts and the ligatures do form correctly, so the issue does not appear to be my fontspec or test file. The font itself has the ligatures as demonstrated by LibreOffice.

How do I get XeLaTeX to form the ligatures with Bitstream Baskerville?

Thanks.
Attachments
libreoffice-baskerville-bt.pdf
LibreOffice Writer version
(7.28 KiB) Downloaded 18 times
xelatex-baskerville-bt.pdf
XeLaTeX version
(6.79 KiB) Downloaded 14 times
Last edited by Stefan Kottwitz on Sun Sep 26, 2021 12:57 pm, edited 1 time in total.
Reason: xelatex compiler setting added

event-horizon
Posts: 4
Joined: Sun Sep 26, 2021 12:13 pm

Postby event-horizon » Tue Sep 28, 2021 8:59 am

The same problem occurs with the Georgia font which is readily available on Linux.

Here is the fontspec:

\defaultfontfeatures[Georgia]{
  Path = /usr/share/fonts/truetype/msttcorefonts/,
  Extension = .ttf,
  UprightFont = *,
  ItalicFont = *_Italic,
  BoldFont = *_Bold,
  BoldItalicFont = *_Bold_Italic
}


I've attached the LibreOffice version (with ligatures) and the XeLaTeX version (no ligatures).

It appears that certain fonts are experiencing the issue.
Attachments
xelatex-georgia.pdf
XeLaTeX version
(6.41 KiB) Downloaded 13 times
libreoffice-georgia.pdf
LibreOffice version
(6.79 KiB) Downloaded 20 times

event-horizon
Posts: 4
Joined: Sun Sep 26, 2021 12:13 pm

Postby event-horizon » Wed Oct 06, 2021 9:12 am

It is unclear if the ligature characters are being used in the PDF generated by *LaTeX.

I did a simple experiment. I selected the characters fi and fl (highlighting them in preparation for a copy/paste). With the XeLaTeX versions of the PDFs, I was able to individually select 'f', 'i', and 'l'. With the LibreOffice versions, I wasn't able to. I could only select fi (together as one) and fl (again, together as one). There was no way to select the individual letters.

To rule out XeLaTeX, I used pdfLaTeX with Times font. Same result.

I then went to the basics, Computer Modern font with LaTeX -> dvi. The dvi file was using the ligatures (could only select the ligature, not the individual letters). This was true of Times (\usepackage{times}) as well. But the moment I ran dvipdf, the ligatures disappeared, i.e., the individual letters could be selected.

XeLaTeX has an option to produce xdvi, but there is no viewer available for it, so I am unable to test this with XeLaTeX.

This points to the PDF conversion as the problem. The DVI and PDF viewer (okular) is able to distinguish. But the PDF file produced doesn't use the ligature for some reason.

I tried to view the dvi file with another viewer: evince. This viewer produced garbage at the ligatures. However, when I viewed the PDF converted from dvi, evince was showing the characters correctly. Further evidence that the ligatures are being converted to their constituent letters by the PDF converter.

Can anyone with PDF converter expertise please advise on what can be done here?

Thanks.

zauguin
Posts: 3
Joined: Thu Jan 24, 2019 9:50 pm

Postby zauguin » Thu Oct 14, 2021 6:25 pm

event-horizon wrote:The same problem occurs with the Georgia font which is readily available on Linux.


For Georgia (at least the Georgia version in my system, 5.59) the ligatures you are looking for are defined as "Discretionary Ligatures" and not as "Default Ligatures" in the font file and are therefore disabled by default. You can request them using fontspec's "[Ligatures=Discretionary]" option:

% !TEX xelatex
\documentclass[12pt]{article}
\usepackage{fontspec}
\setmainfont[Ligatures=Discretionary]{Georgia}
\begin{document}
34 first flood effect
\end{document}


event-horizon wrote:It is unclear if the ligature characters are being used in the PDF generated by *LaTeX.

I did a simple experiment. I selected the characters fi and fl (highlighting them in preparation for a copy/paste). With the XeLaTeX versions of the PDFs, I was able to individually select 'f', 'i', and 'l'. With the LibreOffice versions, I wasn't able to. I could only select fi (together as one) and fl (again, together as one). There was no way to select the individual letters.

To rule out XeLaTeX, I used pdfLaTeX with Times font. Same result.

I then went to the basics, Computer Modern font with LaTeX -> dvi. The dvi file was using the ligatures (could only select the ligature, not the individual letters). This was true of Times (\usepackage{times}) as well. But the moment I ran dvipdf, the ligatures disappeared, i.e., the individual letters could be selected.

XeLaTeX has an option to produce xdvi, but there is no viewer available for it, so I am unable to test this with XeLaTeX.

This points to the PDF conversion as the problem. The DVI and PDF viewer (okular) is able to distinguish. But the PDF file produced doesn't use the ligature for some reason.


You are interpreting this incorrectly. PDF files contain a mapping back from glyphs to the text they represent. Current pdfLaTeX versions (and also most other TeX engines) provide correct mappings there, so for example a "ffi" ligature is mapped back to the three letters "f" "f" and "i". Both okular and evince recognize such situations as ligatures and therefore allow to select the ligatures partially (You might notice that all parts have exactly the same width, even if this doesn't fit to the visual appearance of the glyph.) These mappings are important e.g. to enable proper copy and paste even if ligatures are present.

Your Libreoffice file on the other hand doesn't set this mapping correctly and instead maps the whole ligature to to a single private use codepoint. Therefore the viewer has no chance to realize that it is a ligature and doesn't allow to select it's parts. (Often copy and paste does something weird too)

I tried to view the dvi file with another viewer: evince. This viewer produced garbage at the ligatures. However, when I viewed the PDF converted from dvi, evince was showing the characters correctly. Further evidence that the ligatures are being converted to their constituent letters by the PDF converter.
Thanks.

What you are observing is that these mappings are not present in the DVI file (The DVI format does not support these), but your DVI to PDF converter inserts them while embedding the font. This does not mean that the ligatures get broken up in the PDF file.

event-horizon
Posts: 4
Joined: Sun Sep 26, 2021 12:13 pm

Postby event-horizon » Fri Oct 15, 2021 10:58 am

Zauguin, thank you for your response. Based on your response, it looks like XeLaTeX and the PDF converter are working as intended?

For Georgia (at least the Georgia version in my system, 5.59) the ligatures you are looking for are defined as "Discretionary Ligatures" and not as "Default Ligatures" in the font file and are therefore disabled by default. You can request them using fontspec's "[Ligatures=Discretionary]" option


Unfortunately, Ligatures=Discretionary does not work. I think this is available only for OpenType. Both the Bitstream Baskerville and the Georgia fonts on my machine are TrueType. Here is the error:

Package fontspec Warning: OpenType feature 'Ligatures=Discretionary' (dlig)
(fontspec)                not available for font 'Georgia' with script
(fontspec)                'CustomDefault' and language 'Default'.


Is there an equivalent option for TrueType?


Return to “XeTeX”

Who is online

Users browsing this forum: No registered users and 2 guests