2

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.

4
  • 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{{=}{+}}`. Commented May 7, 2015 at 19:13
  • Cheers, I tried to look around but sometimes its a problem to find these things without the right keywords! Commented May 7, 2015 at 19:35
  • 1
    If you are trying to write C code, you might look at the listings package. Commented May 7, 2015 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) Commented May 7, 2015 at 23:41

1 Answer 1

6

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{{+}{=}}} 
4
  • It has been touched here: tex.stackexchange.com/questions/55701/… Commented May 7, 2015 at 19:34
  • Thanks. I think one can actually also define an operator as follows: \DeclareMathOperator{\pluseq}{\mathbin{{+}{=}}} Commented May 7, 2015 at 19:37
  • @jbx No, \DeclareMathOperator is not the right way; just \newcommand is what you need. Commented May 7, 2015 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. Commented May 7, 2015 at 23:40

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.