I want to define a new command that is similar to \addstackgap from stackengine package except that it has an optional argument. The command modifies the small stack gap so that the preferred amount of padding is adding above and under the argument. However, after the command ends, the amount allocated to small stack gap must go back to its normal value, which is done by using \stackgapSdefault command defined here. Here is an example:
\documentclass{IEEEtran}
\usepackage{array}
\usepackage{amsmath,amsfonts}
\usepackage{stackengine}
\newlength{\stackgapSdefaultl}
\setlength{\stackgapSdefaultl}{10mm}
\newcommand{\stackgapLdefault}{
\setstackgap{L}{\stackgapLdefaultl}
}
\newcommand{\stackgapSdefault}{
\setstackgap{S}{\stackgapSdefaultl}
}
\newcommand{\stackgapadd}[2][\stackgapSdefaultl]{
\renewcommand{\stacktype}{S} \setstackgap{S}{#1} \addstackgap{#2} \stackgapSdefault
}
\begin{document}
\begin{equation}
\left[
\stackgapadd{$e = m c^{2}$}
\right]
\end{equation}
\stackanchor{Top}{Bottom}
\end{document}
The gap in \stackanchor{Top}{Bottom} must be 10mm as specified in the default settings. If we put \stackgapSdefault after the equation environment, the gap resets to its default value, but it should have automatically reset because \stackgapSdefault is already included in \stackgapadd. How can I force stackgapSdefault it to take effect even when it is inside math mode?
