# Error creating a \newcommand which uses \hspace

None of my \newcommand declarations work for \hspace, with or without arguments; I use the latest MathJax with the general libraries. Attempts so far:

\newcommand{hs}[1]{\hspace{#1}}
\newcommand{hs}[1]{\hspace{{#1}}}
\newcommand{hs}[1]{\hspace{{#1}px}}
\newcommand{hs1}[]{\hspace{10px}}


I have a pageful of other \newcommand declarations that work just fine, unsure what's failing here. Any remedy?

• Note that mathjax is not LaTeX so you should probably not expect any \newcommand to work. – daleif Jan 25 at 18:13
• @daleif \newcommand works in MathJax. – egreg Jan 25 at 18:24
• @PhelypeOleinik Excellent, it works - thanks. Feel free to post your response as an answer if you'd like the answer credit. – OverLordGoldDragon Jan 25 at 18:34
• @egreg out of the box with no extra configuration? – daleif Jan 25 at 19:16

In usual conditions, all commands in TeX must be preceded by a backslash, to tell TeX that they are commands, so instead of

\newcommand{hs}[1]{\hspace{#1}}


you need

\newcommand{\hs}[1]{\hspace{#1}}


which will work as you expect.


The second version adds an extra pair of braces that shouldn't be there, so it won't work as well.

\hspace{{1cm}} will expand to \hskip{#1}\relax, which isn't valid syntax and will throw you a Missing number error.

The third version is the same. The unit will only appear after the Missing number error, so it is of no use there. Besides, TeX doesn't know the unit px, so even if you remove the braces you'll still get a Illegal unit of measure.

The fourth contains, besides the illegal px unit, two problems. The first is that in usual circumstances numbers aren't allowed in command names, so you can't use \hs1. The second is that the first optional argument of \newcommand (the number of arguments) must not be empty ([]). An empty argument is very different from a missing argument! If you try to do that (after removing the number from the command name) you'll get another Missing number error because LaTeX was expecting a number there.