The context

The following org buffer

* Random name

This is an equation

  x = a + b

This is a box


is previewed as

An Emacs buffer showing that the equation environment is properly rendered while the tcolorbox not. The previewing of the tcolorbox environment only displays its content but not the box at all

The question

Just as it is possible to preview the content of a equation environment. Is it possible to preview the content of the tcolorbox envionment?

It seems that Emacs is not loading the tcolorbox environment. Is there any way I can make Emacs load a given LaTeX package? so that when previewing a LaTeX code snippet that uses the tcolorbox environment, the actual content is displayed.

Additional information

Have you installed the tcolorbox package?

Yes. I can confirm this because I've compiled several documents that uses the tcolorbox environment with pdflatex without any problems.

Have you checked the variable org-latex-packages-alist contains the tcolorbox package?

Yes. When describing the variable, I get the following value: (("" "tcolorbox" t))

What's the value of the variable org-preview-latex-default-process?

Its value is dvipng. This is the default value and I've not changed it.

If you add #+LATEX_HEADER: \usepackage{tcolorbox} at the top of your Org mode file and export to PDF. Do you see the box?

Yes, I can see the box in the generated PDF file but still can't see when executing org-latex-preview within a tcolorbox environment. tcolorboxes are still being previewed as tiny empty boxes.

I tested this when org-latex-packages-alist was equal to nil.

if you try to export without the header, is there a \usepackage{tcolorbox} in the generated .tex file?

Without the header and with org-latex-packages-alist equal to nil, there is no \usepackage{tcolorbox}. However, the environment tcolorbox is used within the .tex file. In the resulting PDF file, only the text within the tcolorbox is rendered as normal text but no box is rendered.

Without the header and with org-latex-packages-alist equal to (("" "tcolorbox" t)), \usepackage{tcolorbox} does appears within the document. In the resulting PDF file, the tcolorbox environment is properly displayed (i.e. its content and the actual box).

Post screenshoots of the tiny empty box

Actually, it is not a tiny empty box. I wrote that because I tested it with a black background. Actually, the text within the tcolorbox is rendered in the preview but the box is not. See how the following Org file is previewed

#+LATEX_HEADER: \usepackage{tcolorbox}
#+LATEX_HEADER: \usepackage{lipsum}

This is random text.

  a b c d

This is random text


This is random text.

Preview and resulting PDF of the Org mode file shown above

enter image description here

This was tested when these variables had the following values

  • org-latex-packages-alist: nil
  • org-preview-latex-default-process: dvipng
  • There does seem to be a problem with dvipng (I use imagemagick as my org-preview-latex-default-process). I'll check some more when I have some time.
    – NickD
    Commented Sep 17, 2020 at 1:14
  • If you hve imagemagick installed, try it with that. If that works, then the problem is with the dvipng method.
    – NickD
    Commented Sep 17, 2020 at 1:20
  • Executed (setq org-preview-latex-default-process 'imagemagick) but now previewing can't occur because I'm getting the following error: org-compile-file: File "/tmp/orgtexLO3Agf.png" wasn’t produced. Please adjust ‘imagemagick’ part of ‘org-preview-latex-process-alist’. I do have imagemagick installed in my system.
    – doltes
    Commented Sep 17, 2020 at 1:37
  • Solved the issue with the help of an answer from this question. I had to used imagemagick instead of dvipng (by executing (setq org-preview-latex-default-process 'imagemagick)) and then modify the /etc/ImageMagick-7/policy.xml file as stated in an answer to the question. Thank you so much for your help @NickD. Please edit your answer so I can mark it as accepted answer.
    – doltes
    Commented Sep 17, 2020 at 1:54
  • Can you specify which answer you used: the one by Raoul Hatterer or the one by Alec Vercreysse? Or maybe another one? I added some info to the answer, but I was vague about what you really used to solve the problem.
    – NickD
    Commented Sep 17, 2020 at 2:58

1 Answer 1


Add the package to org-latex-packages-alist:

(with-eval-after-load 'org
    (add-to-list 'org-latex-packages-alist '("" "tcolorbox" t)))

The t is important: it tells Org mode to include that package for LaTeX preview. Otherwise, it will only be included when you export the file to LaTeX/PDF, but not when previewing LaTeX fragments.

EDIT: There seem to be problems with the dvipng setting of org-preview-latex-default-process that require more investigation.

Setting the process to imagemagick with

(setq org-preview-latex-default-process 'imagemagick)

works out of the box for me (ImageMagick-6 on Fedora 31), but it did not work for the OP (ImageMagick-7 on Arch Linux). Apparently, the /etc/ImageMagick-7/policy.xml file imposed some restriction on permissions that prevented the conversion of the PDF file to a PNG file (the imagemagick process uses pdflatex to convert the TeX file to PDF and then uses the convert program from ImageMagick to convert the PDF to PNG). The OP reports that he was able to solve the problem from an answer to this question: this one.

EDIT: To debug problems:

  • have you installed the tcolorbox package?

  • check the value of org-latex-packages-alist - does it contain the tcolorbox entry (with a t as shown above)? Use C-h v org-latex-packages-alist RET to get the value.

  • check the value of org-preview-latex-default-process with C-h v org-preview-latex-default-process and update the question with it.

  • add #+LATEX_HEADER: \usepackage{tcolorbox} at the top of your Org mode file and export to PDF. Do you see the box?

  • if you try to export without the header, is there a \usepackage{tcolorbox} in the generated .tex file?

  • check the ltximg/ subdirectory for images and view each one. You might want to delete them and run the preview again: that's the only way to make sure they are up-to-date.

  • use edebug or M-x debug-on-entry to stop execution at the beginning of org-compile-file and then step through it to figure out what Org mode is doing, so you can save the generated file(s) and you can try to reproduce the process by hand.

  • I tried this but it didn't work: I executed that command, killed the Org buffer, opened it again, and executed org-latex-preview within the tcolorbox environment but it was displayed as a tiny empty box. Did this solution worked on your Emacs setup?
    – doltes
    Commented Sep 16, 2020 at 19:18
  • 1
    Yes it works. I added some debugging suggestions to the answer.
    – NickD
    Commented Sep 16, 2020 at 20:01
  • I've already edited my answer with that information.
    – doltes
    Commented Sep 17, 2020 at 0:32

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.