# Defining an inline equation environment

I am wondering whether it is possible to define an inline equation environment in which equations do not break when they reach document margins. Here is a MWE in which my equation breaks (prob, you need to add/remove some o)

\documentclass{article}

\begin{document}

looooooooooooooooooooooooooooooooooooooooong text $f(x)=3x^2-2x+5+7$

\end{document}


One can claim that it is proper to use a display environment. However, sometimes, i want my equations to be in an inline-mode. Further, I know that i can achieve the desire outcome if i use \mbox{} command. More precise,

\documentclass{article}

\begin{document}

looooooooooooooooooooooooooooooooooooooooong text \mbox{$f(x)=3x^2-2x+5+7$}

\end{document}


So, my question is if it is possible to define an environment in which \mbox{} is loaded automatically instead of manually (as in the 2nd MWE). That is, $..$=\mbox{$...$}

• I do not really understand what you are looking for. I mean, you could certainly write a command, say UnbreakEq{} which internally puts its argument within an mbox. But that would then require you to wrap each inline equation in \UnbreakEq{$f(x)=3x^2-2x+5+7$} instead of \mbox{$f(x)=3x^2-2x+5+7$}, which is hardly more convenient. Are you looking for a way that automatically wraps everything written as $...$ in an mbox, without displaying this in the source-code? – Manuel Weinkauf Nov 1 '16 at 14:36
• yes exactly. I am looking for a way that automatically wraps everything written as $...$ in an mbox, without displaying this in the source-code – Yorgos Nov 1 '16 at 14:42
• I also think that the OP wants to do this if and only if the formula would be broken automatically. In other words, how to make  unbreakable. – Sigur Nov 1 '16 at 15:14

By setting \relpenalty and \binoppenalty to 10000, no inline formula can be broken across lines, unless a specific penalty item is issued: by a hard-coded rule in TeX, breaks in inline formulas can only happen after binary operation or relation symbols, with the penalty (that measures the desirability of a break) stated by those parameters' value, or at an explicit penalty.

\documentclass{article}

\relpenalty=10000
\binoppenalty=10000

\usepackage{mathtools}

\begin{document}

looooooooooooooooooooooooooooooooooooooooong text $f(x)=3x^2-2x+5+7$

\end{document}

• ...because breaks in in-line math content are only allowed around a relation or a binary operator. – Werner Nov 1 '16 at 15:18