# Combining everything before begin document into a package [duplicate]

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.

Thanks

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

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{MyProject}[2018/03/10 v1.0 Class for my project]

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

% other stuff from the preamble

\endinput


\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:

\documentclass{MyProject}
\begin{document}
...
\end{document}


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

\documentclass{<class>}[2018/03/10]