[Tex/LaTex] How to reuse new command among different files to keep them consistent

best practicesmacros

I have several .tex files with \newcommand in the beginning, I found it really cumbersome to copy and paste these new commands each time I have a new .tex file, and it is easy to make mistakes and hard to keep the new commands up to date. Is there a way to make a head file with all my new commands, typeset it so that the new commands apply to all my tex files?

Best Answer

The simplest way would be to just place your common macro definitions into a separate .tex file an \input 1 this in the preamble of all documents.

You can also just make your own package. The only differences (if you don't want to use package options with it) are to name it somename.sty and to add \ProvidesPackage{somename} as first macro. Then load it using \usepackage{somename} instead of \input.

Note that you can place you common file into your own TEXMF tree where it is then found by LaTeX, so that the file does not need to be in the same directory any more.

1) no, do not use \include for this