We often find ourselves using nonzero stretch and shrink parts in \hskip and \mskip, typically 50% of the natural space value, e.g., \hskip.1em plus.05em minus.05em or \mskip1mu plus.5mu minus.5mu. How do we automate the computation of the half? In other words, we need something like
\documentclass{standalone}
\newcommand{\mSkipWithHalfStretchAndHalfShrink}[1]{\mskip#1 plus.5#1 minus.5#1}% 50 per cent of the argument after plus and minus. The argument may be any integer or floating-point number.
\showoutput
\begin{document}
\(a\mSkipWithHalfStretchAndHalfShrink{20mu}b\)% expected to expand to \(a\mskip20mu plus10mu minus10mu b\)
\end{document}
Unfortunately, this produces the stretch and shrink parts of around 0.28–0.29 regardless of the integer argument. Moreover, using a decimal point in the argument, such as in \(a\mSkipWithHalfStretchAndHalfShrink{1.5mu}b\), throws an error. We also tried stuff such as \mskip#1 plus\ratio{#1}{2} minus\ratio{#1}{2} using the calc package, however, without success.
\dimevalfrom? – Sep 18 '22 at 00:11\hspaceflexto\newcommand{\hspaceflex}[1]{\hskip plus\dimeval{#1/2} minus\dimeval{#1/2}}or rather\newcommand{\hspaceflex}[1]{\hskip plus \dimeval{#1/2} minus \dimeval{#1/2}\relax}or something else? – Jan 23 '23 at 15:36\mspaceis undefined. Do you probably mean\mskip#1 plus \muskipeval{#1/2} minus \muskipeval{#1/2}}? – Jan 23 '23 at 17:32amsmath, which should always be done for math documents – egreg Jan 23 '23 at 21:18\mskip#1 plus \muskipeval{#1/2} minus \muskipeval{#1/2}work anyway? – Jan 23 '23 at 21:20