# Arguments in newcommand



What am I missing here?

• 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
• Also keep in mind that MathJax is not LaTeX. Dec 12, 2019 at 4:05
• Note that questions about MathJax are off-topic on this site.
– cfr
Dec 12, 2019 at 4:48
• You need to ask the mathjax people how they support newcommand with optional args. As mentioned this is javascript not latex, so off topic Dec 12, 2019 at 7:12
• @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

\newcommand{\Dot}[2][X]{\mathbf{#2}\cdot\mathbf{#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

\newcommand{\Dot}[2]{\mathbf{#2}\cdot\mathbf{#1}}


with use

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

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