TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A Tikz diagram such as

    \path (0,0) node[draw] (A) {A};
    \path (2,0) node[draw] (B) {B};
    \draw (A) -- (B) node[midway,above = 0 em] {via};

when processed with (pdf)LaTeX gives

enter image description here

while using TeX4ht extracts only the text, giving a conversion to

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)"> 
<meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)"> 
<!-- html --> 
<meta name="src" content="test.tex"> 
<meta name="date" content="2011-11-17 09:21:00"> 
<link rel="stylesheet" type="text/css" href="test.css"> 
<!--l. 8--><p class="noindent" > ABvia


With more complex Tikz input, TeX4ht turns parts of the picture into separate .png files. What is the best way to get TeX4ht to convert the entire Tikz environment into a single graphic in the output? I've already tried using the Tikz externaliation library, but this does not compile successfully. (Note: Output as for example an SVG would also be fine - the key thing it to maintain the layout.)

For clarity, the result of trying to use externalization with Tikz is:

===== 'mode=convert with system call': Invoking 'latex -halt-on-error -interact
ion=batchmode -jobname "test-figure0" "\def\tikzexternalrealjob{test}\input{tes
t}" && dvips -o "test-figure0".ps "test-figure0".dvi' ========

! Package tikz Error: Sorry, the system call 'latex -halt-on-error -interaction
=batchmode -jobname "test-figure0" "\def\tikzexternalrealjob{test}\input{test}"
 && dvips -o "test-figure0".ps "test-figure0".dvi' did NOT result in a usable o
utput file 'test-figure0' (expected one of .epsi:.eps:.ps:). Please verify that
 you have enabled system calls. For pdflatex, this is 'pdflatex -shell-escape'.
 Sometimes it is also named 'write 18' or something like that. Or maybe the com
mand simply failed? Error messages can be found in 'test-figure0.log'. If you c
ontinue now, I'll try to typeset the picture.

See the tikz package documentation for explanation.
Type  H <return>  for immediate help.

l.11 \end{tikzpicture}


The diagram is part of a larger page, so the aim to to process the text part as normal but have the Tikz part treated differently (as a picture or as an SVG: whatever is better).

share|improve this question
Do you mean that externalisation doesn't compile when run using TeX4ht? When I'm trying to get png's, then I run the externalisation with ordinary LaTeX to get them. The difficulty with SVG output is that it doesn't do mixed text and graphics all that well. What's the desired outcome? A single document consisting of just the picture, or the diagram embedded in a larger (HTML) document? – Loop Space Nov 17 '11 at 11:03
@AndrewStacey See edit on externalization (which works fine for pdfLaTeX with appropriate settings). I'm not too fussed about whether the graphic is in SVG or .png format (although I've been told that SVG is the future). I can use a script to do multiple runs if necessary, but was rather hoping to set up the .tex file such that TeX4ht did the entire job itself. An answer showing an appropriate workflow using standard LaTeX plus TeX4ht would, I think, also be valid. – Joseph Wright Nov 17 '11 at 12:46
up vote 18 down vote accepted

There is specialized output driver for use with tex4ht in Tikz. Using it, diagrams are saved in SVG.

    \path (0,0) node[draw] (A) {A};
    \path (2,0) node[draw] (B) {B};
    \draw (A) -- (B) node[midway,above = 0 em] {via};
share|improve this answer
Excellent - I'd been looking at this from the TeX4ht end, and did not think about the pgf end. Now all I have to do is get it to work with the real problem ... – Joseph Wright Nov 17 '11 at 13:46
this mode has some restrictions, see pgf manual section 10.2.4 (I have version from tlcontrib, I hope it is the same in version from ctan) – michal.h21 Nov 17 '11 at 13:57
I've narrowed my other issues down to using \shortstack inside a node to have multi-line text. That does not seem to work (a tabular also breaks the SVG file entirely). However, I can probably put up with this. – Joseph Wright Nov 17 '11 at 14:02
I'd suggest another wrinkle: include this driver only if tex4ht is used: \ifx\HCode\UnDef\else\def\pgfsysdriver{pgfsys-tex4ht.def}\fi – Boris Nov 17 '11 at 16:51
@Boris In the real case, this is not an issue. I have a number of different target formats, and each one has a short custom .tex file before converging on a single main body. So the driver selection can go in the online-only .tex file. – Joseph Wright Nov 17 '11 at 21:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.