How to define a math command that displays a variable in a specific font?

How to define a math command that displays a variable in a specific font? E.g. usage \MyMathCommand{P}.

-

You could use

\newcommand{\MyMathCommand}[1]{\mathbf{#1}}


which would print the variable in boldface (perhaps typical of matrix or vector notation). There is also \mathit (for italic math) and \mathsf (for sans serif fonts). These can be mixed in some fonts. You may be interested also in \mathcal (for calligraphy-style letters, perhaps used in set notation) or something else altogether.

If you wish for this command to work in either text or math mode, you can use:

\newcommand{\MyMathCommand}[1]{\ensuremath{\mathbf{#1}}}

-