I am putting together a large document and my preamble is unwieldly and disorganised. What order does it make sense to load packages. Obviously, hyperref goes last, apart from things that have to go after hyperref. I tend to load font packages first, as they seem like a big global change. What other categories should I arrange my preamble around? Are there other cases where load order is important? Should I keep other commands close to the packages they relate to? e.g. should I keep my bibliography formatting commands near my \usepackage{biblatex} call?
|
|
|||||||||||
|
|
If you want to see how things can get tangled in a preamble have a look at the preamble of the Comprehensive LaTeX Symbol List. It might not be exactly spaghetti code but it can certainly be classified as code soup! So you right, you need to have a strategy and start working on it early in the development of your document. The tips below are from my own workflow and observations. Early on, when I started with LaTeX, I realized that having used numerous macros and packages to change the looks of almost every single parameter originally set by the LaTeX 1. Consider developing your own class or package to hold your changes. It is as simple as hitting a 2. Have the packages and own related commands, near each other For smaller changes, i.e., write short packages, either using the doc/docstrip system or if you are in a hurry just use the package
Similarly, for tables
3. Divide the preamble into headings, such as If you do not develop your own class and use any of the major classes such as 4. Have the problematic package settings in their own packages e.g., Some packages are difficult to set and can give you problems if they are loaded before or after some packages (See Which packages should be loaded after hyperref instead of before?). Others need some complicated and long settings. Again here if you work on a long documents it may be worth changing these settings to small packages. If you identify sources of errors better save and restore commands rather than move them around. For example the
There are a lot of similar techniques in the Comprehensive LaTeX Symbol List, preamble, worth a read. |
|||||||||||||||
|
|
It's a somewhat peripheral matter, but I ordinarily comment Examples:
Of course, specifying the purpose of a given package helps me classify it in relation to others — its function is not the same in all documents. |
||||
|
|
|
As you've already observed, loading Without knowing what your document is about, I don't believe it's possible to give very specific recommendations on how your document's preamble should be organized/structured. The following comments and notes are therefore a bit generic.
|
|||||||||||||||||
|
|
Here's a detail that'll probably be trivial to most, but made me stumble one time: Put the metadata ( I was just used to putting it first in my preamble because these commands were among the first things I learned in LaTeX, so they stayed at the top, while other things (= packages) were added at the bottom. Another detail that won't matter in most situations, but can nonetheless easily be done: Put |
|||||
|
|
Preambles that load a lot of packages (or large packages, such as TikZ) can really slow down your workflow. TeX supports format (.fmt) files, which store TeX data structures in serialized form. TeX can reload them and pick up where it left off in processing a given document. By creating a format file, you can avoid re-loading packages every time you build your document. Creating a format file requires a number of steps (I'm using
After the above, you can modify This is a good place to plug Chris Monson's LaTeX Makefile, which will re-make your format file as needed (i.e., |
|||||||||||||
|