# Avoid inline equations starting on left the margin

I would like to avoid that ANY inline equation starts on left the margin.

The solution I have for that right now is to compile the document, check where this happened and add a ~ in front of the inline equation and then recompile. But this is quite annoying.

This

\documentclass{minimal}
\begin{document}
iada iada iada iada iada iada $2+2=4$ iada iada iada
\end{document}


would produce a break as

iada iada iada iada iada iada iada iada iada iada iada iada iada iada iada iada iada iada iada iada


But I rather a similar effect as here (only without having to include the ~ everytime!)

\documentclass{minimal}
\begin{document}
iada iada iada iada iada iada~$2+2=4$ iada iada iada
\end{document}


which would give

iada iada iada iada iada iada iada iada iada iada iada iada iada iada iada iada iada iada iada

• What is the problem with equations touching the left margin? – kiss my armpit Oct 30 '13 at 17:33
• Inline equations often break the flow of the text. Avoiding this can thus make the text easier to read. – andrecb Oct 31 '13 at 14:32

Provided that I agree with Marienplatz's comment, this is a simple attempt to achieve what you want, but you have to use a new command \inline{...} instead of $...$:

\documentclass{minimal}

\newcommand{\inline}[1]{%
\nolinebreak$#1$%
}

\begin{document}

\end{document}


Output:

## EDIT

I don't think that redefining $...$ is a good practice.

Anyway, you can do that by adding the following lines to your preamble (DISCLAIMER: I don't know if this can cause any other problem... Surely you don't have to use $$...$$ but $...$ instead):

\makeatletter
\let\inline=$\catcode\$=\active
\protected\def$#1${%
\nolinebreak\inline#1\inline%
}
\makeatother


so that the MWE

\documentclass{minimal}

\makeatletter
\let\inline=$\catcode\$=\active
\protected\def$#1${%
\nolinebreak\inline#1\inline%
}
\makeatother

\begin{document}
iada iada iada iada iada iada $2+2=4$ iada iada iada
iada iada iada iada iada $2+2=4$ iada iada iada

• Thanks for the answer. Do you think it is possible to redefine the standard $...$ to do just that? I would like to avoid changing to inline{...}in already existing documents. – andrecb Oct 31 '13 at 14:35