I am currently using MathJax inside of a Jupyter notebook running a Julia 1.0 kernel and attempting to use \newcommand, but it seems like the documentation and posts I've read for \newcommand conflicts with what I am seeing.

When I use: \newcommand{\Dot}[2][X]{\mathbf{#2}\cdot\mathbf{#1}}, my expectation is that when I use \Dot{a}{b} I would see the output of \mathbf{a}\cdot\mathbf{b}, however I am seeing output of \mathbf{a}\cdot\mathbf{X}b. In order to see my expected output, I have to use: \newcommand{\Dot}[3][X]{\mathbf{#3}\cdot\mathbf{#2}}. I thought that maybe the first argument was some sort of function name placeholder or something a la the first element of argv in C, so I tried \newcommand{\Dot}[2][X]{\mathbf{#3}\cdot\mathbf{#2}}, but then use of the macro doesn't render.

What am I missing here?

  • 6
    With \newcommand{\Dot}[2][X]{\mathbf{#2}\cdot\mathbf{#1}} you have to use it like \Dot[b]{a}. The optional argument always has to be the first and given in square brackets, see also latexref.xyz/… Dec 12, 2019 at 4:05
  • 10
    Also keep in mind that MathJax is not LaTeX. Dec 12, 2019 at 4:05
  • 4
    Note that questions about MathJax are off-topic on this site.
    – cfr
    Dec 12, 2019 at 4:48
  • 1
    You need to ask the mathjax people how they support newcommand with optional args. As mentioned this is javascript not latex, so off topic
    – daleif
    Dec 12, 2019 at 7:12
  • 2
    @MadyYuvi I don't see why this is off topic, the OP mentioned mathjax but the syntax error causing the problem applies to latex and has a purely latex answer as given in Henri's first comment above. Dec 12, 2019 at 8:28

1 Answer 1


defines a command with an optional argument, and optional arguments are always marked with [] in LaTeX and placed as the first argument (if used), so the use would be

\Dot{a} to produce a·X

\Dot[Y]{a} to produce a·Y

The declaration that would match the call that you tried would be to have two mandatory arguments so


with use

\Dot{X}{a} to produce a·X

\Dot{Y}{a} to produce a·Y

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.