7
$\begingroup$

$\def\test{{\rm test}}$Is it an acceptable way to do a MathJax \def command like $\def\rg{{\rm rg}}$ to define a shortcut for a function, if it is frequently used in a question, like $$\begin{align*} \test(1) & = 1 \tag{\test} \\ \test(2) & = 2 \\ \test(3) & = 3 \end{align*}$$ Or should one refrain from this (or use another method)?

To provide an example, I added a $\def\test{{\rm test}}$ at the beginning of the post. Notice this will enable the use of \test even in comments of answers etc. See here for a discussion on that issue itself.

$\endgroup$
7
$\begingroup$

In addition to \DeclareMathOperator{}{}, one may want to introduce things which are not operators (e.g. shorthand for longer combinations), in which case one can use \newcommand{\command}{content}.

For example, when writing a very long answer which refers to the continuum hypothesis often enough, I might add a command \newcommand{\CH}{\mathsf{CH}} which would save time in rendering.

One can still use this to define operators by using \operatorname{diag} directly (if used once or twice) or by adding a new command as above.


AS WITH ALL NEW COMMANDS ADDED: Don't overuse it. It affects the LaTeX throughout the page (everything below the definition).

$\endgroup$
  • 1
    $\begingroup$ "Everything below the definition" could cause some weird bugs. For instance, voting patterns could adjust how posts are formatted. If one can redefine commands that have already been defined, two users could use this sort of formatting to display different messages depending on whose post is on top... $\endgroup$ – apnorton Nov 8 '13 at 4:44
3
$\begingroup$

A better way to introduce a new function name is DeclareMathOperator, as in \DeclareMathOperator{\diag}{diag} It provides correct font and spacing automatically.

$\DeclareMathOperator{\diag}{diag}$ Usage example: $\diag A$.

I think it is reasonable to use this capability, as long as you do not abuse the system by redefining existing operators.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .