sorry if the title is badly worded but I wasn't sure how to word it.

My question is this: I have a lot of things before \begin{document} in my latex file, maybe like 180 lines of setting up commands and use packages.

I was wondering if I could put all the code above the line \begin{document} into a package and import that in so I can save lines.


  • For a single document, you can just save all the files as e.g. mypreamble.tex and then use \input{mypreamble}. No real need to make a package. – Alan Munn Mar 10 '18 at 4:32
  • @AlanMunn A project specific preamble and a default preamble are different things. – Heiko Oberdiek Mar 10 '18 at 4:37
  • @HeikoOberdiek Of course, but the principles of creating the package are identical. – Alan Munn Mar 10 '18 at 4:38
  • @AlanMunn Not entirely. For a project I would rather use a class instead of a package, because I have then a really clean preamble for the document. – Heiko Oberdiek Mar 10 '18 at 4:42
  • Could you also put the \bibliographystyle in there as well? – Vass Mar 10 '18 at 4:45

You can write a class:

\ProvidesClass{MyProject}[2018/03/10 v1.0 Class for my project]
\LoadClass[<options>]{<class name>}% former: \documentclass[...]{...}

\RequirePackage[<options>]{<package name>}% former: \usepackage[...]{...}

% other stuff from the preamble


\documentclass and \usepackage need other names, see above. Also, remove \makeatletter/\makeatother pairs, because \makeatletter is automatically active in class and package files.

Then use the class:


A class or package have advantages over a simple \input:

  • Options can be added.
  • Some version support by LaTeX:


    Then, LaTeX will warn, if the class or package are older than specified.

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