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?
Asked
Active
Viewed 4,648 times
9
Cragfelt
- 4,005
one-hand-octopus
- 221
1 Answers
8
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
Martin Scharrer
- 262,582
\mycommands.stystyle 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. – Steven B. Segletes Jan 13 '17 at 16:58\includeor\importhttp://tex.stackexchange.com/questions/246/when-should-i-use-input-vs-include – Timothy Truckle Jan 13 '17 at 16:58mycommands.stynot\mycommands.sty. – jon Jan 13 '17 at 17:24\includefor including definitions, it should only be used after\begin{document}– David Carlisle Jan 14 '17 at 11:47