From: Rasmus <rasmus@gmx.us>
To: emacs-orgmode@gnu.org
Subject: Re: tikz for multiple targets
Date: Wed, 10 Jul 2013 11:50:14 +0200 [thread overview]
Message-ID: <87wqoyagmh.fsf@gmx.us> (raw)
In-Reply-To: <87k3kztlam.fsf@ucl.ac.uk> (Eric S. Fraga's message of "Tue, 9 Jul 2013 23:34:25 +0100")
Eric S Fraga <e.fraga@ucl.ac.uk> 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
output.
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
(insert
(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 ".svg"))
(rename-file (concat fname ".svg") final t)
(if (file-exists-p final)
(format "[[file:%s]]" final)
""
(error "conversion failed")
)))
#+END_SRC
> 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
seemingly.
–Rasmus
--
The Kids call him Billy the Saint
next prev parent reply other threads:[~2013-07-10 9:50 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-09 22:34 tikz for multiple targets Eric S Fraga
2013-07-10 9:50 ` Rasmus [this message]
2013-07-10 9:54 ` Rasmus
2013-07-10 10:16 ` Fabrice Popineau
2013-07-10 10:56 ` Eric S Fraga
2013-07-10 20:44 ` Andreas Leha
2013-07-11 6:11 ` Eric Schulte
2013-07-11 8:38 ` Rasmus
2013-07-11 16:01 ` Eric Schulte
2013-07-11 10:50 ` Andreas Leha
2013-07-11 16:07 ` Eric Schulte
2013-07-11 18:56 ` Andreas Leha
2013-07-11 19:03 ` Eric Schulte
2013-07-11 23:15 ` Andreas Leha
2013-07-11 22:33 ` Eric S Fraga
2013-07-12 0:20 ` Eric Schulte
2013-07-15 13:11 ` Eric S Fraga
2013-07-16 11:31 ` Eric S Fraga
2013-07-16 12:26 ` Andreas Leha
2013-07-16 15:18 ` Eric S Fraga
2013-07-11 7:21 ` Eric S Fraga
2013-07-11 15:58 ` Eric Schulte
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wqoyagmh.fsf@gmx.us \
--to=rasmus@gmx.us \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).