I have the following inline code:
$\texttt{TEST}(v *= 2, v += 2, v = 4)$
But when it is rendered, the plus is very far away from the equal sign. How can I overcome this problem and make LaTeX consider += as a single operator?
math-mode
I have the following inline code:
$\texttt{TEST}(v *= 2, v += 2, v = 4)$
But when it is rendered, the plus is very far away from the equal sign. How can I overcome this problem and make LaTeX consider += as a single operator?
Best Answer
+
is a binary operator and=
is a binary relation. When TeX finds the sequenceit transforms it into
but a Bin is not allowed before a Rel, so it's changed into an Ord.
Solutions:
or, manually,
These exploit the fact that TeX doesn't insert any space between two consecutive Rel symbols.
You can also define a macro that switches the behavior, so you can type the formulas more naturally:
I added a nonsense line to show that
\switch
respects grouping. The scope of\switch
ends with the formula (or group) in which it's issued.