# Automatically breaking a line before an in-line mathematical expression

How do I automatically break the line before mathematical expression without using \\

Minimal example:

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}

\begin{document}

text text text text text text text text text text text text text $f:A \to B; f(x) = x^2 + x + 1$ text text text text text text text text text $p(x) = \{ a_0 + a_1 x + a_2 x^2 + a_3 x^3 + \ldots + a_n x^n \}$ text text text text text text text text
text text

\end{document}


Result:

But, I need:

Remember: I need automatically, without \\.

put it into braces and use sloppypar.

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}

\begin{document}
\begin{sloppypar}
text text text text text text text text text text text text
text ${f:A \to B; f(x) = x^2 + x + 1}$ text text text text
text text text text text
${p(x) = \{ a_0 + a_1 x + a_2 x^2 + a_3 x^3 + \ldots + a_n x^n \}}$ text
text text text text text text text text text
\end{sloppypar}

\end{document}


If you want it document wide, than write into the preamble relpenalty=9999 binoppenalty=9999. Then you do not need the braces. However, than it will never be broken, which is not a good idea.