3

For some automated testing, I would need a document that renders simple math exactly the same way, one with unicode-math, one without. The issue with differing subscripts is preventing this, at the moment.

Can you help me to set up two documents that render a simple $a_b$ visually 100% identical?

Maybe this could be achieved by using a math font that exists in two variants.

\documentclass{minimal}
\begin{document}
  $a_b$
\end{document}

\documentclass{minimal}
\usepackage{unicode-math}
\begin{document}
  $a_b$
\end{document}
5
  • 2
    You would always use different fonts (latin-modern-math.otf / cmmi10.pfb/cmmi7.pfb or lmmi10.pfb if you use the lmodern package). There is no 100% certainity that glyphs from two distincts fonts are identical. Jun 1, 2018 at 15:52
  • @UlrikeFischer Sorry, I don't get your point. These fonts rendering differently is exactly the root cause of my problem, that I try to find a workaround for, here. At least, I think it is.
    – mhchem
    Jun 1, 2018 at 16:48
  • The main point of unicode-math is that it changes the math font . You can tweak the output so that it looks similar to the output without unicode-math but you can't get 100% identity. If you want identical look you need to use the same math fonts and the same engine. Why do you need such a test? It seems rather odd to me. I would set up separate tests for the different engines. Jun 1, 2018 at 17:05
  • @UlrikeFischer the odd thing is that the subscript drop is set by \fontdimen16\textfont2 so if you use unicode-math in xetex and lmodern package in pdftex you can force them to look similar but the xetex settings seem to be read-only the font-dimens are set by the font but changing the values later seems to have no effect Jun 1, 2018 at 17:37
  • @DavidCarlisle I think there was a way to set the font dimens with xetex, can check later. But I'm trying to make clear that it is not only a question of font dimens. The glyphs can differ too, even if latin-modern-math and lmmi are from the same "family". Jun 1, 2018 at 17:40

1 Answer 1

3

If you use unicode-math then you are using a different font and a different layout engine (the settings for Unicode Math fonts and classic Tex math fonts are quite different) However if you use latin modern for both, you can expect the glyphs to be similar and you ought to be able to make the metrics similar.

XeTeX sets the font parameters based on the OpenType math font table, but I could not see how to change the values later (you can change the fontdimen settings but they have no effect) However you can set the PDFtex ones to match xetex.

enter image description here

a.pdf is pdftex and b.pdftex is xetex generated by

pdflatex --jobname=a file
 xelatex --jobname=b file

where file.tex is

\documentclass{article}
\ifx\Umathchar\undefined
\usepackage{lmodern}
\else
\usepackage{unicode-math}
\fi
\begin{document}

\showoutput
\sbox0{$x$}

\ifx\Umathchar\undefined

\fontdimen16\textfont2=2.47pt
\else

\fi



  $a_b$
\end{document}

xetex showed

....\TU/latinmodern-math.otf(1)/m/n/10 glyph#1296
....\hbox(4.86658+0.07013)x4.0202, shifted 2.47003
.....\TU/latinmodern-math.otf(1)/m/n/7.01236 glyph#1405

By default pdftex lowered the subscript more but by setting fontdimen 16 t0 2.47pt you get:

....\OML/lmm/m/it/10 a
....\hbox(4.8611+0.0)x4.01666, shifted 2.47
.....\OML/lmm/m/it/7 b

Which looks more or less the same.....

5
  • Splendid! The files looks identical when compared at 300 dpi. This should save me a few hundred manual comparisons. Thanks! (Still, files that are more complicated, contain a + or a line height, render differently.)
    – mhchem
    Jun 1, 2018 at 19:31
  • @mhchem there are ~30 fontdimens I only set one. but you could set them all ... Jun 1, 2018 at 19:35
  • Which leads to my other question. Is it intended that the fontdimens differ?
    – mhchem
    Jun 1, 2018 at 21:22
  • I just checked 400 test cases by visual inspection. :-) I am glad, it's a one-time task.
    – mhchem
    Jun 1, 2018 at 21:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .