# Can i export LaTex to a .tex file?

I'm cofiguring emacs with org. Principally I wrote in emacs using .org file so i want a standard header file where i define al my "use package" file in particular:

``````\usepackage{geometry}
\usepackage{fontspec}
\usepackage[applemac]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[main=british,italian]{babel}
\usepackage{chemfig}
\usepackage{mol2chemfig}
``````

so here I see that i can create a `header.tex` file containing the upper code, so in the template i can simply recall `#+LaTex_header: \input{path/header.tex}`.
So I want to define it in my `configuration.org` document, and when i star emacs i want that, in addition of inint.el file, i want that it produce also a `header.tex` that i can use. How can I do?

I think what you are trying to achieve does not really require the workaround of generating a header.tex file, though you could certainly do that with Emacs.

The best thing in your case would be to define a custom LaTeX class, so at the beginning of your .org file you would simply call `#+LATEX_CLASS: myarticle`, for example:

``````(add-to-list 'org-latex-classes
'("myarticle"
"\\documentclass{scrreprt}
\\usepackage{geometry}
\\usepackage{fontspec}
\\usepackage[applemac]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage[main=british,italian]{babel}
\\usepackage{chemfig}
\\usepackage{mol2chemfig}
[NO-DEFAULT-PACKAGES]
[PACKAGES]
[EXTRA]"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
``````

• i try to implement this but it doesn't work. so i add `(with-eval-after-load 'ox-latex` before and it compile, but when i call the class from a test file it doesn't work. – acidwinzip 77 Jul 12 '18 at 15:58
• sorry, `#+LATEX_CLASS: myarticle`. I just fixed the answer. Good point about `with-eval-after-load` as well, but that's a bit tangent to the question at hand. – dangom Jul 12 '18 at 16:01

You can solve your problem easily by configuring the variable `org-packages-alist`, as shown in documentation:

org-latex-packages-alist is a variable defined in ‘org.el’. Its value is nil

Documentation: Alist of packages to be inserted in every LaTeX header.

These will be inserted after ‘org-latex-default-packages-alist’. Each element is either a cell or a string.

A cell is of the format:

``````("options" "package" SNIPPET-FLAG)
``````

....

Take care to insert packages which not conflict with already declared packages in variable `org-latex-default-packages-alist` - this one can be also customized.

This way you do not need any additional export file as header.

• But my aim is to not modify anithing except configuration.org, so everything I need to see is under that file – acidwinzip 77 Jul 12 '18 at 16:14

Thats a different solution but the result is better. I removes the need for an extra file. You can add

``````#+LATEX_HEADER: \usepackage{package}
``````

To your org-file to do same. Or if you use ox-extra.

``````#+header: header: yes
#+begin_export latex
\usepackage{package}
#+end_export
``````

You just need the fix from: https://lists.gnu.org/archive/html/emacs-orgmode/2015-11/msg00427.html