1

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.

4
  • I have no idea why mu4e is triggering the error. To fix the void case symbol you might have to require cl.el.
    – jagrg
    Feb 9, 2019 at 19:00
  • I put (require 'cl) as first line of my elisp block now all examples give package error.
    – user2740
    Feb 10, 2019 at 14:05
  • Try changing "raw" to "results" and see if that works for you. With the "raw" argument the result is not wrapped inside a block, and therefore the exporter has no way of knowing that the code should export to latex.
    – jagrg
    Feb 10, 2019 at 17:06
  • That's it! Thank you!
    – user2740
    Feb 10, 2019 at 17:13

1 Answer 1

1

FWIW I cannot reproduce your problem. The %foo comment should not be escaped so there's definitely something wrong, either with your configuration or a bug with your version of Org. I would try with emacs -Q first and if it still fails I would try upgrading Org. You could also check for errors in the compilation buffer.

1
  • Thank you, I've updated my answer
    – user2740
    Feb 9, 2019 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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