mgieseki / dvisvgm

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

Misrender of "periodic table" example using dvisvgm backend driver #227

Closed rfdonnelly closed 1 year ago

rfdonnelly commented 1 year ago

Hello. This is a follow on to #225 which was resolved by having me use the PGF/TikZ dvisvgm backend driver. Thank you for that. Using the dvisvgm backend driver fixed the "focused ion beam system" example but it breaks the periodic table example at https://tikz.net/periodic-table.

The labels for the gray elements get misplaced (red annotations mine):

image

I suspect this is an issue with the PGF/TikZ dvisvgm backend driver instead of dvisvgm itself but I thought I would start here first to confirm.

Screenshot Comparison

Click the images for the corresponding SVG/PDF source file:

SVG using default driver SVG using dvisvgm driver PDF

Versions

I get the same results with both of the following configurations.

Alpine Linux 3.17

texlive Docker Image

Reproduce

Copy the example from https://tikz.net/periodic-table to default.tex.

Copy default.tex to dvisvgm.tex and modify as follows:

--- examples/periodic-table/default.tex 2023-02-04 15:02:12.868609073 -0800
+++ examples/periodic-table/dvisvgm.tex 2023-02-04 15:02:12.918592361 -0800
@@ -1,9 +1,9 @@
 % Adapted from https://texample.net/tikz/examples/periodic-table-of-chemical-elements.
 % All Credit to Ivan Griffin.

-\documentclass[tikz,border=5mm]{standalone}
+\documentclass[dvisvgm,tikz,border=5mm]{standalone}
 \usetikzlibrary{shapes,calc}

 \begin{document}

 \newcommand{\ElemLabel}[4]{

Then run:

latex default.tex
dvisvgm --font-format=woff default.dvi

latex dvisvgm.tex
dvisvgm --font-format=woff dvisvgm.dvi
muzimuzhi commented 1 year ago

A simplified example:

\ifnum\pdfoutput>0 % pdf output
  \documentclass[tikz, margin=5pt]{standalone}
\else % dvi output
  \documentclass[dvisvgm, tikz, margin=5pt]{standalone}
\fi

\begin{document}
\begin{tikzpicture}
  \node[draw] {before {\color{gray}GRAY} after};
\end{tikzpicture}
\end{document}

Rrelevant .dvi content (dumped using dviasm). I'm far from familiar with dvi operations hence not able to say if they are alright.

tikz dvips backend ``` push: xxx: 'ps: 0 setgray ' push: fnt: cmr10 at 10pt set: 'b' right: 0.277786pt set: 'efore' w: 3.333328pt xxx: 'color push gray 0.5' set: 'GRA' right: -0.833344pt set: 'Y' xxx: 'color pop' w0: set: 'after' pop: pop: xxx: 'ps::[begin]' xxx: 'ps:: pgfr' xxx: 'ps:: restore ' xxx: 'ps:: restore ' ```
tikz dvisvgm backend (with document class option `dvisvgm`) ``` push: xxx: 'dvisvgm:raw {?nl} ' xxx: 'dvisvgm:raw ' push: fnt: cmr10 at 10pt set: 'b' right: 0.277786pt set: 'efore' w: 3.333328pt xxx: 'dvisvgm:raw ' xxx: 'color push gray 0.5' set: 'GRA' right: -0.833344pt set: 'Y' xxx: 'dvisvgm:raw ' xxx: 'color pop' w0: set: 'after' pop: right: 83.041794pt xxx: 'dvisvgm:raw ' xxx: 'dvisvgm:raw {?nl} ' pop: ```
muzimuzhi commented 1 year ago

Just a workaround: Since this picture is simple (from ps-special's view, for example no shading no pattern), dvisvgm is able to process the .dvi output of latex without setting tikz backend to dvisvgm (default backend is dvips I think).

Hence the original \documentclass[tikz,border=5mm]{standalone} works.

Unfortunately, this workaround doesn't help automatic compiling required by https://github.com/yuzutech/kroki/pull/1440.

rfdonnelly commented 1 year ago

Thank you for minimizing the example!

mgieseki commented 1 year ago

Thanks for reporting the issue. It's a bug in dvisvgm's character handler that's easy to fix. I'll push the patch shortly.

muzimuzhi commented 1 year ago

Wow, this once again pushes me to try compiling dvisvgm on macOS, instead of waiting for the update from texlive once a year.

rfdonnelly commented 1 year ago

Thank you @mgieseki!