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$
7
  • 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, 2012 at 0: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, 2012 at 8:10
  • Yes, strictly speaking it's unnecessary, but it's a tradition I would like to follow. Jun 25, 2012 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. Jun 25, 2012 at 18:44
  • 1
    I've added the definition for \leq as requested. For + it's just like for =.
    – egreg
    Jun 26, 2012 at 20:29

2 Answers 2

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 =.

4
  • I noticed that current version of solution isn't a friend of \usepackage{amsmath}. Jun 25, 2012 at 21:16
  • Now it is fine. Jun 25, 2012 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 ? Jun 26, 2012 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). Mar 18, 2020 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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .