[Tex/LaTex] How to typeset the c++ increment symbol in LaTeX

relation-symbolssymbols

How can I typeset the increment "+=" symbol? It should act as a relation (like =), but should not have extra space between the "+" and "=".

Best Answer

It depends on what you consider right. The first thing to note is that the symbol should represent a relation. TeX puts no space between two consecutive relations (and no line break either). So

\documentclass{article}

\newcommand{\pluseq}{\mathrel{+}=}
\newcommand{\eqplus}{=\mathrel{+}}

\begin{document}
$x\pluseq 2$

$x\eqplus 2$
\end{document}

will produce

enter image description here

If you prefer a (font dependent) negative kerning, just add it; changing the above definitions into

\newcommand{\pluseq}{\mathrel{+}\mathrel{\mkern-2mu}=}
\newcommand{\eqplus}{=\mathrel{\mkern-2mu}\mathrel{+}}

you'd get

enter image description here

Experiment and decide. Having a macro means you can do whatever you want of the symbol, without changing anything in the document body.