1

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}
  • just use \newcommand{\z}{{\mathbf{z}}(k)} but $\mathbf{z}(k)$ has strange spacing, perhaps better would be \DeclareMathOperator\z{z} then $\z(k)$ so \z gets the same space rules as \log – David Carlisle Oct 13 '15 at 20:38
  • There's no reason for using \DeclareMathOperator in this case. – egreg Oct 13 '15 at 22:44
2

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.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.