# Managing your custom LaTeX files

## Avoiding repetition

After any significant time using LaTeX you will probably end up with a large variety of commonly used packages.

% -------------------MATH PACKAGES --------------------------------------
\usepackage[binary-units=true]{siunitx} % SI units
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{microtype} % better fonts/apperance
\usepackage{bm} % boldface


You also might have a big list of macros that you reuse in multiple documents.

\newcommand{\linearize}[3]{\ensuremath{\left. \frac{\partial #1}{\partial #2} \right|_{#3} \delta #2}}
\newcommand{\norm}[1]{\ensuremath{\left\| #1 \right\|}}
\newcommand{\abs}[1]{\ensuremath{\left| #1 \right|}}
\newcommand{\Real}[1]{\ensuremath{\Re \left\{ #1 \right\}}}


This is one of the greatest benefits of using LaTeX, but it still requires that you ensure each new document has a copy of your packages and macros. There a variety of ways one could include this code into a new document

1. Simply copy the code into the preamble
2. Copy the file into the working directory and use \input or \include

Both of these approaches run into trouble when you add new macros without explicitly ensuring you’ve updated the local copy. Instead here I’ll describe another, much more robust solution

## Local texmf tree

Every TeX distribution will automatically search your local ~/texmf directory. In this directory you can store all of your commonly used files, and every document on your system will automatically have access to them. The paths are:

• Windows XP: C:\Documents and Settings\<user name>\texmf\
• Windows 7: C:\Users\<user name>\texmf\
• Linux: ~/texmf/
• MacOS: /Users/<user name>/Library/texmf/

### Personal Style and Macro Files

You can define your own set of commonly used packages using a style file. Simply create a file my_packages.sty in ~/texmf and add the following as the first line

\ProvidesPackage{my_packages}
\usepackage{siunitx}
\usepackage{amsmath}


and in all of your documents you can then use \usepackage{my_packages}. You can also add all of your custom macros to this file so they’ll always be available and there is only a single place to maintain them, rather than spread all over you system.

This is also the ideal location to keep a .bib file if you’re using a reference management system. Now all of your citations/references are in a central location and available to your system.

## My approach

I store my often used packages and macros in my texmf tree. I’ve also saved this as a git repository so it’s backed up and version controlled. In case a future change breaks an older document I can always return to a previous version.

In addition, git makes it very easy to keep track of these personal files across multiple computers. I simply clone the repo and have all of my custom LaTeX macros and references on any new system.

There’s a standard structure to the texmf directory and you can read about it below. Also there’s a link to my own setup, with my packages and master BibTeX library.