Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This is a very short question and hopefully there's a short answer. I know I can use \stackrel{top}{bot} to vertically merge two symbols into one with top on top and bot on the bottom. Is there something similar for left-right merging? I ask because I want to make a += symbol (for an additive update step in code). If there's already a symbol for that, that would be OK too.

share|improve this question
10  
\mathrel{{+}{=}} –  egreg Jan 23 '13 at 17:09
    
More semantic than the following proposition ! –  projetmbc Feb 27 '13 at 15:57

2 Answers 2

For this problem the solution is quite simple:

\mathrel{+}=

so that the combination will be treated as a relation, since = is a relation and TeX never puts space between two relation symbols. So

$a \mathrel{+}= b$

will be rendered as

enter image description here

You might want to define a shorthand

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

and input the formula above as

$a \pluseq b$
share|improve this answer

While egreg's answer is great for the user's specific question, there is another technique that can be used for the more general case if the two symbols to be combined need some resizing or vertical shifting before being joined. It employs the scalerel package (which I just today submitted to CTAN), which allows one to scale/shift one object relative to a second object. For example, with the command

$\scalerel{$K$}{\spadesuit}$

one can join things in a way which may be more visually pleasing than merely placing the two symbols adjacent. Here is a pic of the comparison:

enter image description here

Since the package is not available until it gets distributed in a few days, I include the style package below

\ProvidesPackage{scalerel}[2013/02/27]

\usepackage{calc}
\usepackage{tikz}
\global\newlength\thesrwidth
\global\newlength\thesrheight
\global\newlength\srblobheight
\global\newlength\srblobdepth
\global\newlength\mnxsrwidth
\newsavebox{\prebox}

\newcommand\scalerel{\@ifstar{\scalerelplain}{\scalerelplus}}

\newcommand\scalerelplain[3][99in]{%
  \sbox{\prebox}{$#2$}%
  \setbox0\hbox{$#3$}%
  \setlength\srblobheight{\ht0+\dp0}%
  \setlength\srblobdepth{\dp0}%
  \setbox0\hbox{$#2$}%
  \setlength\thesrwidth{\wd0*\ratio{\srblobheight}{\ht0+\dp0}}%
  \setlength\thesrheight{\ht0*\ratio{\srblobheight}{\ht0+\dp0}}%
  \setlength\mnxsrwidth{#1}%
  \ifdim\thesrwidth>\mnxsrwidth\setlength\thesrwidth{\mnxsrwidth}\fi%
  \raisebox{-\srblobdepth+\dp0*\ratio{\srblobheight}{\ht0+\dp0}}%
           {\resizebox{\thesrwidth}{\thesrheight}{\usebox{\prebox}}}%
}

\newcommand\scalerelplus[3][99in]{\scalerelplain[#1]{#2}{#3}#3}

\newcommand\stretchrel{\@ifstar{\stretchrelplain}{\stretchrelplus}}

\newcommand\stretchrelplain[3][10000]{%
  \sbox{\prebox}{$#2$}%
  \setbox0\hbox{$#3$}%
  \setlength\srblobheight{\ht0+\dp0}%
  \setlength\srblobdepth{\dp0}%
  \setbox0\hbox{$#2$}%
  \setlength\thesrwidth{\wd0}%
  \setlength\thesrheight{\ht0*\ratio{\srblobheight}{\ht0+\dp0}}%
  \setlength\mnxsrwidth{\thesrheight*100/#1}
  \ifdim\thesrwidth<\mnxsrwidth\setlength\thesrwidth{\mnxsrwidth}\fi%
  \raisebox{-\srblobdepth+\dp0*\ratio{\srblobheight}{\ht0+\dp0}}%
           {\resizebox{\thesrwidth}{\thesrheight}{\usebox{\prebox}}}%
}

\newcommand\stretchrelplus[3][10000]{\stretchrelplain[#1]{#2}{#3}#3}

\newcommand\scaleto[3][99in]{%
  \sbox{\prebox}{$#2$}%
  \setlength\srblobheight{#3}%
  \setlength\srblobdepth{0pt}%
  \setbox0\hbox{$#2$}%
  \setlength\thesrwidth{\wd0*\ratio{\srblobheight}{\ht0+\dp0}}%
  \setlength\thesrheight{\ht0*\ratio{\srblobheight}{\ht0+\dp0}}%
  \setlength\mnxsrwidth{#1}%
  \ifdim\thesrwidth>\mnxsrwidth\setlength\thesrwidth{\mnxsrwidth}\fi%
  \setlength\srblobdepth{\dp0*\ratio{\srblobheight}{\ht0+\dp0}}%
  \raisebox{-\srblobdepth+\dp0*\ratio{\srblobheight}{\ht0+\dp0}}%
           {\resizebox{\thesrwidth}{\thesrheight}{\usebox{\prebox}}}%
}

\newcommand\stretchto[3][10000]{%
  \sbox{\prebox}{$#2$}%
  \setlength\srblobheight{#3}%
  \setlength\srblobdepth{0pt}%
  \setbox0\hbox{$#2$}%
  \setlength\thesrwidth{\wd0}%
  \setlength\thesrheight{\ht0*\ratio{\srblobheight}{\ht0+\dp0}}%
  \setlength\mnxsrwidth{\thesrheight*100/#1}
  \ifdim\thesrwidth<\mnxsrwidth\setlength\thesrwidth{\mnxsrwidth}\fi%
  \setlength\srblobdepth{\dp0*\ratio{\srblobheight}{\ht0+\dp0}}%
  \raisebox{-\srblobdepth+\dp0*\ratio{\srblobheight}{\ht0+\dp0}}%
           {\resizebox{\thesrwidth}{\thesrheight}{\usebox{\prebox}}}%
}

\endinput
share|improve this answer
    
In response to a possible criticism that, in my example, the scalerel result is now descended and enlarged with respect to the baseline font, that can be remedied by rescaling that result to conform in size and baseline to the capital letter A as follows: \scalerel*{\hbox{$\scalerel{$K$}{\spadesuit}$}}{A} –  Steven B. Segletes Feb 27 '13 at 15:20
    
scalerel is now available at ctan.org/tex-archive/macros/latex/contrib/scalerel –  Steven B. Segletes Mar 1 '13 at 23:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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