Defining a Length that Scales with Fontsize Changes

"crass" it may be but that's what you should do: store it as a macro.

\baselineskip does not change automatically, the baseline for each font size is stored in macro definitions and baseline length is set within the \selectfont macro each time the font changes.


Recommending, in your package documentation, a syntax such as \Sstackgap=0.7ex is disputable; the standard LaTeX syntax uses \setlength and since \Sstackgap is a skip register (since you define it with \newlength), this opens the way to weird errors; a user typing

\Sstackgap=0.3ex Plus other things

will be puzzled with a strange error message Missing number treated as 0. Do you see why?

If you want this length to be expressed in the font based units em or ex, respecting the current font, you must treat it as a macro:

\newcommand{\setstackgap}[2]{%
  \@namedef{#1stackgap}{#2}%
}

where #1 is either L or S (add an error checking routine). Then you can say

\newcommand\stackgap{%
  \@nameuse{\if S\stacktype S\else L\fi stackgap}\relax
}

and the user can say

\setstackgap{S}{.7ex}
\setstackgap{L}{.3em}

or whatever. Alternatively, define a \stackengineset macro:

\newcommand{\stackengineset}[2]{\def#1{#2}}

so users can type

\stackengineset{\Sstackgap}{0.7ex}

Note that in both ways a fixed length can be specified as well.


You could use a syntax such as \Sstackgap=0.7ex, by doing

\def\Sstackgap{\afterassignment\@foo\skip@}
\def\@foo{\edef\@Sstackgap{\the\skip@}}

and modifying \stackgap to use \@Sstackgap instead of \the\Sstackgap; similarly for \Lstackgap. But I can't recommend this way of doing things, contrary to the standard LaTeX syntax.