org-babel을 사용하여 TikZ 그림에서 PNG를 생성하는 방법은 무엇입니까?
Jan 11 2021
tikz 코드에서 이미지를 생성하기 위해 org-babel을 사용하려고합니다.
첫 번째 코드 ( 이 예제 에서 가져옴)는 완벽하게 작동하지만, tikz 그림을 png (또는 jpg)로 내보내고 싶을 때 다음과 같은 오류가 발생합니다.
org-compile-file: File "/tmp/babel-RNLDyr/latex-o3rO8d.pdf" wasn’t produced. See "*Org PDF LaTeX Output*" for details
이 오류의 원인을 찾을 수없고 " Org PDF LaTeX Output "버퍼가 존재하지 않습니다.
svg를 만들기 위해 코드 사용 (작동합니다) :
#+HEADER: :file ./images/contour.svg :imagemagick yes
#+HEADER: :results output silent :headers '("\\usepackage{tikz}")
#+HEADER: :fit yes :imoutoptions -geometry 400 :iminoptions -density 600
#+BEGIN_src latex
\begin{tikzpicture}
\draw[->] (-3,0) -- (-2,0) arc[radius=0.5cm,start angle=-180,end angle=0] (-1,0) -- (1,0) arc[radius=0.5cm,start angle=180,end angle=0] (2,0) -- (3,0);
\filldraw (-1.5,0) circle[radius=1mm];
\filldraw (1.5,0) circle[radius=1mm];
\end{tikzpicture}
#+END_src
png를 만들기위한 코드 사용 (작동하지 않음) :
#+HEADER: :file ./images/contour.png :imagemagick yes
#+HEADER: :results output silent :headers '("\\usepackage{tikz}")
#+HEADER: :fit yes :imoutoptions -geometry 400 :iminoptions -density 600
#+BEGIN_src latex
\begin{tikzpicture}
\draw[->] (-3,0) -- (-2,0) arc[radius=0.5cm,start angle=-180,end angle=0] (-1,0) -- (1,0) arc[radius=0.5cm,start angle=180,end angle=0] (2,0) -- (3,0);
\filldraw (-1.5,0) circle[radius=1mm];
\filldraw (1.5,0) circle[radius=1mm];
\end{tikzpicture}
#+END_src
답변
1 doltes Jan 11 2021 at 21:52
다음과 같은 최소한의 재현 가능한 예제로 TikZ의 PNG 이미지를 생성 할 수있었습니다.
아래 표시된 GIF emacs
에서 -Q
플래그 를 사용 하고 main.el
파일 에있는 Lisp 코드를로드 하여 실행 하는 것을 볼 수 있습니다 . 이미지는 main.org
문제없이 파일에서 생성됩니다 .
다음 코드 블록은 main.org
파일 의 내용을 보여줍니다.
#+LATEX_HEADER: \usepackage{tikz}
#+begin_src latex :file main.png :results file graphics
\begin{tikzpicture}
\draw node[circle, draw] (a) {$a$}
node[circle, draw, right of = a] (b) {$b$}
node[circle, draw, below of = a] (c) {$c$}
node[circle, draw, below of = b] (d) {$d$};
\end{tikzpicture}
#+end_src
다음 코드 블록은 main.el
파일 의 내용을 보여줍니다.
; The following configuration sets the font (demostration purposes)
(set-frame-font "Iosevka SS04 Light 30")
; The following configuration make Org Mode use imagemagick for processing images.
;
; This was retrieved from this question (https://emacs.stackexchange.com/questions/60696) I posted.
(setq org-preview-latex-default-process 'imagemagick)
; The following configuration disables the confirmation prompt whenever code blocks are evaluated.
(setq org-confirm-babel-evaluate nil)
; The following hook make images to be shown after code blocks are executed.
(add-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images)
; The following configuration allows code blocks whose language is latex to be evaluated
(org-babel-do-load-languages 'org-babel-load-languages
'((latex . t)))
![](https://post.nghiatu.com/assets/images/s/AlM39.gif)