8

I have a LaTeX file with some directives for my TeX documents (\usepackage and such things). Now I want to reuse this file in different org-mode files. I know I can include files with #+include: 'path/to/some/file.tex', but this puts the content of the file after \begin{document}.

Can I somehow include a file into the header?

As suggested, here an example:

A template.tex file that holds the header:

\documentclass[a4paper]{customClass}
\usepackage{etex}
\title{Some Title}
\supervisor{Someone}

As also shown here, this uses a custom document class, which is one of the reasons why I just want to be able to include it.

Then I have a file which contains all the content (content.org):

#+INCLUDE: template.tex

* Chapter 1
** Subchapter 1
   Some content
** Subchapter 2
   More content

Which currently outputs (content.tex):

\documentclass[11pt]{article}
\usepackage[latin1]{inputenc}
% a lot more org-mode standard header stuff
% ...

\begin{document}

\maketitle

\setcounter{tocdepth}{3}
\tableofcontents
\vspace*{1cm}

% my template.tex file
% not where I wanted it
\documentclass[a4paper]{customClass}
\usepackage{etex}
\title{Some Title}
\supervisor{Someone}


\section{Chapter 1}
% rest of the document
% ...

\end{document}

So in short: I want to reuse my template.tex file in a few org documents to have consistent formatting. Is this possible?

  • 1
    Please add a MWE to show what you want to achieve and assist the helpers to help you. – user31729 Mar 25 '14 at 13:35
  • You are right, that might have been a good idea for me to think of. :) Added one now. – Andreas Arnold Mar 25 '14 at 13:56
  • 2
    Perhaps LaTeX_HEADER: \input{template}? – Sean Allred Mar 25 '14 at 14:01
  • 1
    I'm still on a < 8.0 version of org, but don't you want to set this in your .emacs? That is, with (add-to-list 'org-export-latex-classes <stuff> ). – jon Mar 25 '14 at 17:40
  • 1
    That works! I had to add a few options to keep org-mode from outputting too many things, but it works now. #+LATEX_CLASS: myarticle #+bind: org-export-latex-title-command "" #+OPTIONS: toc:nil – Andreas Arnold Mar 26 '14 at 14:57
3

While I do not know a way to do this with a LaTeX file, you can use #+SETUPFILE: file (http://orgmode.org/manual/In_002dbuffer-settings.html) to include an external org file in exporting. Then you can use #+LaTeX_HEADER: in the external org file.

For example, with the following in content.org:

#+SETUPFILE: template.org

and with the following in template.org:

#+LaTeX_CLASS: customClass
#+LaTeX_CLASS_OPTIONS: [a4paper]
#+LaTeX_HEADER: \usepackage{etex}
#+LaTeX_HEADER: \title{Some Title}
#+LaTeX_HEADER: \supervisor{Someone}

When you export content.org, they will be included as a part of the preamble of content.tex.

2

The latex header org uses for export is stored in org-format-latex-header, which you can modify as you like. According to the help:

It is imperative that this header make sure that no page number appears on the page. The package defined in the variables org-latex-default-packages-alist' andorg-latex-packages-alist' will either replace the placeholder "[PACKAGES]" in this header, or they will be appended.

1

You can create file local variable in your org file to disable default header,then there is no it's own header outputs which confuses latex code that you want.

# Local Variables:
# org-latex-default-packages-alist: nil
# org-latex-with-hyperref: nil
# org-latex-packages-alist: nil
# End:
  • 1
    Welcome to TeX.SX! Your answer is a little bit short. Could you elaborate a little bit on it ;-) – user31729 Sep 17 '14 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.