The inspection of the math list happens after expansion (and after assignments). It is an extra stage just applicable to math mode that converts the math list into a horizontal list that is then typeset as a normal horizontal list.
So there is no real connection between the macro structure and the math spacing, It does not matter whether the thing to the left of the +
has arguments or not, it just matters what it expands to (nothing in your example) so your example is equivalent to
\noindent
\( +x\) \\ % unary: "+x"
\( +x\) \\ % unary: "+x"
\({} +x\) \\ % binary: " + x"
\( +x\) \\ % unary: "+x"
\({} +x\) \\ % binary: " + x"
and as your comments show a binop like +
gets binary spacing if it is between two mathord atoms such as {}
or x
.
Your example (from elsewhere, with \somecommand
being a zero-argument macro)
\(\somecommand{} {+} x\)
is
\({} {+} x\)
Here the {+}
construct makes a mathord so you get no spacing. My comment that this was probably bad markup was mainly related to the trailing {}
after \somecommand
it is OK to do that habitually in text mode to avoid dropping spaces but in math mode it's usually has an effect.
\(\somecommand{} {+ x}\)
is
\({} {+ x}\)
so here the math list has two, not three, mathord atoms: {}
and +x
. In this simple case it doesn't affect the spacing, but the inner expression is a single atom, so {+x}
(and not x
) would take any superscripts etc, and as it is an inner list linebreaking is suppressed and any white space is forced to its natural width (again not relevant here); basically in math node {...}
is a box command like \hbox{....}
.
There are in fact two choices for a unary math sign, a mathord or a mathop, it's easy to get an ad hoc mathord by using {+}
but it is probably more consistent to declare the operators explicitly.
1 $a-+b$
2 $a-{+}b$
3 $a-\mathord{+}b$
4 $a-\mathop{+}b$
5 $x+y$
6 $x{+}y$
7 $x\mathord{+}y$
8 $x\mathop{+}y$
As you see from (1) if two binop atoms are adjacent the second one effectively turns into a mathord so you get the spacing as in (2) or (3) although arguably as a prefix operator giving it mathop spacing (with a small gap before its argument) is more consistent.
either way you don't want to be filling you document expressions with weird {}
constructs and \mathxx
primitives, just define
\unaryplus{{+}}
or whatever version you like and then use
a + \unaryplus b
and it will all work out OK.
Here are two options:
\documentclass{article}
\usepackage{amsmath}
\newcommand{\subplus}{\mathbin{\genfrac{}{}{0pt}{}{}{+}}}
\newcommand{\subminus}{\mathbin{\genfrac{}{}{0pt}{}{}{-}}}
\newcommand{\subcdots}{\genfrac{}{}{0pt}{}{}{\cdots}}
\begin{document}
Option 1:
\[
1 - \begin{array}{@{}*{8}{c@{}}}
1 & & 1 & & 1 & & 1 \\ \cline{1-1}\cline{3-3}\cline{5-5}\cline{7-7}
1 & {}+{} & 1 & {}-{} & 1 & {}+{} & 1 & {}- \cdots
\end{array} =
\frac{\sqrt{5}-1}{2}
\]
Option 2:
\[
1 - \frac{1}{1} \subplus \frac{1}{1} \subminus \frac{1}{1} \subplus \frac{1}{1} \subminus \subcdots =
\frac{\sqrt{5}-1}{2}
\]
\end{document}
OptionĀ 1 sets the fraction as an array
, using \cline
to simulate the fraction lines. OptionĀ 2 uses amsmath
to set a fraction with 0pt
horizontal rule. Additional macros have been created to set these using \subplus
, \subminus
and \subcdots
.
Best Answer
Using math mode (best solution):
If you don't want to use math mode (worst solution):