I want to export an org file containing a tikz diagram to pdf.
I've read the manual.
This is the most minimal example I could come up with:
#+LATEX_HEADER: \usepackage{tikz}
#+begin_src emacs-lisp :results silent
(org-babel-do-load-languages
'org-babel-load-languages '((latex . t)))
(setq org-babel-latex-htlatex "htlatex")
(defmacro by-backend (&rest body)
`(case (if (boundp 'backend) (org-export-backend-name backend) nil) ,@body))
#+end_src
#+header: :file (by-backend (html "tree.svg") (t 'nil))
#+header: :imagemagick
#+header: :results (by-backend (pdf "latex") (t "raw"))
#+begin_src latex
\begin{tikzpicture} %foo
\draw[thin] (0,0) circle (1);
%\draw (ba) circle (1);
\end{tikzpicture}
#+end_src
To execute I put the cursor in the elisp block and do C-c C-c
, then M-x org-latex-export-to-pdf
This yields:
Process completed with errors: [package error]
Interestingly it works when I remove just one of the 2 comments (or replace ba
by 0,0
)
Upon doing M-x org-latex-export-to-latex
I can see that the code block evaluates to
\begin{tikzpicture} \%foo
\draw[thin] (0,0) circle (1);
\%\draw (ba) circle (1);
\end{tikzpicture}
The comments aren't ignored but the %
are escaped! (And the package error is probably how latex deals with unknown tokens foo
and ba
)
How can I keep the comments in my code and still compile?
Org-mode version 8.2.10
GNU Emacs 25.2.2
Progress:
jagrg is correct I don't get the error with emacs -Q
.
I have now 2 types of errors:
emacs -Q --load debug_init
1) With debug_init
being either of the following files:
(require 'package)
(add-to-list 'load-path "/usr/share/emacs25/site-lisp/mu4e")
(require 'mu4e)
--- or ---
;;(require 'package)
(add-to-list 'load-path "/usr/share/emacs25/site-lisp/mu4e")
(require 'mu4e)
results in Process completed with errors: [package error]
and If I remove %foo
it compiles.
(I can also just fix up the generated .tex
file)
2) with emacs -Q
or either of the following init files:
(require 'package)
;;(add-to-list 'load-path "/usr/share/emacs25/site-lisp/mu4e")
;;(require 'mu4e)
--- or ---
(require 'package)
(add-to-list 'load-path "/usr/share/emacs25/site-lisp/mu4e")
;;(require 'mu4e)
I get by-backend: Symbol’s function definition is void: case
Update 2
Symbol’s function definition is void
is solved, thanks jagrg!
current setup:
myinit:
(require 'cl-lib)
(org-babel-do-load-languages
'org-babel-load-languages '((latex . t)))
(setq org-babel-latex-htlatex "htlatex")
(defmacro by-backend (&rest body)
`(cl-case (if (boundp 'backend)
(org-export-backend-name backend) nil) ,@body))
main.org:
#+LATEX_HEADER: \usepackage{tikz}
#+header: :file (by-backend (html "tree.svg") (t 'nil))
#+header: :imagemagick
#+header: :results (by-backend (pdf "latex") (t "raw"))
#+begin_src latex
\begin{tikzpicture} %foo
\draw[thin] (0,0) circle (1);
%\draw (ba) circle (1);
\end{tikzpicture}
#+end_src
open with emacs -Q --load myinit main.org
then type M-x -l-pd
resulting in Process completed with errors: [package error]
Update 3
changing "raw" to "results" does the trick.
(require 'cl)
as first line of my elisp block now all examples give package error.