You can remove the
The problem occurs during the output routine where
\protect is set to protect things rather than allow them to work, but it is
\noexpand which is the wrong sort of protection.
The simplest thing to do is just avoid the problem
unless you really need calc-syntax setlength here
\@parboxrestore changes a lot more than just parbox and minipage. As well as the output routine (for page head and foot) which was the case that failed, footnotes, figures tables and any other floats will pick up the redefinition.
In case you were wondering.....
the latex sources say
% The setting of |\protect| immediately before the |\shipout|
% is needed so that protected commands within |\write|s are
% handled correctly.
% Within shipout's vbox it is reset to its default value, |\relax|.
% Resetting it to its default value after the shipout has been
% completed (and the contents of the writes have been expanded)
% must be done by use of |\aftergroup|.
% This is because it must have the value |\relax|
% before macros coming from other uses of |\aftergroup| within
% this box are expanded.
% Putting this into the |\aftergroup| token list does not affect
% the definition used in expanding the |\write|s because the
% aftergroup token list is only constructed when popping the
% save-stack, it is not expanded until after the shipout is
% Question: should things from an |\aftergroup| within the shipped
% out box be executed in the environment set up for the writes, or
% after it finishes?
followed by the code
\begingroup % the \endgroup is put in by \aftergroup
\let \protect \noexpand
\@parboxrestore were moved down 2 lines after the
\set@typeset@protect then things would work but this is deeply embedded latex code and this would be affecting the typesetting of every page on every latex document. Something bad would happen to someone somewhere (most likely because they were using a package that patched this command in unexpected ways....