# A version of \smash that interpolates between the true height/depth and the text-height/depth of the current line

I have a paragraph of text that includes a "deep" math symbol, one that dips below the ordinary bottom of the text a little. Originally I had nothing below that symbol; it was near the end of the paragraph on the penultimate line, and the line underneath did not extend to the horizontal position of the offending symbol. The spacing between the final two lines of the paragraph was too great, so I used \smash to reset it to "normal".

Later, I added some more text at the end of the paragraph. Now \smash makes the spacing too little. But without \smash the spacing still feels too great to me. Wouldn't it be nice if there were a \halfsmash version of \smash that would adjust the "height" (respectively the "depth") of the symbol to exactly halfway between its true height (depth) and the current height (depth) of ordinary running text on the same line?

Like \smash, this would work whether used in or out of math mode. It might not work well in displayed math mode, but this would not be part of the design goals. It might not work for content that breaks across lines.

Bonus points for:

• Accepting an optional argument that specifies as a proportion the difference that is desired between the true height/depth and line-height/-depth (defaulting to one-half). (Thus \halfsmash[0.25]{content} would give {content} a height one-quarter of the way between its true height and the current line-height of the text, and a depth one-quarter of the way between its true depth and the current line-depth of the text. \halfsmash[1]{...} would be just like \smash{...}, and \halfsmash[0] would have no effect.)
• Being compatible with the amsmath extension to \smash that gives the optional arguments [t] and [b].
• I have no idea whether \smash works properly in subscript/superscript contexts. If it does, consider this desirable too.

I started looking at doing this but quickly realised that

• it required dealing with both the height and the depth of the symbol
• it calls for testing whether TeX is in math mode at the time the macro is called (I found out that there is a macro \ifmmode that can be used for this, though)
• it requires you to find out what the "default" height and depth are of text on the current line (I am not sure how you do this)
• a working approach will involve using a math extension, maybe PGF, to interpolate between two different heights/depths, then perhaps using \raisebox to achieve a box with the correct height/depth.

# Edit:

Here is my attempt. Unfortunately I have fallen at the first hurdle - it doesn't even compile (\equal doesn't seem to be available to me in this circumstance, for some reason).

\documentclass[a4paper]{amsart}

\usepackage{ifthen, pgf, xparse}

\newlength{\lenA}
\newlength{\lenB}
\newlength{\lenC}
\newlength{\lenD}

