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?

  • 5
    Create your own \mycommands.sty style file, so that each invocation of it is merely \usepackage{mycommands}. It starts with \ProvidesPackage{mycommands} and ends with \endinput. What goes in between is up to you. Jan 13 '17 at 16:58
  • write all the defines in a separate file and use \include or \import tex.stackexchange.com/questions/246/… Jan 13 '17 at 16:58
  • 3
    Note that Steven meant to write mycommands.sty not \mycommands.sty.
    – jon
    Jan 13 '17 at 17:24
  • 2
    @jon: In such cases we would give a kingdom for editing comments even after 5 minutes ;-)
    – user31729
    Jan 13 '17 at 17:28
  • 2
    @TimothyTruckle never use \include for including definitions, it should only be used after \begin{document} Jan 14 '17 at 11:47

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.