Automatically prevent extra line spacing because of math

The boxes and glue system seems to be both the strength and weakness of TeX. One of the major problems I often have to deal with is uneven distances between lines as in the example below.

Inserting some \smash commands around the math proves that this extra line spacing is not at all necessary; there is plenty of room for the math on lines of standard height:

Currently, inserting \smash commands manually is the only acceptable solution I have found to this problem, as I doubt messing with the interline glue is a good idea (or what?). I wonder if there is an automatic way to accomplish this? Can I prevent TeX from adjusting the line height based on the size of inline math?

You might think:

But what if you want to place large structures, like matrices, in inline math? Certainly you do not want them to collide with the adjacent lines?

But the fact is that I never place matrices or similar large constructions in inline math. In my opinion, such things belong entirely in displayed math.

\documentclass{article}

\usepackage{mathtools}

\usepackage{lipsum}

\begin{document}

Consider the map~$\Ad_{g_0^2}$.
La la la la la la la la la la la la la la la la la.
And the algebra~$\widetilde{A}$.
\lipsum[1]

Consider the map~\smash{$\Ad_{g_0^2}$}.
La la la la la la la la la la la la la la la la la.
And the algebra~\smash{$\widetilde{A}$}.
\lipsum[1]

\end{document}

• For small problems with \tilde{A}, you can use in the preamble something like \setstretch{1.06} from setspace. Personally, I consider the interline spacing in LaTeX is very tight. – Bernard Jul 16 '16 at 13:21
• consider your example. you lucked out. it could have happened that the accented A came right under the expression with the subscript. then you be out of luck -- or you could rewrite. (la)tex does not know where on adjacent lines the potential conflicts appear; it's undoubtedly possible -- with an extensive redesign of the tex internals -- to record and use this information, but given the restrictions under which tex was created, it's quite amazing that it works as well as it does. nobody has yet improved the math handling, to the best of my knowledge. – barbara beeton Jul 16 '16 at 14:29
• I am well aware that such collisions might happen. But they will happen independently of whether \smashing is done automatically or manually. In both cases, the solution for me is to rewrite the text. To be clear, I do not, under any circumstances, want uneven line spacing. I prefer TeX to let the lines collide instead and then leave it to me to rewrite what I find necessary. – Gaussler Jul 16 '16 at 14:36
• if you use $$..$$ for inline math then you just need \def$$#1$${\smash{$#1$} – David Carlisle Jul 16 '16 at 14:54
• @DavidCarlisle Will there be unwanted side effects of doing this globally? – Gaussler Jul 16 '16 at 14:59

Here's a luatex version that could be made more robust but after the linebreaking it uses a callback to set the height and depth of boxes and (s) replace any baselineskip or lineskip glue by a fixed value. (Probably it should preserve the height of the first box and the depth of the last, left as an exercise..

\documentclass{article}

\usepackage{mathtools}

\directlua{
function fixlines(h,c)
local pd=0
print('code: ' .. type(c) .. ':' .. c)
for n in node.traverse(h) do
%
% smash boxes
if n.id==0 then
n.depth=0
n.height=0
end
%
% lineskip or baselineskip set to 12pt
if n.id==12 and (n.subtype==1 or n.subtype==2) then
n.width=786432 % 12pt in sp
end
end
return h
end
}
\usepackage{lipsum}

\begin{document}

Consider the map~$\Ad_{g_0^2}$.
La la la la la la la la la la la la la la la la la.
And the algebra~$\widetilde{A}$.
\lipsum[1]

Consider the map~\smash{$\Ad_{g_0^2}$}.
La la la la la la la la la la la la la la la la la.
And the algebra~\smash{$\widetilde{A}$}.
\lipsum[1]

\end{document}