0

When I write out $2 \operatorname{Re} z$, I get the expected output rendered, which is:

enter image description here

However, when I define the macro $\Re$ for it in MathJax as

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    ...
    TeX: {
      Macros: {
        Re: ["{\\operatorname{Re}{#1}}",1]
        }
      }
    });
</script>

and write $2 \Re z$, the rendered output is

enter image description here

where the spacing after Re is rendered as expected, but the spacing before Re is not (i.e., the 2 is too close to the Re).

How do I get the expected spacing before the Re? (I don't expect this to be a MathJax issue; the config is included just in case.)

rorty
  • 103

1 Answers1

3

The issue is braces.

Try compiling the following document

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$ 2 \operatorname{Re} z $

$ 2 {\operatorname{Re} z} $
\end{document}

The latter is what you included in the MathJax config. By declaring \operatorname{Re} you indicated that it should be spaced like \mathop (see this post for more explanation), but the spacing rules are only observed if there is another object in front of it of the right type. By including the extra set of braces, you suppressed this extra spacing.

In a TeX document I would normally also not define a new macro to be \operatorname{Re} and instead use the \DeclareMathOperator; I don't know if this is possible within MathJax's configuration. In any case, try removing the outermost layer of braces in your config file and see if that fixes the issue.

Also, \operatorname takes one argument. I am not sure whether there is a need to define your \Re command so that it effectively takes one additional argument. I would probably have written just

Re: "\\operatorname{Re}"

as your macro definition in MathJax.

Willie Wong
  • 24,733
  • 8
  • 74
  • 106
  • This solved my issue. I had blindly followed another person's config who used those braces. And the reason I had explicitly included the single argument is that it corrected the spacing between Re and z when I had those extra braces. Thanks! – rorty Nov 26 '19 at 04:38