I would really like to create a length \bar that defaults to having the same as the length \foo even if \foo gets changed, but I would also like the user to be able to set \bar to be whatever length they want. I can get close if instead of a length \bar I use a macro \baz, but the user would need to be careful with the usage. What is the best way to go about this?
\documentclass{article}
\let\bar\relax
\newlength{\foo}
\newlength{\bar}\setlength{\bar}{\foo}
\newlength{\qux}
\def\baz{\foo}
\begin{document}
\setlength{\foo}{100pt}\bigskip
foo: \the\foo\par bar: \the\bar\par baz: \the\baz\par
\setlength{\foo}{2\baz}\bigskip
foo: \the\foo\par bar: \the\bar\par baz: \the\baz\par
\def\baz{400pt}
\setlength{\qux}{2\baz}\bigskip
% Note that \baz no long works with \the
foo: \the\foo\par bar: \the\bar\par baz: \baz\par
% Note that \qux is "wrong"
qux: \the\qux\par
\end{document}






\bazis a string, not a length, use\setlength{\qux}{2\dimexpr\baz}– Steven B. Segletes Dec 29 '16 at 18:14xassoccntdoes for counters, I think – Dec 29 '16 at 18:19\def\baz{\dimexpr\foo}if you always wanted\bazto behave like a length, but change as\foochanges. This is unlike\bar, which is fixed with the\setlength, regardless of how\foosubsequently changes. – Steven B. Segletes Dec 29 '16 at 18:31\dimexpris it loses any strecthable glue. – StrongBad Dec 29 '16 at 19:22