8

Suppose we have the following code

\documentclass{article}
\begin{document}
$a=b=c=d=e=f=g=h=i=j=k=l=m=n=o=p=q=r=s=t=u=v=w=x=y=z$
\end{document}

which produces the following result Result

I want to have an additional equal sign automatically added before symbol s.

UPDATE

The same question about \leq and

$a \leq b \leq c \leq d \leq e \leq f \leq g \leq h \leq i \leq j \leq k \leq l \leq m \leq n \leq o \leq p \leq q \leq r \leq s \leq t \leq u \leq v \leq w \leq x \leq y \leq z$
Ivan Bychkov
  • 731
  • 1
  • 6
  • 13
  • Is this method supposed to work for inline-math situations only? The reason I ask is that most display-math environments (other than those of the breqn package) force you to choose explicit line break points -- giving you a chance to supply the extra = sign. Separately, should you maybe be concerned that consecutive = signs without intervening material might confuse your readers? – Mico Jun 25 '12 at 00:43
  • 1
    I know that this is traditional of Russian typography; but it's unnecessary and, in my opinion, confusing. Perhaps not so much when the equals sign is repeated, but it surely is when a binary operation symbol is repeated. – egreg Jun 25 '12 at 08:10
  • Yes, strictly speaking it's unnecessary, but it's a tradition I would like to follow. – Ivan Bychkov Jun 25 '12 at 16:59
  • @egreg: Did not know that applied to binary relations as well. Repeating a - sign actually changes the meaning as 9 - 5 is different than 9 - -5 (over two line), so am surprised that that is the standard in Russian typography. – Peter Grill Jun 25 '12 at 18:44
  • It is applied mainly to = and +. – Ivan Bychkov Jun 25 '12 at 21:08
  • 1
    I've added the definition for \leq as requested. For + it's just like for =. – egreg Jun 26 '12 at 20:29
  • Thanks. The transformation from the original definition is really unobvious. – Ivan Bychkov Jun 26 '12 at 21:01

2 Answers2

10

I wouldn't recommend such repetition. However, with a modification of this answer you can get what you want:

\documentclass{article}
\usepackage{amsmath}

\mathchardef\mathequals=\mathcode= \begingroup\lccode~== \lowercase{\endgroup\def~}{\mathequals\discretionary{}{\the\textfont0=}{}} \AtBeginDocument{\mathcode=="8000 }

\begin{document} $a=b=c=d=e=f=g=h=i=j=k=l=m=n=o=p=q=r=s=t=u=v=w=x=y=z$ \end{document}

The \AtBeginDocument is necessary because amsmath uses the = symbol for some of its initializations. It doesn't hurt when amsmath is not loaded.

Other math symbols

Let's see how we can redefine \leq to have the same properties as =. I adapted a trick that I believe is due to the late Michael J. Downes (the main developer of amsmath):

\let\mathleq=\leq
\def\getmeaning#1"#2#3{\noexpand\the\textfont"#3\char"}
\begingroup\edef\x{\endgroup
  \def\leq{\mathleq\discretionary{}{\expandafter\getmeaning\meaning\mathleq}{}}}\x

The expansion of \meaning\mathleq is \mathchar"3214 and we need to save the 2 (which is needed as argument to \textfont) leaving 14 in the input stream. After the \edef we get

\def\leq{\mathleq\discretionary{}{\the\textfont"2\char"14}{}}

that is similar to what I used before for =.

egreg
  • 1,121,712
  • I noticed that current version of solution isn't a friend of \usepackage{amsmath}. – Ivan Bychkov Jun 25 '12 at 21:16
  • Now it is fine. – Ivan Bychkov Jun 25 '12 at 21:45
  • I managed to adapt your solution to some other binary operation symbols. But I couldn't do it for \leq. Could you provide an extended version of solution suitable for this case also ? – Ivan Bychkov Jun 26 '12 at 20:25
  • The first part solution for equality symbol breaks cases when = is used as part of something else. For example, \coloneqq or := is broken up as := and =. (This does not bother me but might be useful for readers to know). Surprisingly, the package rmathbr breaks (here: makes dysfunctional) \coloneq and \coloneqq altogether (at least in conjunction with all other packages I'm using). – Linear Christmas Mar 18 '20 at 15:17
2

From http://dxdy.ru/post82175.html

In preambule:

\def\?#1{#1\nobreak\discretionary{}{\hbox{$\mathsurround=0pt #1$}}{}}

Then you should add \? before operations:

\begin{document}
$a \?\leq b \?\leq c \?\leq d \?\leq e \?\leq f \?\leq g \?\leq h \?\leq i \?\leq j \?\leq k \?\leq l \?\leq m \?\leq n \?\leq o \?\leq p \?\leq q \?\leq r \?\leq s \?\leq t \?\leq u \?\leq v \?\leq w \?\leq x \?\leq y \?\leq z$
\end{document}
Dmitry
  • 134