[Tex/LaTex] Where should I define new command globally

document-classesmacros

I'd like to define a command \alert{} by

\newcommand{\alert}[1]{\textcolor{red}{#1}}

in a way that I could use it on every new file.

I was thinking to define it on some cls file (amsart for example). But if I create a new file using report class the new command will not work.

Is there some internal file where I could define my command to work as a default LaTeX command. For example, using any class we can make use of some commands (\textrm{} for example). So I guess that there is some file to be loaded globally.

Best Answer

Adding a "global" command is possible. But one of the strengths of the TeX system is portability: if you have the same TeX distribution on two machines, the same file will compile on both, with the same result.

What would happen in your case is that compiling the document on a different machine would bang out with an

! Undefined control sequence

error.

The safest way is to have a file, say sigur.sty containing the lines

\ProvidesPackage{sigur}[2012/01/10 Local macros by Sigur]

\RequirePackage{color}
\newcommand{\alert}[1]{\textcolor{red}{#1}}

with possibly other definition you deem useful, and save it in the "local tree", that is as

/usr/local/texlive/texmf-local/tex/latex/sigur/sigur.sty

and doing

sudo mktexlsr

after that operation.

Any user on your machine will be able to say

\usepackage{sigur}

in their document. Don't forget to enclose the file when you distribute a document using it.

Also, don't forget to document your macros.