# Repeating certain signs after linebreak in inline math expressions

I use LaTeX to type my University Maths notes. In that, I often find myself faced with linebreaks in inline math expressions. In such a situation, I usually want to double the sign just before the break, putting one copy at line end and the other copy at the start of the following line. Unfortunately, TeX won't do that. Up till now, I had it do this manually (e.g. $d=$ $=\dim M$, $f:M\to$ $\to\mathbb{R}$ or even $x\mapsto$ \linebreak $\mapsto(x,f(x))$, because sometimes TeX breaks the line after the second copy). It is pretty boring to inspect the document for all such linebreaks, so I was wondering if there was a way of telling TeX to do this automatically. The ideal thing would be a macro \doubleatbreaks which, with the syntax \doubleatbreaks{<sign>} makes sure <sign> is doubled at linebreaks in inline math. E.g., \doubleatbreaks{=} would make =s double at breaks, \doubleatbreaks{\times} would make \times double at breaks, etc. Is there a way to do this?

Edit

As @egreg noted, rmathbr is the way. Just one thing: When I have a minus at a line break, I usually put a plus on the new line, because -+=- and --=+. rmathbr doubles the -. How can I get - (linebreak) + instead?

• There's no need to repeat the symbol after a line break. – egreg Feb 27 '16 at 11:35
• You may want to look at the rmathbr package. – egreg Feb 27 '16 at 11:47
• @egreg Just downloaded it, but it has no .sty, only a .dtx, and TeX is just not loading it, it rightly complains there is no file rmathbr.sty. How do I solve this? – MickG Feb 27 '16 at 12:18
• OK I just needed to typeset the .ins. – MickG Feb 27 '16 at 12:20
• The package is in TeX Live and, I believe, in MiKTeX – egreg Feb 28 '16 at 9:11

A few steps to get this done:

1. Go to CTAN;
2. Find the package rmathbr;
5. Open rmathbr.ins;
6. Typeset it (i.e. compile it);
7. This produces a .sty; locate it and place it in a directory TeX will find it in;

This makes a lot of symbols repeat. Opening the .sty now also opens the .pdf of the documentation. The package seems to have few known issues, and the documentation says it should be loaded after other packages.

If someone wants, like me, to break a minus with a plus (i.e. $a-$ $+b$ with a linebreak in between), because -+=- and --=+, I hacked into the code of the package and produced this:

\makeatletter
\begingroup
\catcode\-\active
\ifnum\mathcode\-<32768
\xdef-{\noexpand\xbrokenbin{\mathchar\number\mathcode`\-}}
\else
\gdef-{\xbrokenbin{\mathchar8704}}
\fi
\endgroup
\DeclareRobustCommand{\xbrokenbin}[1]{\rmathbr@xbrokenbin{#1}}
\def\rmathbr@xbrokenbin#1%
{
\relax
\def\rmathbr@arg{#1}
\def\rmathbr@this{\rmathbr@xbrokenbin}
\def\rmathbr@output{\rmathbr@@xbrokenbin}
\futurelet\rmathbr@let@token\rmathbr@brokenop%
}
\def\rmathbr@@xbrokenbin#1%
{
\ifnum\lastpenalty=\relpenalty
\mathbin{#1}
\else
\mathbin{#1}
\ifx$\rmathbr@let@token \else \rmathbr@selector{+} \fi \fi \rmathbr@setbrokens \penalty\binoppenalty % } \def\rmathbr@selector#1% { \mathchoice {\discretionary{}{\hbox{$\m@th\displaystyle#1$}}{}} {\discretionary{}{\hbox{$\m@th\textstyle#1$}}{}} {\discretionary{}{\hbox{$\m@th\scriptstyle#1$}}{}} {\discretionary{}{\hbox{$\m@th\scriptscriptstyle#1$}}{}}% } \makeatother I created a file handleminus.tex containing the above code and with that, I got the following very simple MWE: \documentclass[a4paper]{report} \usepackage{amsmath,rmathbr} \input handleminus.tex \begin{document} Foobar Foobar Baz Baz Tom Dick Harry Tizio Caio Sempronio sorrata$d=\dim M$. wojgaoperjgojefgiwejafoiwjofipjaweoifjwaeoifjowipjfowiepjf pqppp$a\times b$qoifjoqiwjfoiwqjfoiqwjfoiqwjfoiqwjfoiwqjfo qpogkpoqwkgpoqwkpowq pqi$a-b\$
\end{document}

Compiling to:

Remember, of course, to \input after loading the package, or the code above will be overwritten by the package's code and you will be back with repeated minuses.

Thanks egreg for pointing that package out.

Working a bit it is certainly possible to make a version of \xbrokenbin that takes two arguments and creates a command that prints the first argument, breaks the line and then gives the second argument, i.e. one such that \xbrokenbin{-}{+} gives what the above code produces. However, I don't need such contortions, so I will not take the time to do that. Also, I would discourage such contortions: having a \subseteq repeat like a \cdot would be very odd.

• I have some problems with iteractions of this package and some others. graphicsx, cancel, etc, but all problems were solved by putting '\usepackage{rmathbr}' to the end of preambula.And I have seen the code and now have no idea where it can interact with other packages. So, Can it affect another packages really? – Lust_For_Love Apr 23 '16 at 17:37