5

In my .org file I embedded a simple Latex segment:

$f(x) = x^2$    

Then I use the following command to generate a preview for that segment:

org-toggle-latex-fragment

But I get an error:

org-compile-file: File "/var/folders/x2/zp6vz8z97xv48g97pht5_mrc0000gn/T/orgtexu9KnIy.dvi" wasn’t produced.  
Please adjust ‘dvipng’ part of ‘org-preview-latex-process-alist’.

I tried to debug the issue:

  • The file /var/folders/x2/zp6vz8z97xv48g97pht5_mrc0000gn/T/orgtexu9KnIy.tex exists
  • I can use pdflatex to create a file from the above .tex without any issue.
  • I can also create a dvi from the above by just running latex orgtexu9KnIy.tex. No error happens.
  • When I run dvipng orgtexu9KnIy I get the following output:

    This is /usr/local/texlive/2017/bin/x86_64-darwin/dvipng (dvipng (TeX Live)) 
    1.15 Copyright 2002-2015 Jan-Ake Larsson
    [1]
    

And I have a file orgtexu9KnIy1.png in the current folder. I'm suspicious bit wondering about the additional 1 in the file name.

Org expects the file name to be orgtexu9KnIy.png and not orgtexu9KnIy1.png.


The value of the variable org-preview-latex-process-alist:

((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")))
4
  • Looks like an incomplete TeX setup. Maybe, pdflatex is setup but not dvipng. Does AucTeX Preview work with the generated LaTeX file? If that works (with png-previews) you could give texfrag a try.
    – Tobias
    Apr 19, 2020 at 7:59
  • Can you run a fourth step: dvipng orgtexu9KnIy.dvi, and see if that succeeds too? Also,please add the value of org-preview-latex-process-alist to your question.
    – NickD
    Apr 19, 2020 at 19:15
  • @NickD updated my question, dvipng seems to work, but it generates a file orgtexu9KnIy1.png which has an additional 1 in the filename, which is a bit strange. There are no other pngs in the same folder.
    – BMBM
    Apr 20, 2020 at 4:46
  • I have the exact same problem. In my case, when I open the dvi file using the dvipng same problem occurs. However, when I double click it, a pdf file is generated (with exact same name, i.e. the extra 1 is NOT there in the filename). Adding sim-links doesn't work. Tried to reinstall emacs and latex multiple times from scratch. Solution below by @zacho314 worked for me!
    – Shambho
    Jan 29 at 8:25

5 Answers 5

5

NickD's comment helped me to debug the issue. In the end everything was setup correctly, but I needed to create symlinks in /usr/local/bin to latex and to dvipng. It was not enough to have these utilities in my PATH.

The tools were installed in /usr/local/texlive/2017/bin/x86_64-darwin/ by brew.

I found that out because in the messages buffer there was a zsh: latex command not found, which I also initially overlooked.

5
  • It should be enough to have them in your PATH: check the value of ~PATH` inside emacs using (getenv "PATH") - it may be that something changes it or it is not set correctly somehow.
    – NickD
    Apr 20, 2020 at 21:37
  • Hm it didn't work, I added the dir to the PATH in my .zshrc, but looks like by default emacs won't read that. I didn't bother to fix that, but other people looked into that: stackoverflow.com/questions/9435019/…
    – BMBM
    Apr 21, 2020 at 9:46
  • Are you using terminal emacs or GUI emacs? From the terminal, emacs should inherit the PATH setting from the shell, so that should work. From the GUI, you have to put the PATH setting in some place (perhaps $HOME/.profile) which is sourced by whatever GUI you use and then emacs will inherit from that.
    – NickD
    Apr 21, 2020 at 12:28
  • Yes you are right, I use the GUI version. Thanks for the tip, I will try to make that work!
    – BMBM
    Apr 21, 2020 at 14:10
  • I have the exact same problem. In my case, when I open the dvi file using the dvipng same problem occurs. However, when I double click it, a pdf file is generated (with exact same name, i.e. the extra 1 is NOT there in the filename). Adding sim-links doesn't work. Tried to reinstall emacs and latex multiple times from scratch. Solution below by @zacho314 worked for me!
    – Shambho
    Jan 29 at 8:24
4

If on Linux, you might be missing some packages. This fixed it for me:

sudo apt install texlive-latex-extra

Couldn't tell which of the many latex packages was the one I was missing, despite having latex and dvipng available. The Org manual (v9.5 retrieved 2022/08/20) says that those should be enough, though.

Credits

4
  • On Fedora, sudo dnf install texlive-scheme-full worked for me.
    – Zaz
    Jan 26, 2023 at 0:11
  • 1
    On Arch it's sudo pacman -S texlive-latexextra
    – ayorgo
    Mar 27, 2023 at 10:58
  • Great, that solved for me
    – BuddhiLW
    Jul 8, 2023 at 16:25
  • Same here. Debian Trixie today.
    – RichieHH
    Feb 4 at 17:15
3

In my case the issue was that the expansion of the relative path %f in "dvipng -fg %F -bg %B -D %D -T tight -o %O %f" from org-preview-latex-process-alist wasn't correct.

I fixed it by changing %f to %F (which is expanded to the absolute path in org-compile-file) in all dvipng-related commands from org-preview-latex-process-alist:

(let ((png (cdr (assoc 'dvipng org-preview-latex-process-alist))))
  (plist-put png :latex-compiler '("latex -interaction nonstopmode -output-directory %o %F"))
  (plist-put png :image-converter '("dvipng -D %D -T tight -o %O %F"))
  (plist-put png :transparent-image-converter '("dvipng -D %D -T tight -bg Transparent -o %O %F")))

The org file I'm editing is on a different file-system than my root file-system, which is probably why this was an issue for me.

1
  • This worked for me!! Thanks a ton!
    – Shambho
    Jan 29 at 8:23
1

On Windows, with MikTex, I came across this error, and here is the solution.

emacs default latex processing: *.tex -[latex.exe]-> *.dvi -[dvipng.exe]-> *.png

even the latex/dvipng executable can be found in PATH, extra works must done to make it work.

1st, execute latex xx.tex and dvipng xx.dvi in command line, MikTex will prompt GUI dialog to confirm dependency installation, press OK to install.

2nd, if current user is Administrator, it will be shorten to ADMIN~1, latex can't recognize it. change temporary-file-directory , org-preview-latex-image-directory varibles, don't use shorten name.

0

I had the exact same error message, and the name of the preview file had '1' appended. The solution was to clear the preview cache (by removing ltximg folder).

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.