[Tex/LaTex] How to define (user defined) functions in math mode

math-operators

I am used to define some complicated and frequent mathematical expressions to be able to use them easily in my papers. For example I have defined
\def\c{{\mathbb{C}}} for $\mathbb{C}$ (the field of complex numbers).

However sometimes there are more complicated formulas and mathematical expressions which involve one, two, or more variables (or parameters). For example, consider $Hom_{\mathbb{Z}} (M,N)$ which involves two variables $M$ and $N$.

My question is "how can I define such expressions generally with the ability to change the variable inside them.

Best Answer

These are not variables in "typesetting sense". You could define

\newcommand{\Hom}[3]{\operatorname{Hom}_{#1}(#2,#3)}

and then use

\Hom{Z}{M}{N}

for getting

HomZ(M, N)

but this is no way more expressive or readable than

\Hom_{Z}(M,N)

after having defined

\DeclareMathOperator{\Hom}{Hom}

Actually, I contend that the latter form is much more readable than the first one.


Note. Be careful in saying

\def\c{\mathbb{C}}

because \c is an "accent command" in LaTeX (\c{c} is used in French, Albanian, Turkish, Portuguese, Catalan and other languages). Always use \newcommand or, if you really know what you're doing, \renewcommand; but don't redefine general use commands: if one of your bibliography items contains a "รง" you'll regret having redefined \c.

Related Question