There are some dvisvgm
command line options that are not mentioned in the TikZ manual, but which should generally be used.
Font format: --font-format=woff2
LaTeX input (compile with latex
or dvilualatex
):
\documentclass[varwidth]{standalone}
\usepackage{amsmath}
\begin{document}
Hello World!
\begin{equation*}
\int_0^1 2x dx = 1
\end{equation*}
\end{document}
Compile with:
latex texsx-469409-a
dvisvgm --zoom=-1 --exact --font-format=woff2 texsx-469409-a
The default font format that dvisvgm
embeds in the SVG output is not correctly interpreted by most WEB browsers. Instead, browsers use some replacement font, e. g. Times. Also, mathematical symbols may be incorrectly displayed:
Therefore, always add option --font-format=woff2
!!! The default font format may change in future dvisvgm
versions.
Improved bounding box calculation: --exact
SVG-1.1, the current standard, is a single-page document format, primarily intended for creating vector graphics to be embedded in the HTML code of Web pages. Therefore, dvisvgm
tries to calculate the tight Bounding Box around the content of the page, similar to what the standalone
class is made for. One could also use the article
class together with \pagestyle{empty}
to achieve the same result without using standalone
; dvisvgm
tries to crop the page around the visibile content.
In case of pure-text documents, without using graphical objects that push the page borders outwards, the resulting bounding box of the output is determined by the glyph boxes from the tfm
files of the used font. However, these tend to be smaller than the glyphs themselves. This may lead to cropped output where parts of the glyphs are invisible because they are outside of the document edges.
dvisvgm
provides option --exact
to calculate the document's bounding box in such a way that glyph outlines fall entirely within the final bounding box.
Alternatively, the border
option of the standalone
document class can be set with a non-negative length value in order to add space around the content. This requires dvisvgm
to be called with option --bbox=papersize
. [Comment by @Martin]
Responsive SVG: --zoom=-1
Option --zoom=-1
produces "responsive SVG" that automatically scale to fill the available space. Such SVG don't have a fixed size. This is important for SVG to be embedded into a web page using HTML containers, such as <object>
or <img>
.
LaTeX input (compile with latex
or dvilualatex
):
\documentclass[dvisvgm]{standalone}
\usepackage{tikz}
\usetikzlibrary{animations}
\begin{document}
\tikz
\node :fill opacity = { 0s="0", 5s="1" }
:rotate = { 6s="0", 10s="360", repeats, restart=false}
[fill = blue!20, draw = blue, ultra thick, circle]
{Hello!};
\end{document}
Compile with:
latex texsx-469409
dvisvgm --zoom=-1 --exact --font-format=woff2 texsx-469409
HTML code for embedding:
<img src="https://agrahn.gitlab.io/svg/texsx-469409.svg" width="200"/>

<img src="https://agrahn.gitlab.io/svg/texsx-469409.svg" width="400"/>

<img src="https://agrahn.gitlab.io/svg/texsx-469409.svg"/>

dvisvgm
driver when compiling to PDF. I'm quite surprised that you even get a usable PDF out of that. Also you have to add\tikzset{make snapshot if necessary}
, to force a snapshot for the PDF.dvisvgm
is linked against Ghostscript'slibgs.so
library.dvisvgm
but compiling to PDF. So you end up withdvisvgm
specials in the PDF file which is likely to corrupt the file.\includegraphics
without any driver option.dvisvgm
delegatesPSFile
special tolibgs
.dvisvgm
specials are mostly animation-related and simply ignored during conversion to PDF.