# Reducing LATEX_HEADER clutter at the top of my org files

I often write notes in org mode and export them to latex. However, because some documents are complex I need to include many latex packages at the top like so:

``````#+LATEX_HEADER: \usepackage[margin=1.15in]{geometry}
``````

Is it possible to store all the latex header commands (\usepackage, macros definitions etc.) in a separate tex file so that I can just have a single line include at the top of the org file? This will reduce a lot of the clutter and make it easier for me to add packages.

You can make use of a `#+SETUPFILE:`

Put all of these settings in a file, for example `./setup/setupfile.org`, and then include them into your document with

``````#+SETUPFILE: ./setup/setupfile.org
``````

In this file, you can also include `#+OPTIONS:`, `#+AUTHOR`, and similar in-buffer settings. What's even more useful, is that if you load the `#+SETUPFILE:` first, you can then override some of these configurations with local settings.

Another solution is to make use of `#+INCLUDE: "./setup/more-settings.org" src org` (note the `"`) which simply includes the file contents as org source. This is a little more versatile, as there can more than one `#+INCLUDE` where there (afaik) can be only one `#+SETUPFILE`.

Finally, to hide the clutter visually, you can also put all of these local settings in a drawer (i.e., between a line with `:DRAWER:` and a line with `:END:`), and simply hide them with `tab`.

• In my practical experience the drawer solution is the most convenient and fastest way of working with headers. – Dieter.Wilhelm May 29 '18 at 7:04

An alternative solution is to check/customize the variable `org-latex-packages-alist` - add there all your needed `\usepackage{...}`.

This variable is declared in and used by the `ox-latex`, so your org configuration must have an declaration `(require 'os-latex)`. This way no lines to add to org documents, except the title.

As for macros, an usual place to store is the yasnippet package, if you use it.

An alternative solution is to use a non exported headline to wrap configuration:

``````* Configuration :ignoreheading:
#+AUTHOR:
#+STARTUP: showall
...
``````

The advantage of this solution vs drawers is that you can easily include sophisticated configuration, such as LaTeX blocks

``````#+BEGIN_EXPORT LATEX
...
#+END_EXPORT
``````

which are not read (by default) when in drawers.

The advantage of this solution vs configuration files (setupfile or include) is that you can easily change the configuration since it is included in the current file.

Finally, if you want this headline to remain closed by default when opening you org file, you can use the following syntax:

``````* Configuration :ignoreheading:
:PROPERTIES:
:VISIBILITY: folded
:END:
``````
• I have but one upvote to give - but this just became my new default! All of these answers should go into the org-manual as suggested best-practice for latex export, as a document-focused setup vs putting most of the setup in emacs config. – glallen Oct 17 '19 at 13:45

Rather than use `#+SETUPFILE:` as per the accepted answer, if you're just interested in LaTeX output, then you could add the following instead:

``````#+LATEX_HEADER: \input{header.tex}
``````

In `header.tex` (or whatever you want to call it), you can then put all your LaTeX preamble without the need for a whole bunch of `#+LATEX_HEADER:` arguments. To be super meta, you could also have this `#+LATEX_HEADER` option in your `#+SETUPFILE`.

• Edited my answer in response to this question. – jdtonkin Jul 3 '18 at 4:11