calc 包与 \g@addto@macro 中的 \setlength 不兼容?

calc 包与 \g@addto@macro 中的 \setlength 不兼容?

我想系统地在\parboxes 和minipage环境中进行一些缩进。为此,我在 LaTeX 文件的序言中添加了以下代码:

\makeatletter
\g@addto@macro\@parboxrestore{\setlength{\parindent}{1.5em}}
\makeatother

它工作正常,除了当我加载包时calc。然后我得到了

! Missing number, treated as zero.
<to be read again> 

等等。似乎\g@addto@macro不像\setlength在中重新定义的方式calc。如何解决这个问题?

这是一个最小的工作示例:

\documentclass{article}
\makeatletter
\g@addto@macro\@parboxrestore{\setlength{\parindent}{1.5em}}
\makeatother
\usepackage{calc}
\begin{document}
\begin{minipage}{\textwidth}
\end{minipage}
\end{document}

答案1

minipage你可以删除

\documentclass{article}
\makeatletter
\g@addto@macro\@parboxrestore{\setlength{\parindent}{1.5em}}
\makeatother
\usepackage{calc}


\begin{document}

a
\end{document}

问题发生在输出例程中,其中\protect设置为保护事物而不是允许它们工作,但这是\noexpand错误的保护。

最简单的做法就是避免问题

 \g@addto@macro\@parboxrestore{\parindent=1.5em\relax}

除非你真的需要 calc-syntax setlength


请注意,\@parboxrestore变化远不止 parbox 和 minipage。除了失败的输出例程(用于页眉和页脚)、脚注、图表和任何其他浮点数都将重新定义。


如果你想知道......

乳胶消息来源称

% 
%    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
%    completed.
%
%    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?
%

接下来是代码

\def\@outputpage{%
\begingroup           % the \endgroup is put in by \aftergroup
  \let \protect \noexpand
  \@resetactivechars
  \global\let\@@if@newlist\if@newlist
  \global\@newlistfalse
  \@parboxrestore
  \shipout \vbox{%
    \set@typeset@protect

如果\@parboxrestore将其向下移动 2 行,\set@typeset@protect那么一切就会正常,但这是深度嵌入的 latex 代码,这会影响每个 latex 文档中每一页的排版。某个地方的某个人可能会遇到一些不好的事情(很可能是因为他们使用了一个以意想不到的方式修补此命令的软件包……

相关内容