I am trying to define a command which automatically allows linebreaks inside inline equations at several punctuation characters — I am aware of \allowbreak but don’t want to manually insert it; here, I am dealing with the comma and the semicolon.
Following this thread, I wrote the following:
\documentclass{article}
\makeatletter
\mathchardef\m@thcomma\mathcode`\,
\mathchardef\m@thsemicolon\mathcode`\;
{
\catcode`,=\active
\catcode`;=\active
\gdef,{\m@thcomma\discretionary{}{}{}}
\gdef;{\m@thsemicolon\discretionary{}{}{}}
}
\makeatother
\newcommand*{\breakpunc}[1]{%
\begingroup%
\mathcode`\,=\string"8000%
\mathcode`\;=\string"8000%
#1%
\endgroup%
}
\begin{document}
%
\framebox{%
\parbox{1cm}{%
\( \breakpunc{a, b, c; d, e, f} \)%
}%
}\quad%
%
\framebox{%
\parbox{1.5cm}{%
\( \breakpunc{a, b, c; d, e, f} \)%
}%
}%
%
\end{document}
which gives the desired result:

However, when I load the babel package with French language, the TeX engine enters an infinite loop during compilation. I am not familiar with category codes but, in all likelihood, there is a conflict between frenchb and the way I make the characters , and ; active and redefine them. I noticed that everything seems to be fine if I only deal with the comma in the command \breakpunc.
I am willing to make a local redefinition of the characters , and ; so there might be a “better” and cleaner solution to achieve what I want, a solution which would not conflict with what other packages make with those characters. My question is: do you know one?

breqnpackage also provides support for breaking displayed math. – Dec 13 '12 at 18:08