[Tex/LaTex] New DeclareMathOperator

math-operators

In my MWE below, I wanted the create a shortcut for some operators. How can I get the \DeclareMathOperator command to show up like the conventional way of using the actual command $\mathbf{z}(k)$ ?

Also, is there an even shorter way to get this command, like say for example just type \z instead of $\z$ ?

Here is my code:

\documentclass[11pt]{book}
\usepackage{amsmath,amsfonts,amssymb,amsthm, bm} 

\DeclareMathOperator{\z}{{\mathbf{z}}(k)}

\begin{document}
How do I get this Math operator $\z$ to show like this $\mathbf{z}(k)$?
\end{document}

Best Answer

Quoting from this question, DeclareMathOperator is designed to create commands that should typeset operator names such as sin and lim. The default font for these quantities is upright. If you want part of the operator name to be slanted (in the way variables are usually typeset), you have to specify this explicitly:

\DeclareMathOperator{\z}{{\mathbf{z}}(\mathnormal{k})}

On the other hand, I would guess that what you actually want is that only the 'z' itself is the operator name:

\DeclareMathOperator{\z}{\mathbf{z}}

The part in parenthesis should be the argument to this operator. If you frequently use the same argument, you could define a short hand for this, using \newcommand:

\newcommand{\zk}{\z(k)}

Concerning your second question, if you encapsulate your definition with \ensuremath, you can use your command both within or outside of math environments:

\newcommand{\zk}{\ensuremath{\z(k)}}

With the last definition, both $\zk$ and \zk{} should give the same result.

Related Question