# Duplicate equal sign on line break in text mode

In Cyrillic typography tradition you need to duplicate the math operators (+, =, -, x) on line break. Following this answer I can get it working in math mode. How can I make = duplicate on line break in text mode:

MWE:

\documentclass{article}
\usepackage{amsmath}

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

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

\begin{document}
In math mode: $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 + 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$

In Text mode: 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 + 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}

• just use a macro that expands to \discretionary{=}{=}{=} – David Carlisle Apr 8 at 18:14

## 1 Answer

\documentclass{article}
\usepackage{amsmath}

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

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

\newcommand\z[1]{\ifhmode\unskip\fi\nobreak\ \discretionary{#1}{#1}{#1}\nobreak}

\begin{document}
In math mode: $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 + 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$

In Text mode: a  \z=  b \z= c \z= d \z= e \z= f \z= g \z= h \z= i \z= j \z= k \z= l \z= m \z= n \z= o \z=
p \z= q \z= r \z= s \z= t \z= u \z= v \z= w \z= x \z= y \z= z + 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}


or

\documentclass{article}
\usepackage{amsmath}

\newcommand\z[1]{\relax
\ifmmode
#1\discretionary{}{\the\textfont0 #1}{}%
\else
\ifhmode\unskip\fi\nobreak\ \discretionary{#1}{#1}{#1}\nobreak
\fi}

\begin{document}
In math mode: $a \z= b \z= c \z= d \z= e \z= f \z= g \z= h \z= i \z= j \z= k \z= l \z= m \z= n \z= o \z= p \z= q \z= r \z= s \z= t \z= u \z= v \z= w \z= x \z= y \z= z + 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$

In Text mode: a  \z=  b \z= c \z= d \z= e \z= f \z= g \z= h \z= i \z= j \z= k \z= l \z= m \z= n \z= o \z=
p \z= q \z= r \z= s \z= t \z= u \z= v \z= w \z= x \z= y \z= z + 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}

• And how can i use \z= in math mode? So I can replace = with \z= in whole document? – Denys Potapov Apr 8 at 18:33
• @DenysPotapov I added something – David Carlisle Apr 8 at 18:44
• Thanks! If there will be no answer when i do not need to replace each occurrence of = than i will mark your answer as correct. – Denys Potapov Apr 8 at 18:59
• @DenysPotapov you could make = active and define it to be as above so not need \z but active = is far more intrusive than the mathcode"8000 "math active" used in your question, it would work in a simple example above but break = in \includegraphics[width=...] or \textwidth=5cm or ... – David Carlisle Apr 8 at 19:01