# automatic \allowbreak around mathbin and mathrel characters

I would like linebreaks to be permitted within math formulas on both sides of any characters of the mathbin and mathrel character classes. It seems like linebreaking is by default only permitted after these characters:

\documentclass{article}

\begin{document}

text text text text text text text text text text text text $$x + x + x + x + x + x + x + x + x$$

i text text text text text text text text text text text text $$x + x + x + x + x + x + x + x + x$$

text text text text text text text text text text text text $$x + x + x + x + x \allowbreak+ x + x + x + x$$

text text text text text text text text text text text text $$x = x = x = x = x = x = x = x = x$$

text text text text text text text text text text text text $$x = x = x = x = x \allowbreak= x = x = x = x$$

\end{document}


Oddly, I have also seen situations where an \allowbreak afterwards had an effect (that was after a \cong symbol), but I cannot reconstruct an example right now.

How can I automatically allow linebreaks around mathbin and mathrel symbols? Of course I could always manually insert \allowbreak or include it in my own macros defining such operators as well as \let-redefine the existing such symbols occurring in my document, but that seems like the wrong approach.

I know what I am doing stylistically; what I typeset is not ordinary math with run-of-the-mill equations, plus I really like having an indication of formula continuation at the beginning of the next line. In any case, I think for example that in something like a = b = c⋅d a line break before the second equals sign looks perfectly fine. Basically, I would in some sense like to get rid of LaTeX's preference.

I'm looking for a way to (1) give the left-hand side of such a symbol the same status as its right-hand side or (2) to basically insert automatic \allowbreaks around such symbols. (Note that these two options are not the same.) Note that this ideally shouldn't screw up more complex math symbols built with existing or self-defined mathbin/mathrel symbols.

-
A line break in an in-line equation should happen after an operation or relation symbol, so the reader will have a clue that the equation isn't over. Indeed, TeX (reluctantly) breaks after these symbols, but not before unless manually instructed to do so. – egreg Nov 8 '12 at 7:35
@egreg Thanks for the details, but my preference is different. (Such a symbol at the beginning of the next line also tells readers that the formula is continued, assuming the reader parses the start of the next line and doesn't abruptly stop reading. This is in fact the default case of sentence processing: Even when reading ordinary sentences, the fact that many sentences stretch over multiple lines means that line-final expressions can be misparsed unless the reader continues the reading process.) -- If it's impossible to do in LaTeX, I'd rather hear that directly. – Lover of Structure Nov 9 '12 at 1:50
Btw, fwiw, I've also seen a style where (say) a plus sign is repeated, that is it is typeset both at the end of the first line and the beginning of the second line. – Lover of Structure Nov 9 '12 at 1:52
The principle is exactly the same as what's used when splitting a word: the hyphen is not at the start of the new line. If one reads "a=b+c" at the end of a line will take this as a complete equation; with "a=b+c+", it would be clear that the equation is not complete. Repeating the symbol is used in Russian typography; it's quite ambiguous and useless, IMO. – egreg Nov 9 '12 at 9:43
the russian convention was discussed briefly in a tugboat article by mikhail grinchuk, with suggested macros \brokenrel and \brokenbin to be used in situations where such breaks were needed. this was relevant to plain tex, but may contain some ideas that could be useful in the present situation. – barbara beeton Nov 20 '12 at 20:53

The flexisym package allows arbitrary commands to be inserted into math character definitions. It is usually used in conjunction with breqn for which it was written but here I use it directly. the definition of binary and relation functions are a bit opaque but just copied directly from the existing definition with the addition of \allowbreak as in your example, but applied to all characters of those classes (as long as they are defined via the standard LaTeX declarations).

\documentclass{article}

\usepackage{flexisym}

\begingroup
\catcode\_11
\catcode\:11
\gdef\math_bsym_Bin:Nn#1#2{%
\allowbreak\math_char:NNn 2#1{#2}\allowbreak}
\gdef\math_bsym_Rel:Nn#1#2{%
\allowbreak\math_char:NNn 3#1{#2}\allowbreak}
\endgroup

\begin{document}

text text text text text text text text text text text text $$x + x + x + x + x + x + x + x + x$$

i text text text text text text text text text text text text $$x + x + x + x + x + x + x + x + x$$

text text text text text text text text text text text text $$x + x + x + x + x + x + x + x + x$$

text text text text text text text text text text text text $$x = x = x = x = x = x = x = x = x$$

text text text text text text text text text text text text $$x = x = x = x = x = x = x = x = x$$

\end{document}

-
As for "standard LaTeX declarations", is it okay if I define something with \newcommand{\macroname}{\mathbin{...}}? – Lover of Structure Nov 26 '12 at 7:31
The wording was just copied from the flexisym documentation. I think if you use primitives like that it depends exactly what the ... is. The official LaTeX syntax to declare a binary operator is of course \DeclareMathSymbol{+}{\mathbin}{operators}{"2B} – David Carlisle Nov 26 '12 at 9:47
Let me further add that flexisym necessitates that a lot of superscripts and subscripts like ...^+ and ...^\somecommand{somearg} will now have to be enclosed in braces (...^{+} and ...^{\somecommand{somearg}}, respectively). – Lover of Structure Nov 26 '12 at 9:57
Of course that requirement is also explicit in the latex manual (not that anyone follows it) see tex.stackexchange.com/questions/82329/… – David Carlisle Nov 26 '12 at 10:07