Reading comments, the first thing you should do is read the documentation of org-preview-latex-process-alist
. How? Do C-h v org-preview-latex-process-alist RET
. This will familiarise you with how Emacs actually makes those svg images. Then once you know what you are doing, this code will make more sense.
The default value of preview-latex-process-alist
is something like this,
((dvipng :programs
("latex" "dvipng")
:description "dvi > png" :message "you need to install the programs: latex and dvipng." :image-input-type "dvi" :image-output-type "png" :image-size-adjust
(1.0 . 1.0)
:latex-compiler
("latex -interaction nonstopmode -output-directory %o %f")
:image-converter
("dvipng -fg %F -bg %B -D %D -T tight -o %O %f"))
(dvisvgm :programs
("latex" "dvisvgm")
:description "dvi > svg" :message "you need to install the programs: latex and dvisvgm." :use-xcolor t :image-input-type "dvi" :image-output-type "svg" :image-size-adjust
(1.7 . 1.5)
:latex-compiler
("latex -interaction nonstopmode -output-directory %o %f")
:image-converter
("dvisvgm %f -n -b min -c %S -o %O"))
(imagemagick :programs
("latex" "convert")
:description "pdf > png" :message "you need to install the programs: latex and imagemagick." :use-xcolor t :image-input-type "pdf" :image-output-type "png" :image-size-adjust
(1.0 . 1.0)
:latex-compiler
("pdflatex -interaction nonstopmode -output-directory %o %f")
:image-converter
("convert -density %D -trim -antialias %f -quality 100 %O")))
Since you are using svg images (good choice!) the element that pertains to you is,
(dvisvgm :programs
("latex" "dvisvgm")
:description "dvi > svg" :message "you need to install the programs: latex and dvisvgm." :use-xcolor t :image-input-type "dvi" :image-output-type "svg" :image-size-adjust
(1.7 . 1.5)
:latex-compiler
("latex -interaction nonstopmode -output-directory %o %f")
:image-converter
("dvisvgm %f -n -b min -c %S -o %O"))
We need to edit the :image-converter ("dvisvgm %f -n -b min -c %S -o %O")
part as suggested by @Martin in the comments. Instead of changing the element already in org-preview-latex-process-alist
, I decided to make a new one and add that in the list. Here is how that is done,
(setq my:dvi-to-svg
(my:dvi-to-svg :programs
("latex" "dvisvgm")
:description "dvi > svg"
:message "you need to install the programs: latex and dvisvgm."
:use-xcolor t
:image-input-type "dvi"
:image-output-type "svg"
:image-size-adjust (1.7 . 1.5)
:latex-compiler ("latex -interaction nonstopmode -output-directory %o %f")
:image-converter ("dvisvgm %f -e -n -b min -c %S -o %O")))
(with-eval-after-load 'ox-latex
(add-to-list 'org-preview-latex-process-alist my:dvi-to-svg)
(setq org-preview-latex-default-process 'my:dvi-to-svg))
Now in your document put #+OPTIONS: tex:my:dvi-to-svg
. Now you can change anything about my:dvi-to-svg
.
--exact
or just-e
? Some glyphs exceed the bounding box specified by the TFM data so that the graphics get clipped. Option--exact
should prevent this problem.org-preview-latex-process-alist
has to be adapted accordingly.