0

I successfully use org LaTeX-preview to have my formulas displayed as images in my org-mode documents. There is one problem I am facing, though: I need the LaTeX math font to be upright instead of slanted. This is easily solved in an ordinary LaTeX-document by adding \usepackage[math-style=upright]{unicode-math}. For some reason, I have trouble getting it to work with LaTeX preview. This is my package specification for preview images:

(setq org-latex-packages-alist '(
("" "amssymb" t)
("" "turnstile" t)  ; for Turnstiles
("" "centernot" t)  ; for striked through Turnstiles
("" "mathpartir" t) ; for inference patterns
("math-style=upright" "unicode-math" t) ; for upright Math font
))

If I understand how org-latex-packages-to-string works, the above specification should produce the desired result. I even manually added "\usepackage[math-style=upright]{unicode-math}" to org-format-latex-header:

(setq org-format-latex-header "\\documentclass{article} 
\\usepackage[usenames]{color}
\[PACKAGES]
\[DEFAULT-PACKAGES]
\\usepackage[math-style=upright]{unicode-math}         % added package 
\\pagestyle{empty}             % do not remove
% The settings below are copied from fullpage.sty
\\setlength{\\textwidth}{\\paperwidth}
\\addtolength{\\textwidth}{-3cm}
\\setlength{\\oddsidemargin}{1.5cm}
\\addtolength{\\oddsidemargin}{-2.54cm}
\\setlength{\\evensidemargin}{\\oddsidemargin}
\\setlength{\\textheight}{\\paperheight}
\\addtolength{\\textheight}{-\\headheight}
\\addtolength{\\textheight}{-\\headsep}
\\addtolength{\\textheight}{-\\footskip}
\\addtolength{\\textheight}{-3cm}
\\setlength{\\topmargin}{1.5cm}
\\addtolength{\\topmargin}{-2.54cm}"
)

This did not work either. Do you have an idea what I can do to have the LaTeX-fragments displayed upright instead of slanted?

Edit: The value of org-preview-latex-process-alist is

((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 -D %D -T tight -bg Transparent -o %O %f"))
 (dvisvgm :programs
          ("latex" "dvisvgm")
          :description "dvi > svg" :message "you need to install the programs: latex and dvisvgm." :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." :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")))

Also, I have (setq org-latex-create-formula-image-program 'dvipng) in my .init file. This is why the value of org-preview-latex-default-process is dvipng.

5
  • What's the value of org-preview-latex-process-alist and org-preview-latex-default-process? Also, you shouldn't be using amssymb together with unicode-math.
    – d125q
    Dec 2, 2021 at 9:07
  • I have added the information you were asking for. Why shouldn't I use amssymb together with unicode-math? Afaik, you should just load unicode-math after amssymb. Dec 2, 2021 at 12:09
  • Are you sure your configuration works? unicode-math works only with XeLaTeX or LuaLaTeX, it does not work with plain LaTeX which is what your configuration uses. I am able to get upright math without any problems, but I use xelatex and not latex. I get an error if I attempt to use latex.
    – d125q
    Dec 2, 2021 at 15:01
  • As for why you should not use unicode-math and amssymb together: They serve the same purpose and clash with each other. See e.g. tex.stackexchange.com/questions/175860/….
    – d125q
    Dec 2, 2021 at 15:02
  • I actually did not know that unicode-math only works with with XeLaTeX or LuaLaTeX - that might be the issue! Is there a way to use XeLaTeX or LuaLaTeX with dvipng or imagemagick? Although I have everything installed, dvisvgm does not do anything. Dec 2, 2021 at 17:31

1 Answer 1

0

Thanks to d125q's comments, I solved the issue. It was twofold:

First and foremost, unicode-math is a package which only works with XeTeX or LuaTeX, but org by default compiles with LaTeX. This is why you need the preview images to be generated by XeTeX or LuaTeX. This is my configuration:

(setq org-preview-latex-process-alist
       '((dvipng :programs
         ("lualatex" "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
         ("lualatex -output-format dvi -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 "xdv" :image-output-type "svg" :image-size-adjust
          (3 . 1.5)
          :latex-compiler
          ("xelatex -no-pdf -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
              ("xelatex -no-pdf -interaction nonstopmode -output-directory %o %f")
              :image-converter
              ("convert -density %D -trim -antialias %f -quality 100 %O"))))

I copied it off from here and am open for any suggestions (the images are generated more slowly than before).

Secondly, LuaTeX requires org-latex-preview to generate .dvi images (instead of .png or .pdf files). You can configure this by adding (setq org-preview-latex-default-process 'dvisvgm) to your .init file. But caution: You need the dvisvgm dependency, which ships with latex-extra-utils, as well as an emacs build capable of dealing with svg files. This usually is the case, but especially if you build it from source like me, you need to double-check to (1) have librsvg2-dev installed and (2) use --with-rsvg in ./configure.

If those two points are solved, org-latex-preview should compile the images with LuaTeX and thus be able to use the unicode-math package when generating the preview image if you add it to org-latex-packages-alist, for example by adding (add-to-list 'org-latex-packages-alist '("math-style=upright" "unicode-math" t)) to your .init file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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