3

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.

4
  • 1
    Did you already try dvisvgm option --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.
    – Martin
    Commented Jan 24, 2018 at 16:29
  • @Martin Thanks for the response. I am not sure how to specify dvisvgm options. I changed the org-preview-latex-default-process to dvisvgm --exact and got the error "org-format-latex: Unknown conversion process dvisvgm --exact for LaTeX fragments". Previously I had this set to just "dvisvgm". Please let me know if you have any insights on what I am doing wrong here. Commented Jan 24, 2018 at 23:53
  • Sorry, I'm not an Org expert. I don't know if or where the dvisvgm options can be configured. Maybe org-preview-latex-process-alist has to be adapted accordingly.
    – Martin
    Commented Jan 25, 2018 at 18:44
  • If you still have the problem, you should try the answer below: it implements @Martin's suggestion, so it should fix the problem.
    – NickD
    Commented Mar 19, 2021 at 15:00

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.