7

I wish to write full latex code then show result as a image in org mode. My idea is:

  1. Use EXAMPLE block to write full latex code.
  2. Use emacs-lisp to compile the latex code to png.
  3. Show png file but "file:latex.png".

Code as below:

#+NAME: latexcircle
#+BEGIN_EXAMPLE
\documentclass[convert={outfile=latex.png},border=2pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[red] (0,0) circle (1cm);   
\end{tikzpicture}
\end{document}
#+END_EXAMPLE

#+BEGIN_SRC emacs-lisp :var latexcode=latexcircle
(setq latexfile "tmp.tex")
(write-region latexcode nil latexfile)
(setq latexcmd (format "pdflatex --shell-escape %s" latexfile))
(shell-command-to-string latexcmd)
"file:latex.png"
#+END_SRC

#+RESULTS:
: file:latex.png

The file latex.png is created successfully but the result doesn't show the image. I try to use "file latex.png but it doesn't work.

1 Answer 1

8

Refer to this link

#+HEADER: :headers '("\\usepackage{tikz}")
#+BEGIN_SRC latex :fit yes :file latex.png :imagemagick yes :iminoptions -density 600 
\begin{tikzpicture}
\draw[red] (0,0) circle (1cm);
\end{tikzpicture}
#+END_SRC

Output: enter image description here

0

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.