2

This question already has an answer here:

I have these operators +=, -= etc. in Math mode. LaTeX introduces space around single character operators. So I get + = and - = instead.

However, in my case I want no space between the + and the =, and similarly between the - and the = in the second operator.

How do I make them near each other such that there are is no horizontal space between them? I tried to put them in \mathit but it didn't have any effect.

marked as duplicate by egreg math-mode May 7 '15 at 19:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • i'm sure this has been asked before, hence a comment, not an answer. wrap each operator in braces, and wrap the whole thing in \mathrel, like this: \mathrel{{+}{=}}' and \mathrel{{=}{+}}`. – barbara beeton May 7 '15 at 19:13
  • Cheers, I tried to look around but sometimes its a problem to find these things without the right keywords! – jbx May 7 '15 at 19:35
  • 1
    If you are trying to write C code, you might look at the listings package. – John Kormylo May 7 '15 at 19:44
  • @JohnKormylo Thanks. No its not source code. Its still in math mode, defining a transition function of a state with numeric variables. (Its a bit weird I know, I didn't invent it) – jbx May 7 '15 at 23:41
5

the two symbols aren't in the same class, so they'll invariably get some space in between.

to turn an operator or a relation into an "ordinary" character, wrap it in braces. then, combine them and wrap the whole thing in braces, applying \mathbin or \mathrel as appropriate:

\documentclass{article}
\begin{document}
\[ a \mathbin{{+}{=}} b \mathrel{{=}{+}} c \]
\end{document}

output of example code

(i'm still sure this has been covered before.)

The operator can also be defined in the preamble so that it can be reused:

\newcommand{\pluseq}{\mathbin{{+}{=}}}
  • It has been touched here: tex.stackexchange.com/questions/55701/… – hpekristiansen May 7 '15 at 19:34
  • Thanks. I think one can actually also define an operator as follows: \DeclareMathOperator{\pluseq}{\mathbin{{+}{=}}} – jbx May 7 '15 at 19:37
  • @jbx No, \DeclareMathOperator is not the right way; just \newcommand is what you need. – egreg May 7 '15 at 19:47
  • @egreg Thanks. Yes with \DeclareMathOperator it seems to show it in a different way. For example the * is vertically aligned to the top, while with your way its correct. Not sure why, but at least it works fine. – jbx May 7 '15 at 23:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.