# Where should I define new command globally?

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.

-
Adding a command to a class is surely a bad idea. Just make a "personal package" and load it for your documents. But it seems overkill: just have at hand a file with the most useful definitions and when you need one of them, paste it in the new document. – egreg Jan 9 at 23:52
What egreg said. Editing standard class files makes your document non-portable and hard to debug and means that if you distribute your tex setup anywhere you have almost certainly broken the licence conditions of the class you have modified. \textrm is compiled into the latex format no file needs to be read (unlike say \rm which is not defined in the format and only defined if at all by a class or package file) – David Carlisle Jan 10 at 0:00
If you are distributing it to other users you should definitely not modify amsart.cls or similar files. – David Carlisle Jan 10 at 0:01
Texlive for example installs texmf-var texmf tree (which is ore or less empty) in addition to texmf-dist (the main files) for exactly such site wide local installations – David Carlisle Jan 10 at 0:05
@Sigur I don't want to discourage you from sharing your knowledge this way. However, please remember that distributing a package to other people (even if it is not a real "LaTeX package") takes some serious considerations: Have I documented the code well? Do I provide a manual for it? Is the code good? Is the command naming good (in a code for yourself, you can have bunch of short macro names, because you know your code, but for others this is different)? Etc. etc. – tohecz Jan 10 at 0:07

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}


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.

-
 Impossible to have a better help. Thanks so much. I guess that I understand your explanation. I'll try it. – Sigur Jan 10 at 0:09 perfect. It works!! Thanks so much. – Sigur Jan 10 at 0:30