michal-h21 / make4ht

Build system for tex4ht
132 stars 15 forks source link

Different TiKZ SVG output on different devices (opacity='0') #96

Closed yalguzaq closed 1 year ago

yalguzaq commented 1 year ago

This is not really an issue but just a question.

I have the same version of TeX Live 2022 (3.141592653) running on both the server and my local computer, both Linux machines. Yet when I run

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage{float}
\usepackage{tikz,pgfplots}
\usepackage{graphicx}

\begin{document}
\def\fsize{3cm}
\def\tikzgray{black!30!white}
\newcommand\linebe[2]{
\def\lbb{0.2}
\begin{tikzpicture}[scale=3]
% Draw rect to ensure the space is used
\fill[fill=white,opacity=0] (0,0) rectangle (0,0);
% Basis element shape
\fill[fill=\tikzgray] (\lbb,\lbb) rectangle (1-\lbb,1-\lbb);
\draw[thick] (\lbb,\lbb) -- (\lbb,1-\lbb);
\draw[thick,dashed] (\lbb,1-\lbb) -- (1-\lbb,1-\lbb) -- (1-\lbb,\lbb) -- (\lbb,\lbb);
% Line
\draw[thick] (#1) -- (#2);
\end{tikzpicture}
}

\begin{figure}[H]
\linebe{0,0.5}{1,0.5}
\end{figure}

\end{document}

via make4ht file.tex 'mathml,mathjax' on both of these machines, I get different output. On my local machine I get the desired output:

<?xml version='1.0' encoding='UTF-8'?>
<!-- This file was generated by dvisvgm 2.13.3 -->
<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='120.170501pt' height='95.801604pt' viewBox='-.000094 89.266373 120.170501 95.801604'>
<g id='page1' transform='matrix(1.4 0 0 1.4 0 0)'>
<path d='M.398438 132.191412Z' fill='#fff' fill-opacity='0'/>
<path d='M17.4062 115.1836V64.1602H68.4297V115.1836Z' fill='#b3b3b3'/>
<path d='M17.4062 115.1836V64.1602' stroke='#000' fill='none' stroke-width='.79701' stroke-miterlimit='10'/>
<path d='M17.4062 64.1602H68.4297V115.1836H17.4062' stroke='#000' fill='none' stroke-width='.79701' stroke-miterlimit='10' stroke-dasharray='2.98883 2.98883'/>
<path d='M.398438 89.6719H85.4375' stroke='#000' fill='none' stroke-width='.79701' stroke-miterlimit='10'/>
</g>
</svg>

image

whereas when I run the same command on the server, I get

<?xml version='1.0' encoding='UTF-8'?>
<!-- This file was generated by dvisvgm 2.13.3 -->
<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='120.170501pt' height='95.801604pt' viewBox='-.000094 89.266373 120.170501 95.801604'>
<g id='page1' transform='matrix(1.4 0 0 1.4 0 0)'>
<path d='M.398438 132.191412Z' fill='#fff' fill-opacity='0'/>
<path d='M17.4062 115.1836V64.1602H68.4297V115.1836Z' fill='#b3b3b3' fill-opacity='0'/>
<path d='M17.4062 115.1836V64.1602' stroke='#000' fill='none' stroke-width='.79701' stroke-miterlimit='10' stroke-opacity='0'/>
<path d='M17.4062 64.1602H68.4297V115.1836H17.4062' stroke='#000' fill='none' stroke-width='.79701' stroke-miterlimit='10' stroke-opacity='0' stroke-dasharray='2.98883 2.98883'/>
<path d='M.398438 89.6719H85.4375' stroke='#000' fill='none' stroke-width='.79701' stroke-miterlimit='10' stroke-opacity='0'/>
</g>
</svg>

image

The reason is that the second SVG is identical to the first one EXCEPT for fill-opacity='0' and stroke-opacity='0' option for each element.

I have been trying to debug this for hours but with no result. Maybe you have any intuition on what may be going on here?

michal-h21 commented 1 year ago

The SVG images are generated using dvisvgm, which post-process the .idv file produced by tex4ht. Maybe you have a different version of dvisvgm on the server? There can be also different version of pgfsys-dvisvgm.4ht? Maybe you have older version of TeX Live on the server?

yalguzaq commented 1 year ago

Both dvisvgm --version (2.13.3) and tex --version (3.141592653) result in the same output on both machines. How do I check the version of pgfsys-dvisvgm.4ht?

And do you have any idea why would dvisvgm make all SVG elements transparent?

michal-h21 commented 1 year ago

You can find it using:

   $ kpsewhich pgfsys-dvisvgm4ht.def

And compare using diff, for example.

yalguzaq commented 1 year ago

Both files are identical, so this cannot be the cause either.

Thanks for your help though!

michal-h21 commented 1 year ago

It is really strange then! On my system, the output is correct too.

yalguzaq commented 1 year ago

Your intuition about dvisvgm was correct, thanks for putting me in the right direction. The problem, however, was not dvisvgm itself, but its dependencies: dvisvgm -V1 in particular ghostscript. Upgrading ghostscript to the latest version resolved the problem.