I used C-u C-u C-c C-x C-l (org-latex-preview) to re-generate preview images for all LaTeX fragments in a org-mode buffer. The process succeeded in most places but failed somewhere, giving this error:

Creating LaTeX previews in buffer...
org-compile-file: File "/tmp/orgtex3CxTgl.pdf" wasn’t produced.  Please adjust ‘imagemagick’ part of ‘org-preview-latex-process-alist’.

I couldn't tell which formula or line caused the problem from this random file name in the message. And there are too many formulae to check one by one.


Is there a way to get a line number for the line (or the problematic LaTeX fragment itself) that caused the LaTeX preview to fail?

(This is with Emacs 29.1, Ubuntu 22.04)

1 Answer 1


I don't know an easy way (and I don't think one exists at this point). What I usually do is edit org.el and comment out lines 16211-16213 or thereabouts. The lines look like this:

  (dolist (e post-clean)
    (when (file-exists-p (concat texfilebase e))
      (delete-file (concat texfilebase e))))

They clean up all the files (.tex files in particular) that were used to create the image files which are overlaid on the fragments during preview.

The (normally useless) message you show in the org-compile-file line above will then correspond to a .tex file that will still be around so you can debug.

I normally do C-M-x on the org-create-formula-image function (which is where the above lines are found): that evals the defun and I get the modified definition of the function. Note that the function will now be uncompiled - which normally does not make any difference (except it runs slower), but YMMV.

When I'm done debugging, I do M-x load-library org to reload the whole library: that will load the compiled library normally and you'll be back where you started from. I also uncomment the lines that I commented out in org.el although that file is not normally used by Emacs: Emacs uses the compiled org.elc file.

This has been a sore spot for a long time, but I haven't done anything about it. Maybe the time has come to complain on the Org mode ML and get it fixed.

A less intrusive way which does not require the kind of shenanigans I describe above is to do a binary search on your latex fragments. Comment out half the file and do the preview: if you don't get a failure, then the problem is in the other half. Keep commenting out half of what's left (and maybe switch halves to make sure that you get the failure at each stage) until you are down to one fragment. As always with binary search, this is quick: ceiling(log2 N) halvings where N is the number of fragments are enough to get you down to a single fragment.

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.