mgieseki / dvisvgm

A fast DVI, EPS, and PDF to SVG converter
https://dvisvgm.de
GNU General Public License v3.0
306 stars 33 forks source link

\begin{cases} brace incorrectly rendered with XeLaTeX + XDV + unicode-math #198

Closed ma-chengyuan closed 1 year ago

ma-chengyuan commented 1 year ago

I am using dvisvgm 2.14. Here's an MWE of the problem:

\documentclass{article}
\usepackage{unicode-math}

\begin{document}
\[
    \begin{cases}
        1\\2\\3
    \end{cases}
\]
\end{document}

Converting the above to SVG with

xelatex --no-pdf mwe.tex
dvisvgm -f ttf mwe.xdv

produces incorrect

The incorrect SVG produced:

<g id='page1'>
  <text class='f0' x='221.061021' y='73.364288'>⎧
    <tspan y='79.312244'>⎪</tspan>
    <tspan y='92.752125'>⎨</tspan>
    <tspan y='98.70008'>⎪</tspan>
    <tspan y='104.667966'>⎩</tspan>
    <tspan x='230.047326' y='73.803164'>1</tspan>
    <tspan x='230.047326' y='88.149314'>2</tspan>
    <tspan x='230.047326' y='102.495464'>3</tspan>
  </text>
  <text class='f1' x='231.13325' y='630.635118'>1</text>
</g>

I am no expert in SVG, but it appears that if x is omitted, the x position gets implicitly advanced by the x advance of the font. Therefore the components of the vertical braces are misaligned.

With --no-fonts it produces the correct result: correct

mgieseki commented 1 year ago

Thanks for reporting the bug. It's caused by an uncommon usage of an XDV command that expects the width of the string together with the glyphs to type. Instead of the actual width the unexpected value 0 is given which leads to the misalignment. I've prepared a patch that fixes the issue and will commit it later today.