mgieseki / dvisvgm

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

Inclined lines missing after XeLaTeX XDV output conversion to SVG, when using STRUKTEX package #244

Closed csevast closed 1 year ago

csevast commented 1 year ago

Hi, I am using XeLaTeX and DVISVGM as conversion chain tool for TeX embedding in org-mode of Emacs. It works fine but in the case of STRUKTEX package (https://www.ctan.org/pkg/struktex), to produce structured program flowcharts, the inclined lines in the decision statement box are missing after conversion.

I applied the steps manually in command prompt in Windows 11 (all the input and output files are attached).

To produce the correct PDF file (although, it is not cropped to the size of the flowchart box): 1) xelatex -interaction nonstopmode -output-directory .\ orgtexPMk6Om.tex

To produce the incorrect SVG file: 1) xelatex -no-pdf -interaction nonstopmode -output-directory .\ orgtexPMk6Om.tex 2) dvisvgm -n -b min -c 1,1 -o orgtexPMk6Om.svg orgtexPMk6Om.dvx

Employed software versions info: XeLaTeX

>xelatex --version
MiKTeX-XeTeX 4.10 (MiKTeX 23.5)
© 1994-2008 SIL International, © 2009-2023 Jonathan Kew, © 2010-2012 Hàn Thế Thành, © 2012-2013 Khaled Hosny
TeX is a trademark of the American Mathematical Society
using bzip2 version 1.0.8, 13-Jul-2019
compiled with curl version 7.87.0; using libcurl/7.87.0 Schannel
compiled with expat version 2.5; using expat_2.5.0
compiled with fontconfig version 2.13.1; using 2.13.1
compiled with freetype2 version 2.12.1; using 2.12.1
compiled with graphite2 version 1.3.14; using 1.3.14
compiled with harfbuzz version 6.0.0; using 6.0.0
compiled with icu version 72.1; using 72.1
compiled with jpeg version 9.5
compiled with liblzma version 50040002; using 50040002
compiled with libpng version 1.6.39; using 1.6.39
compiled with libressl version LibreSSL 3.1.4; using LibreSSL 3.1.4
compiled with MiKTeX Application Framework version 4.7; using 4.7
compiled with MiKTeX Core version 4.20; using 4.20
compiled with MiKTeX Archive Extractor version 4.0; using 4.0
compiled with MiKTeX Package Manager version 4.9; using 4.9
compiled with pplib version v2.05 less toxic i hope
using teckit version 2.4
compiled with uriparser version 0.9.7
compiled with zlib version 1.2.13; using 1.2.13

DVISVGM

>dvisvgm --version
dvisvgm 3.1

GhostView

>gswin64c --version
10.01.2

The TeX input file orgtexPMk6Om.tex

\documentclass{article}
\usepackage[usenames]{color}
\def\pgfsysdriver{pgfsys-dvips.def}
\usepackage[no-math]{fontspec}
\usepackage[europeanvoltages, cuteinductors, americanresistors]{circuitikz}
\usepackage[monogreek]{xgreek}
\usepackage{mathtools}
\usepackage{bm}
\usepackage{tikz}
\usepackage{listings}
\usepackage{graphicx}
% Package longtable omitted
% Package wrapfig omitted
% Package rotating omitted
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{amssymb}
% Package capt-of omitted
% Package hyperref omitted
\pagestyle{empty}             % do not remove
% The settings below are copied from fullpage.sty
\setlength{\textwidth}{\paperwidth}
\addtolength{\textwidth}{-3cm}
\setlength{\oddsidemargin}{1.5cm}
\addtolength{\oddsidemargin}{-2.54cm}
\setlength{\evensidemargin}{\oddsidemargin}
\setlength{\textheight}{\paperheight}
\addtolength{\textheight}{-\headheight}
\addtolength{\textheight}{-\headsep}
\addtolength{\textheight}{-\footskip}
\addtolength{\textheight}{-3cm}
\setlength{\topmargin}{1.5cm}
\addtolength{\topmargin}{-2.54cm}

