6

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.

  • 1
    Are you looking for a way to define macros with parameters? For example \Homz{M}{N} to give this output? – marczellm Jan 24 '13 at 12:08
  • Yes something like that. How is it possible? – user24323 Jan 24 '13 at 12:11
  • 2
    A suggestion: don't use \c for some command (for example, complex numbers). I'm warning because it happened to me. I got a file with this personal command used a lot of times and I was not able to use the \c c to produce ç. So some find/replace was necessary. – Sigur Jan 24 '13 at 12:11
12

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.

  • I had that problem with ç. See my comment above... lol – Sigur Jan 24 '13 at 12:15
  • @egreg: Thank you. It is exactly what I was looking for. It may seem less readable, but it will help me in writing papers. – user24323 Jan 24 '13 at 12:23
  • @VahidShirbisheh I don't think so. I tell you because I used that way in my first experiences with TeX/LaTeX and changed my mind after seeing that it doesn't shorten the typing nor it makes the input more readable. – egreg Jan 24 '13 at 12:46
5

On the preamble, use

\DeclareMathOperator{command}{text}

to define math operators. For example, you can use

\DeclareMathOperator{\Hom}{Hom}

to define the command \Hom, and use it as $\Hom_Z(M,N)$. Compare with $Hom_Z(M,N)$.

enter image description here

Now, if you want to insert the modules as variables, you can define a new command and pass them like you do with \frac{}{}, for example.

\newcommand{\myhom}[2]{\Hom_Z(#1,#2)}

So you can format any variable globally just formating the #1, for example.

  • Could you give an example how it works? How should I introduce the variables? – user24323 Jan 24 '13 at 12:03
  • Thanks Sigur. But it does not look that much easier. I am looking for a way to define the whole bifunctor Hom with the ability to use different modules M and N whenever I needed. – user24323 Jan 24 '13 at 12:10
  • But it is the same: type \Hom(M,N) with () or \Hom{}{} with {} 2 times takes almost the same time. I believe that the right way is to use it as operator, to format the font shape. But arguments to it, I think irrelevant. – Sigur Jan 24 '13 at 12:14
  • I just tried \newcommand{\Hom}[3]{\operatorname{Hom}_{\mathbb{#1}}(#2,#3)} and it works perfectly. I am sure it will help me to save time in writing repeated formulas with different variables. – user24323 Jan 24 '13 at 12:26

Your Answer

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