I'm using latex source blocks to generate images with org-babel using :results file as in the example below

#+begin_src latex :results file graphics :file myplot.pdf :fit yes

When evaluating this block I get


and the file myplot.pdf has "rendered" latex code.

This works quite well with tikz and pgfplots to create figures or plots that are properly included as images when the document is exported. However, the fonts in my plots created like this do not match the rest of the document when the whole org file is exported to PDF, since the main document and the plots are generated with different latex classes. I'd like to customize the template used by org-mode that surrounds the code inside the #+begin_src #+end_src block to use my customized class.

More specifically, when a latex code block like the one above is evaluated, org will create a temporary file containing something like


WHAT IS IN MY org-latex-default-packages-alist VARIABLE

\pagestyle{empty}             % do not remove
% The settings below are copied from fullpage.sty
\usepackage[active, tightpage]{preview}


where my code is inside the preview environment (preview is added by the :fit yes header). How can I change this template to use a different latex class? The ideal case would be something similar to the #+LATEX_CLASS:mycustomclass header that can be added to the main document. In order words, is it possible to choose one of the classes in org-latex-classes when evaluating a latex code block?

  • Although it's far from convenient, you can customize org-format-latex-header.
    – NickD
    Commented Oct 13, 2020 at 0:44
  • Thanks, that was exactly what I needed. I only needed to change the "documentclass" value in the the string stored in org-format-latex-header to my custom latex class. I wish I could be set with a local file or directory variable, but this is good enough.
    – darcamo
    Commented Oct 13, 2020 at 16:37


Your Answer

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

Browse other questions tagged or ask your own question.