1

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

1 Answers1

2

You can write a class:

\NeedsTeXFormat{LaTeX2e}
\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

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

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

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

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

Heiko Oberdiek
  • 271,626