[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] tikz for multiple targets

From: Rasmus
Subject: Re: [O] tikz for multiple targets
Date: Wed, 10 Jul 2013 11:50:14 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Eric S Fraga <address@hidden> writes:

> Hello again,
> I am trying to get an example that worked with the old exporter to work
> with the new exporter.  The aim is to have a tikzpicture exported to
> both LaTeX and HTML.  The example is in the following message from over
> a year ago now:
> http://article.gmane.org/gmane.emacs.orgmode/53900
> This example no longer works for either LaTeX or HTML.  For LaTeX, I
> would expect the actual tikz code to be inserted into the LaTeX file and
> then processed.  Instead, I get the file name in a verbatim
> environment.

Tikz/pgf works for the latex exporter.  Just insert it as a file link
(with extension tikz or pgf) or as latex verbatim code.

> For HTML, I would expect the image referred to from an
> <img> tag but I get a link to the test.png file instead.

It should be an svg since tikz is a lossless format IMO.

Here's a very rough and ugly function to translate tikz to svg.  I
don't know if there's a more direct approach. . .

#+BEGIN_SRC emacs-lisp
(defun tikz-to-svg (file &optional headers standalone-ops)
  "Convert a tikz picture to a svg picture ready for html

Headers is a string like
 '(pgfplots '(calc tikzlibrary) (kpfonts usepackage oldstylenums). 
Do not include tikz in headers.

Set standalone-ops to t if you want to use the standalone packages conversion.
  (let* ((name (file-name-sans-extension (file-name-nondirectory file)))
         (fname (concat "/tmp/" name))
         (fnamet (concat fname ".tex"))
         (final (concat (file-name-directory file) name ".svg"))
    (with-temp-file fnamet
      (insert (format "\\documentclass[tikz,%s]{standalone}\n"
                      (if (not standalone-ops) ""
                        (if (eq t standalone-ops) 
                            "convert={outfile=\jobname.svg}" standalone-ops))))
      (when headers
         (mapconcat (lambda (x)
                      (cond ((stringp x) (format "\\usepackage{%s}" x))
                            ((and (listp x) (= 2 (length x)))
                             (apply 'format "\\%s{%s}" (reverse x))
                            ((and (listp x) (= 3 (length x)))
                             (funcall 'format "\\%s[%s]{%s}"
                                      (second x) (third x) (first x))
                             (t "")
                             ))) "\n")))
      (insert "\n\\begin{document}\n")
      (progn (insert-file file) (goto-char (point-max)))
      (insert "\n\\end{document}"))
    (call-process "pdflatex" nil "*tmp*" nil "-shell-escape" "-output-directory 
/tmp/" fnamet)
    (call-process "pdf2svg" nil "*tmp*" nil (concat fname ".pdf") (concat fname 
    (rename-file (concat fname ".svg") final t)
    (if (file-exists-p final)
        (format "[[file:%s]]" final)
      (error "conversion failed")

> Is what I want possible with the new exporter?  If so, I imagine the
> test for the backend must be different now.  Any pointers very welcome!

It needs to be added to `org-html-inline-image-rules' and some
potential translation should be added to org-html-inline-image-p,
e.g. substitute pgf or tikz with whatever is the output format.
Perhaps the dvipng code in ox-html can utilized to obtain a png


The Kids call him Billy the Saint

reply via email to

[Prev in Thread] Current Thread [Next in Thread]