chris writes:
>> [ ... snip ... ] >> Solution: >> >> Redefine org-babel-latex-preamble to remove >> the offending line. >> >> (setq org-babel-latex-preamble >> '(lambda (_) >> "\\documentclass[preview]{standalone}")) >> >> With this setup, my example >> >> #+header: :fit yes :headers '("\\usepackage{tikz}") >> #+begin_src latex :exports results :results raw file :file >> test-tikz-triangle.svg >> \begin{tikzpicture} >> \draw[draw=black, fill=blue!10] (0,4) -- (3,0) -- (-3,0) -- cycle; >> \end{tikzpicture} >> #+end_src >> >> exports correctly to an .svg file. > > Hmm, your fix works perfectly! And it's a `defcustom` variable so it's not > even a hack. Yes, I only thought about that afterwards. > I guess that since you haven't selected specific method like: > `#+header: :imagemagick yes`, the method used is `inkscape` > (`ob-latex.el` file): > ``` > (defcustom org-babel-latex-pdf-svg-process > "inkscape \ > --pdf-poppler \ > --export-area-drawing \ > --export-text-to-path \ > --export-plain-svg \ > --export-filename=%O \ > %f" > "Command to convert a PDF file to an SVG file." > :group 'org-babel > :type 'string > :package-version '(Org . "9.6")) > ``` > I would have been, but I've got inkscape installed via Linux Mint apt repo and it appears to be just a bit too old to have the --pdf-poppler option. Right now, for testing, I'm just using the first thing I have at hand that works, which is pdftocairo: : (setq org-babel-latex-pdf-svg-process "pdftocairo -svg %f %O") I'll probably switch to inkscape for options like not exporting text to paths. I also considered dvisvgm, which I use for snippet preview, but I *think* that using xetex, I could not use dvisvgm for Babel blocks because the Babel latex-to-svg process expects a pdf to be produced, whereas xelatex only outputs dvi (actually an extended dvi format called xdv) if you use the -no-pdf option. Could be wrong. > I don't know if you use `org-latex-preview` for `tikz` snippets? Maybe you > don't because that doesn't export to `html`. > > I use `(setq org-preview-latex-default-process 'dvipng)`, and I guess it > would be nice to add an new option in `(defcustom > org-preview-latex-process-alist` to add `inkscape`. I imagine that's possible. But on raw tikz snippets (not src blocks), this already works well for me with dvisvgm. To get it working with xetex I have customized the dvisvgm option in org-preview-latex-process-alist: ... (dvisvgm :programs ("xelatex" "dvisvgm") :description "xdv > svg" :message "you need to install the programs: xetex and dvisvgm." :image-input-type "xdv" :image-output-type "svg" :image-size-adjust (1.7 . 1.5) :latex-compiler ("xelatex -no-pdf -interaction nonstopmode -output-directory %o %f") :image-converter ("dvisvgm %f --no-fonts --exact-bbox --scale=%S --output=%O"))) ... > So with you solution, I guess when we export to `html`, the "normal" `latex` > formulas are rendered by `mathjax`, which works very well, and the `tikz` > diagrams are automatically exported as a `svg` image, while the code to > produce them is not exported. > > I suppose you use those `latex` code block for exporting to `html` purpose? Yes, that's my aim. Yours, Christian