mrpiggi / svg

Handling SVG pictures in LaTeX documents using Inkscape, ImageMagick and/or Ghostscript
Other
65 stars 11 forks source link

Option to include SVG directly into output file #7

Closed DavidGriffith closed 5 years ago

DavidGriffith commented 5 years ago

I'm not sure if this is the place to talk about it, in https://github.com/michal-h21/tex4ebook/issues/52, or perhaps a combination.

The EPUB format allows for SVG files to be directly included whereas all other output formats for *TeX do not. As-is, when using tex4ebook to build an EPUB file which includes SVG files, the SVGs are first converted into PNG files. What should be tweaked where to allow SVGs to be used in the final output instead of PNGs?

DavidGriffith commented 5 years ago

I was overthinking this. Apparently simply doing \includegraphics{foobar.svg} does the trick. I just need to make sure that command is protected by an \@ifundefined to make sure it doesn't happen when building to PDF.

DavidGriffith commented 5 years ago

Thinking this over again, I think perhaps it would be best if the svg package simply passes a command of \includesvg{mysvgfile} along as \includegraphics{mysvgfile.svg}. Your thoughts?

mrpiggi commented 5 years ago

The basic intention of package svg is to support the LaTeX export capabilities of Inkscape to process all given textual content of svg files with the used document processor (pdflatex, lualatex etc.) in order to use the actual document font. So if you don't want the svg file to be processed by the svg package but include it directly, just do not use it.

Nevertheless I could try to create an optional shortcut when package tex4ebook was loaded. Could you please provide a MWE with the intended workflow?

DavidGriffith commented 5 years ago

My intent for this passthrough is to allow for a document to be processed into a PDF document or an EPUB with as few changes or ifdefs as possible. Here's a MWE:

\documentclass[\ifdefined\HCode dvips\fi]{article}
\usepackage{graphicx}
\usepackage{svg}
\parindent=0pt
\begin{document}
Hello world!\\
\includesvg{glider}\\
Wasn't that fun?
\end{document}

That \ifdefined\HCode dvips\fi business is a workaround for a bug in tex4ht which is described here: https://github.com/michal-h21/tex4ebook/issues/50.

Here's glider.svg

<?xml version="1.0" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="140" height="140"><g transform="matrix(20,0,0,20,10,10)"><path d="m0 0h6v6h-6zm0 2h6m-6 2h6m-4-4v6m2-6v6" style="fill:none;stroke:#000;stroke-width:.1;"/><circle cx="3" cy="1" r=".8"/><circle cx="5" cy="3" r=".8"/><circle cx="1" cy="5" r=".8"/><circle cx="3" cy="5" r=".8"/><circle cx="5" cy="5" r=".8"/></g></svg>
mrpiggi commented 5 years ago

https://github.com/michal-h21/tex4ebook/issues/50 seems to be solved