\DeclareDocumentCommand{\halfsmash}{oom}{%
\begingroup
% Wrap the {content} in $...$, if in math mode.
\edef\c{\ifmmode$#3$\else#3\fi}%
% Determine the proportion, \x.
\edef\x{%
\IfNoValueTF {#1}%
{0.5}%
{\ifthenelse {\equal{#1}{t}}%
{\IfNoValueTF{#2}{0.5}{#2}}%
{\ifthenelse {\equal{#1}{b}}%
{\IfNoValueTF{#2}{0.5}{#2}}%
{#1}}}%
}%
% Determine whether to modify height, depth, or both; obtain a proportion (0 or 1) by
% which the height is to be changed (not using \x at this stage).
\edef\h{\IfNoValueTF{#1}{1}{\ifthenelse{\equal{#1}{b}}{0}{1}}}%
\edef\d{\IfNoValueTF{#1}{1}{\ifthenelse{\equal{#1}{t}}{1}{0}}}%
\settoheight{\lenA}{G}% The "ordinary" height of the current line.
\settodepth{\lenB}{g}% The "ordinary" depth of the current line.
\settoheight{\lenC}{\c}% The true height of the {content}.
\settodepth{\lenD}{\c}% The true depth of the {content}.
\pgfmathsetlength{\lenA}{\lenC - (\x * \h * (\lenC - \lenA))}%
\pgfmathsetlength{\lenB}{\lenD - (\x * \d * (\lenD - \lenB))}%
% Typeset the {content}.
\raisebox{0pt}[\lenA][\lenB]{\c}%
\endgroup%
}

\newcommand{\tallmathsymbol}{\Sigma^{x^{y^z}}_{a_{b_c}}}

\newcommand{\sometext}{%
Here is some text.
Its only purpose is to be repeated several times, so as to form a paragraph.
}

\begin{document}

\sometext\sometext\sometext\sometext\sometext$\tallmathsymbol$
\sometext\sometext\sometext\sometext\sometext

\sometext\sometext\sometext\sometext\sometext\halfsmash{$\tallmathsymbol$}
\sometext\sometext\sometext\sometext\sometext

\sometext\sometext\sometext\sometext\sometext$\halfsmash[0.25]{\tallmathsymbol}$
\sometext\sometext\sometext\sometext\sometext

\sometext\sometext\sometext\sometext\sometext$\halfsmash[b]{\tallmathsymbol}$
\sometext\sometext\sometext\sometext\sometext

\sometext\sometext\sometext\sometext\sometext\halfsmash[t][0.25]{$\tallmathsymbol$}
\sometext\sometext\sometext\sometext\sometext

\end{document}


Here is a modification of the amsmath \smash command that allows a "partial" smashing, with the fraction supplied as an argument:

\documentclass{amsart}
\makeatletter
\newcommand{\partsmash}[2][tb]{%
\def\mb@t{\ht\z@ #2\ht\z@}\def\mb@b{\dp\z@ #2\dp\z@}%
\def\mb@tb{\mb@t \mb@b}%
\edef\finsm@sh{\csname mb@#1\endcsname\box\z@}%
\ifmmode \@xp\mathpalette\@xp\mathsm@sh
\else \@xp\makesm@sh
\fi}
\makeatother
\begin{document}
\fboxsep=0pt
\fbox{$\intop$} \fbox{$\smash\intop$}
\fbox{$\smash[t]\intop$} \fbox{$\smash[b]\intop$}

\fbox{$\intop$} \fbox{$\partsmash{.4}\intop$}
\fbox{$\partsmash[t]{.4}\intop$} \fbox{$\partsmash[b]{.4}\intop$}

\end{document}


Here, I smash the actual displayed item, and then put a \vphantom of reduced scale (default 0.5 size, but can specify with optional argument)

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}
\newcommand\halfsmash[2][.5]{\smash{#2}\vphantom{\scalebox{#1}{#2}}}
\begin{document}
\lipsum*[4]%
{\Huge Ay}
\lipsum*[4]
{\Huge\halfsmash{Ay}}
\lipsum*[4]
{\Huge\halfsmash[.8]{Ay}}
\lipsum*[4]
{$\displaystyle\int_0^\infty y dx$}
\lipsum*[4]
{\halfsmash[.8]{$\displaystyle\int_0^\infty y dx$}}
\lipsum*[4]
\end{document}


Here is a working version of the attempt I made in my edit to the question.

I feel sure that someone will come up with a better version than mine.

I'm not sure how I feel about 0 corresponding to "no effect" and 1 corresponding to "like \smash". I'm not sure whether it should be the other way around (of course, it's a simple matter of changing the arithmetic). I can't decide which is more intuitive.

\documentclass[a4paper]{amsart}

\usepackage{ifthen, pgf, xparse}

\newlength{\lenA}
\newlength{\lenB}
\newlength{\lenC}
\newlength{\lenD}

\DeclareDocumentCommand{\halfsmash}{oom}{%
\begingroup
% Wrap the {content} in $...$, if in math mode.
\ifmmode\def\c{$#3$}\else\def\c{#3}\fi%
% Using the optional arguments, if present, determine whether to modify height, depth,
% or both, and by how much.
\IfNoValueTF {#1}%
{\def\h{0.5}\def\d{0.5}}%
{\IfNoValueTF {#2}%
{\ifthenelse {\equal{#1}{t}}%
{\def\h{0.5}\def\d{0}}%
{\ifthenelse {\equal{#1}{b}}%
{\def\h{0}\def\d{0.5}}%
{\def\h{#1}\def\d{#1}}}}%
{\ifthenelse {\equal{#1}{t}}%
{\def\h{#2}\def\d{0}}%
{\def\h{0}\def\d{#2}}}}%
\settoheight{\lenA}{G}% The "ordinary" height of the current line.
\settodepth{\lenB}{g}% The "ordinary" depth of the current line.
\settoheight{\lenC}{\c}% The true height of the {content}.
\settodepth{\lenD}{\c}% The true depth of the {content}.
\pgfmathsetlength{\lenA}{\lenC - (\h * (\lenC - \lenA))}%
\pgfmathsetlength{\lenB}{\lenD - (\d * (\lenD - \lenB))}%
% Typeset the {content}.
\raisebox{0pt}[\lenA][\lenB]{\c}%
\endgroup%
}

\newcommand{\tallmathsymbol}{\Sigma^{P^{Q^{R^{S^T}}}}_{A_{B_{C_{D_E}}}}}

\newcommand{\sometext}{%
Here is some text.
Its only purpose is to be repeated several times, so as to form a paragraph.
}

\edef\sometext{\sometext\sometext}

\begin{document}

\sometext$\tallmathsymbol$\sometext

\sometext\smash{$\tallmathsymbol$}\sometext

\sometext\halfsmash{$\tallmathsymbol$}\sometext

\sometext$\halfsmash[0.25]{\tallmathsymbol}$\sometext

\sometext$\halfsmash[b]{\tallmathsymbol}$\sometext

\sometext\halfsmash[t][0.25]{$\tallmathsymbol$}\sometext

\end{document}