# Forcing inline math mode expressions onto one line

I am encountering something whilst using inline math mode, for which I would like to find a means of avoiding. I notice that if the inline math mode is too close to the right-most edge of the line upon which it would appear compiled, it spreads onto the next line. Here is a selection of code for a MWE to show what I mean:

\documentclass[12pt]{report}
\usepackage{amsmath, amsthm}

\DeclareMathOperator{\lin}{lin}

\begin{document}
\begin{proof}
Our aim is to show that any sequence of functions in $\lin\{\psi(\cdot)x;x\in H,\psi\in D\}$ can be approximated by some function in $S(\mu;H)$ under $\|\cdot\|_{L_2(\mu;H)}$. If true, we would then have
\end{proof}
\end{document}


This code produces:

On the first and second lines, $\lin\{\psi(\cdot)x;x\in H,\psi\in D\}$ and $\|\cdot\|_{L_2(\mu;H)}$ are spread onto the subsequent line. Whilst not shown in this MWE, I notice too that sometimes this can have the impact of inline math expressions running over margin boundaries.

Is there a way to force TeX to put these math-mode expressions onto the next line, so as to avoid them spreading across two lines, whilst also increasing the white spacing between words in the previous line, so as to fill up the space in the line which would otherwise been filled by the shifted portion of the math-mode expression (and avoid the awkward white space you would get if you were to use \newline)? Is there a solution I can apply document-wide rather than just by paragraph?

• You can use \linebreak instead of \newline. But I'd restrict inline math as much as possible. For example, I would put the whole \lin\{...\} in display math. Much more readable, IMO. – campa Dec 7 '20 at 13:19
• you can forbit breaking inline equations with ˙\mbox{$...$}, however, result will be ugly. Better is show these expression as display math. – Zarko Dec 7 '20 at 13:22
• Unrelated don't use \|...\| for the norm, use \lVert ... \rVert this gives the proper left categories on the symbols. Why is that important, try them on -a. – daleif Dec 7 '20 at 13:22
• I'd probably try ...\{\phi(\cdot)x; \allowbreak x... to see if that introduces a better break (hmm, it does not). In the end often the best solution is to rephrase the text – daleif Dec 7 '20 at 13:23

The line break in the middle of your construction \|\cdot\| comes because TeX does not know that the first \| is an "opening"-type symbol, and the second one a "closing"-type. You should tell TeX by using \lVert...\rVert, or better by defining a macro \norm{...} which takes care of that. This won't solve all problems, since inline math always complicate line breaking. You could try inserting \linebreaks manually, or \allowbreak, but in the end the human eye has the last word, and in many occasions a rewording is the best thing to do. Also I would avoid long inline math expressions.

\documentclass[12pt,draft]{report}

\usepackage{amsthm}

\DeclareMathOperator{\lin}{lin}
\DeclarePairedDelimiter{\norm}{\Vert}{\Vert}
\newcommand*{\blank}{{\:\cdot\:}}

\setlength{\parindent}{0pt}

\begin{document}

\begin{proof}
Our aim is to show that any sequence of functions in $\lin\{\psi(\cdot)x;x\in H,\psi\in D\}$
can be approximated by some function in $S(\mu;H)$ under $\|\cdot\|_{L_2(\mu;H)}$.
If true, we would then have\ldots
\end{proof}

\textbf{What you seem to be looking for:}
\begin{proof}
Our aim is to show that any sequence of functions in $\lin\{\psi(\cdot)x;x\in H,\psi\in D\}$
can be approximated by some function in $S(\mu;H)$ under\linebreak$\|\cdot\|_{L_2(\mu;H)}$.
If true, we would then have\ldots
\end{proof}

\textbf{Better tell \LaTeX\ what $\|$ is}
\begin{proof}
Our aim is to show that any sequence of functions in $\lin\{\psi(\cdot)x;x\in H,\psi\in D\}$
can be approximated by some function in $S(\mu;H)$ under $\lVert\blank\rVert_{L_2(\mu;H)}$.
If true, we would then have\ldots
\end{proof}

\textbf{Even better, let \texttt{mathtools} do it}
\begin{proof}
Our aim is to show that any sequence of functions in $\lin\{\psi(\cdot)x;x\in H,\psi\in D\}$
can be approximated by some function in $S(\mu;H)$ under $\norm{\blank}_{L_2(\mu;H)}$.
If true, we would then have\ldots
\end{proof}

$\lin\{\psi(\cdot)x; x\in H, \psi\in D\}$
can be approximated by some function in $S(\mu;H)$ under $\norm{\blank}_{L_2(\mu;H)}$.
`