# [XeTeX] Hyperref & height around links with Latin Modern

David M. Jones dmj at ams.org
Thu Jan 15 02:18:20 CET 2009

There haven't been any public responses to this and there was some
concern locally about whether this indicates a problem with the Latin
Modern fonts that would cause problems for us, so I spent some time
investigating it.

This would appear to be a bug in xdvipdfmx that could potentially
affect any OTF font with large ascenders or descenders.  It does not
affect other TeX engines that use the LM TFM files.  Short of
modifying xdvipdfmx, I don't see any fix.

The size of the rectangle surrounding the link is controlled by the
/Rect entry in the PDF annotation dictionary.  Unlike, say, the hdvips
hyperref driver, which calculates the /Rect size directly based on the
size of the TeX box containing the link, or pdftex, which contains
code internally to calculate the /Rect coordinates, xetex relies upon
xdvipdfmx to calculate the bounding box based on the text inside the

However, instead of using the heights and depths of the characters,
the do_glyph_array() function in dvi.c uses the font ascender and
descender:

height = fnt->size *  fnt->ft_face->ascender / fnt->ft_face->units_per_EM;

depth  = fnt->size * -fnt->ft_face->descender / fnt->ft_face->units_per_EM;

I edited the code a bit to make the lines fit on a single line; look
at the code immediately above the call to pdf_doc_expand_box() in
do_glyph_array() and compare it with the height and depth calculations
before other uses of pdf_doc_expand_box() in the same file.

Adding some code to do_glyph_array() show's the reason for the
difference of the boxes around the links:

face = Latin Modern Roman
ascender  = 1127
descender = -290
height = 738590
depth  = 190054

face = CMU Serif
ascender  =  935
descender = -250
height = 612761
depth  = 163840

That's as deep as I've tried to go.  It doesn't look like the glyph
heights and depths for OTF fonts are currently made available inside
the xdvipdfmx code, but I have no idea what would be required to get

Cheers,
David.

> Date: Sun, 11 Jan 2009 14:03:51 +0100
> From: Freek Dijkstra <software at macfreek.nl>
> Reply-To: Unicode-based TeX for Mac OS X and other platforms <xetex at tug.org>
>
> Hello all,
>
> I have a hyperref-related question. (please suggest a more appropriate
> list if this is off-topic here.)
>
> I recently switched from the Computer Modern to Latin Modern font, and
> noticed that borders around links, as created by hyperref are higher
> then they were for Computer Modern. This looks bad.
>
> Is there a method to decrease the height of the border around links?
>
> Attached is a screenshot (I have no clue if the lists allows that). If
> not, below is a minimal example that shows the difference.
>
> Regards,
> Freek Dijkstra
>
>
> \documentclass{article}
>
> \usepackage{fontspec}
>
> \begin{document}
>
>
> \setmainfont{Latin Modern Roman}
> \setsansfont{Latin Modern Sans}
> \setmonofont{Latin Modern Mono Light}
>
> \section{Latin Modern}
> \label{sec:latin_modern}
>
> This is section~\ref{sec:latin_modern}.
>
>
>
> \setmainfont{CMU Serif}             % Computer Modern Unicode
> \setsansfont{CMU Sans Serif}        % Computer Modern Unicode
> \setmonofont{CMU Typewriter Text}   % Computer Modern Unicode
>
> \section{Computer Modern}
> \label{sec:computer_modern}
>
> This is section~\ref{sec:computer_modern}.
>