3

Question: How to use fontspec fonts so that hyperref boxes are well formed and not too high?

Solved: I don't know why but adding Extension=.ttf inside setmainfont options solves this.

What I expected: To use different fonts like Junicode with XeLaTeX using the fontspec package in a document that has hyperref links.

What I got: Link boxes are too high above the glyphs, as seen in the figure below. I have tested with Junicode and Cardo.

Badly formed link boxes

This is especially annoying when the boxes are not even visible in any sensibly typeset document (try uncommenting the colorlinks line in the MWE).

As a reference, below is a figure where everything works nicely with the default Computer Modern font. Also, TeX Gyre Pagella and TeX Gyre Termes seem to work.

Well formed link boxes with the default font

It seems that the fonts Junicode and Cardo themselves are the cause of this but is there some way to sidestep the issue?

MWE:

% To compile and experience the problem: xelatex file.tex

\documentclass{book}

\usepackage{fontspec}
\setmainfont[
  Mapping=tex-text,
  Extension=.ttf %%% THIS LINE SOLVED THE PROBLEM
]{Junicode}

\usepackage[xetex]{hyperref}%
\urlstyle{rm}%
%%% You can try uncommenting the `colorlinks` option to experience how
%%% uncomfortable it is to try to click those invisible boxes that have
%%% wrong dimensions.
\hypersetup{%
  xetex,%
  %colorlinks=true%
}

\begin{document}

Test link: \href{https://creativecommons.org/licenses/by-sa/4.0/}{CC BY-SA}\\

Curiously italics work: \href{https://creativecommons.org/licenses/by-sa/4.0/}{\textit{CC BY-SA}}\\

test some more \href{https://www.google.com}{\MakeLowercase{Google}} and more\\

Finnish newspaper! \href{https://www.hs.fi/}{Helsingin Sanomat}

\end{document}
8
  • 1
    looks ok for me. Which tex system and which pdf viewer do you use? Side remark: it is quite unnecessary to use the xetex option, hyperref detects this on its own. Commented Mar 20, 2021 at 18:03
  • Good to hear that it might be just a problem on my end. Are my software versions too old? TeX 3.14159265 (TeX Live 2020) and kpathsea version 6.3.2, XeTeX 3.14159265-2.6-0.999992 (TeX Live 2020). Viewer: Evince 3.38.0. Commented Mar 20, 2021 at 18:08
  • 1
    I can't be sure but my guess is that your xdvipdfmx is too old, one windows I have a newer version in texlive 2020. You could install the texlive2021 pretest to check. Commented Mar 20, 2021 at 18:20
  • Makes sense, xdvipdfmx could generate those faulty boxes. I will have to check the new version later. Thanks! Commented Mar 20, 2021 at 18:28
  • 1
    Perhaps you have more than one version of the fonts. Add \XeTeXtracingfonts =1 and then check the log file. Commented Mar 21, 2021 at 7:24

0

You must log in to answer this question.

Browse other questions tagged .