1

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
\LaTeX
#+end_src

When evaluating this block I get

#+RESULTS:
[[file:myplot.pdf]]

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

\documentclass{article}
\usepackage[usenames]{color}

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

\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}
\usepackage[active, tightpage]{preview}

\begin{document}
\begin{preview}
\LaTeX
\end{preview}
\end{document}

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?

2
  • 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

0

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.