Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certain parts removed from circuitikz image #139

Closed
matthuszagh opened this issue Jul 22, 2020 · 5 comments
Closed

Certain parts removed from circuitikz image #139

matthuszagh opened this issue Jul 22, 2020 · 5 comments
Assignees
Labels
enhancement improve existing functionality
Milestone

Comments

@matthuszagh
Copy link

matthuszagh commented Jul 22, 2020

I draw circuit schematics with circuitikz. I've recently noticed that some of the output is being removed when dvisvgm converts the pdf to an svg file. For example, here is a minimal input tex file:

mwe.tex:

\documentclass[border={0pt 1pt}]{standalone}
\usepackage[american]{circuitikz}

\begin{document}
\begin{circuitikz}
\draw (0,0) to[R,o-] ++(0,2) node[vcc]{};
\end{circuitikz}
\end{document}

When I compile this with pdflatex:

$ pdflatex mwe.tex

I get the expected output:

dvisvgm_pdf_issue

However, when I subsequently convert this to an svg with

dvisvgm --pdf mwe.pdf -n -b min -c 10 -o mwe.svg

the circle at the bottom is dropped:

dvisvgm_svg_issue

This is not a cropping issue, since the circle can be in the middle of the image and still be dropped.

I've tried to make this example as minimal as possible. However, I understand circuitikz/tikz are doing a lot under the hood, so please let me know if I can clarify anything.

I'm using dvisvgm 2.9.1 and circuitkz 1.2.2.


Here's another example:

\documentclass[border={0pt 2pt}]{standalone}
\usepackage[american]{circuitikz}

\begin{document}
\begin{circuitikz}
\def\block{node[dipchip, fill=red]}
\draw (0,0) \block{red};
\end{circuitikz}
\end{document}

pdf:
dvisvgm_pdf_issue

svg:
dvisvgm_svg_issue

Does dvisvgm omit certain layers from the output? My initial guess is that circuitkz is drawing the missing elements on another layer.

@mgieseki
Copy link
Owner

The missing graphics objects are a result of internal changes introduced in Ghostscript 9.52. Some PDF drawing operators are no longer accessible by external applications like dvisvgm and therefore can't be redefined. Unfortunately, there isn't much I can do about it. If you replace GS 9.52 (or later) with GS 9.50, dvisvgm should produce correct results. You could also use latex rather than pdflatex and convert the DVI file.

@mgieseki mgieseki self-assigned this Jul 22, 2020
@matthuszagh
Copy link
Author

Thanks for the prompt reply.

That's unfortunate about Ghostscript. Is the intention to continue to provide PDF conversion with limited support, or is there some hope of a workaround eventually?

If anyone else comes across this and wants an alternative to the two options listed above (I had trouble reverting to GS 9.50 and experienced bugs unrelated to dvisvgm when using standalone with luatex to produce a DVI file), I found that inkscape seems to do a good job of converting PDF to SVG. I haven't tested this thoroughly, but I've had good luck so far with

inkscape --pdf-poppler in.pdf -T -l -o out.svg

--pdf-poppler and -T convert the fonts to paths.

@mgieseki
Copy link
Owner

That's unfortunate about Ghostscript. Is the intention to continue to provide PDF conversion with limited support, or is there some hope of a workaround eventually?

I'll have a look if there's a way to work around this specific issue but can't promise yet that it's technically possible. I plan to keep the limited PDF support as long as possible. Unfortunately, each of the recent Ghostscript releases introduced further restrictions because of security reasons. If at some point future restrictions limit the functionality of dvisvgm too much, I'll possibly have to drop PDF support.

You might want to have a look at mutool which is part of mupdf. It's also able to convert PDF to SVG.

@matthuszagh
Copy link
Author

Thanks for the pointer, I'll take a look at mutool as well.

@mgieseki mgieseki added the enhancement improve existing functionality label Jul 24, 2020
@mgieseki
Copy link
Owner

I've added a patch that should work around the issue. At least, it leads to correct results for the two examples above when using dvisvgm with GS 9.52.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improve existing functionality
Projects
None yet
Development

No branches or pull requests

2 participants