2025年5月1日 星期四

修正 emacs org mode LaTeX Error: Environment tikzpicture undefined.

更新 org mode 到 9.7 以後,tikz 的輸出一直有問題,昨天終於有時間好好 monkey patch 一番(笑)

檢視 *Org PDF LaTeX Output* ,得知中間輸出檔位置,如 -output-directory="~/AppData/Local/Temp/babel-XZ7CVv"

其中最新的 *.log 檔會有錯誤訊息 ,*.tex 檔則為第一個中間檔

觀察 *.tex 輸出有 \documentclass[preview]{standalone} ,此一 preview 套件我並未指定;而我指定的 tikz 則未出現(檔頭有 #+LaTeX_HEADER: \usepackage{tikz} 但顯然沒有作用,可能是 Org 9.7 的 breaking change)

試過 Set up the TikZ in Emacs Org | MSC 的方法但也沒有成功,下列連結則間接找到問題

latex - Problem about previewing TikZ svg from org-babel (org-mode 9.7) under dvisvgm (TeX Live) - Emacs Stack Exchange


So, all available control knobs are accessible at


M-x customize-apropos RET org-babel-latex


and in your case these are:


org-babel-latex-preamble


這個設定的確加上了 preview,我在前面加上 "tikz," ,執行 apply and save ,結果就成功了

P.S. LaTeX 教學系列:繪圖小能手 TikZ – Yueswater Blog 有一個不錯的 tikz 教學網頁,值得好好學學




沒有留言:

張貼留言