\setmainfont{Times New Roman}
\setsansfont{Calibri}
\setmonofont{Consolas}
\newcommand{\matr}[1]{\bm{#1}}
\newcommand\textlmtt[1]{\text{\fontfamily{lmtt}\selectfont #1}}
\usetikzlibrary{graphs, arrows.meta, shapes.misc}
\usetikzlibrary{shapes.geometric, arrows, positioning}
\usepackage{struktex}
%\usepackage{fontspec} \usepackage{unicode-math}
%\setmainfont[ItalicFont=NewCM10-Italic.otf, BoldFont=NewCM10-Bold.otf, BoldItalicFont=NewCM10-BoldItalic.otf, SmallCapsFeatures={Numbers=OldStyle}]{NewCM10-Regular.otf}
%\setsansfont[ItalicFont=NewCMSans10-Oblique.otf, BoldFont=NewCMSans10-Bold.otf, BoldItalicFont=NewCMSans10-BoldOblique.otf, SmallCapsFeatures={Numbers=OldStyle}]{NewCMSans10-Regular.otf}
%\setmonofont[ItalicFont=NewCMMono10-Italic.otf, BoldFont=NewCMMono10-Bold.otf, BoldItalicFont=NewCMMono10-BoldOblique.otf, SmallCapsFeatures={Numbers=OldStyle}]{NewCMMono10-Regular.otf}
%\setmathfont{NewCMMath-Regular.otf}

\begin{document}
\definecolor{fg}{rgb}{0.972549,0.972549,0.94902}%
\definecolor{bg}{rgb}{0.152941,0.156863,0.133333}%

\pagecolor{bg}%

{\color{fg}
\begin{struktogramm}%
(150,112)
  \sub{Print a message to the screen.}
  \assign{
    \begin{declaration}[Declaration:]
      \description{\pVar{i}}{an \pKey{int} variable}
    \end{declaration}
  }
  \sub{\pVar{i} gets input from keyboard}
  \ifthenelse{6}{6}{Is \pVar{i} odd?}{\sTrue}{\sFalse}
  \sub{Output to screen ``Is odd''}
  \sub{Output to screen of i odd analysis}
  \change
  \sub{Output to screen ``Is even''}
  \sub{Output to screen of i even analysis}
  \ifend
\end{struktogramm}
}

\end{document}

The correct PDF file: orgtexPMk6Om.pdf

The incorrect SVG file: orgtexPMk6Om

mgieseki commented 1 year ago

The XDV file contains PDF literal specials with PDF operators to draw the lines, like this one:

push:
  right: 15pt
  down: -253.261505pt
  xxx: 'pdf: literal q  0.99626401 0 0 0.99626401 0 0 cm 0.39998 w  0 0 m 214.00452 -34.2415 l S Q'
pop:

Since dvisvgm doesn't support PDF specials, the lines are missing in the SVG file. You somehow need to tell the struktex package to emit PostScript specials instead. By default, it seems to create PDF specials when using XeLaTeX. The conversion works fine with LaTeX. Unfortunately, I can't really help to solve this issue.

muzimuzhi commented 1 year ago

Add \PassOptionsToPackage{dvips}{pict2e} to the very beginning of tex file, then the final svg output is OK.

The reason is similar to the one in https://github.com/mgieseki/dvisvgm/issues/192#issuecomment-1210954442

That's because TikZ creates PDF specials by default when used with XeLaTeX. dvisvgm doesn't support these.

But here struktex loads pict2e to draw diagonal lines, and pict2e creates PDF specials by default when used with XeLaTeX, see pict2e drivers p2e-xetex.def and p2e-dvips.def.

muzimuzhi commented 1 year ago

For the completeness, you may also add either

\UseName{sys_load_backend:n}{dvisvgm} % documented in `texdoc interface3`

or

\UseName{keys_set:nn}{sys}{backend=dvisvgm} % documented in `texdoc expl3`

to the very beginning of tex file, to load l3kernel's dvisvgm backend. Otherwise xetex backend is loaded, which may cause problems if utilities based on for example l3color and/or l3draw are used.

csevast commented 1 year ago

The combination of \PassOptionsToPackage{dvips}{pict2e} with \def\pgfsysdriver{pgfsys-dvisvgm.def} at the very beginning of the tex files worked for me (the last one was set already, and I added the first one).

Thank you very much