TransWikia.com

org-latex-fragment gets cutoff

Emacs Asked by Quarky Quanta on November 17, 2021

I use dvisvgm to generate latex fragments. However, some of my equations seem to be cut off. One example is below

Equation that get cuts off

The svg file generated does not have the cutoff but the image as displayed in emacs does. I have tried rescaling the images (using org-format-latex-options) and also changing the org-format-latex-header, but have had no success so far. If you have any idea on what might be causing the discrepancy please comment back.

One Answer

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.

Answered by scribe on November 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP