\newdimen 和 \widthof 的问题

\newdimen 和 \widthof 的问题

我在TexLive 2018下遇到以下代码的问题:

\documentclass{report}

\usepackage{calc}
\usepackage[inline]{enumitem}
\usepackage{parskip}

\newdimen\lblwidth\lblwidth=\widthof{8.88.\ }

\newlength{\testb}
\setlength{\testb}{\widthof{8.88.\ }}


\begin{document}

\chapter{Exercises}

\begin{enumerate}[labelindent=0pt,labelwidth=\widthof{8.88.\ },label=\textbf{\thechapter.\arabic*.},leftmargin=!,ref=\thechapter.\arabic*]
\item Hallo
\end{enumerate}

\end{document}

在我的系统上会\newdimen产生错误,但是\setlength不会:

日志文件的一部分:

\lblwidth=\dimen106

! Missing number, treated as zero.
<to be read again> 
                   \widthof 
l.7 \newdimen\lblwidth\lblwidth=\widthof
                                        {8.88.\ }
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Illegal unit of measure (pt inserted).
<to be read again> 
                   \widthof 
l.7 \newdimen\lblwidth\lblwidth=\widthof
                                        {8.88.\ }
Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)


! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.7 \newdimen\lblwidth\lblwidth=\widthof{8
                                          .88.\ }
You're in trouble here.  Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

\testb=\skip47
(./widthof.aux)

更改\newdimen为 并\newskip不能解决问题。

答案1

\settowidth{\lblwidth}{8.88.\ }具有正确的 LaTeX 语法,甚至不需要calc

如果你坚持使用calc,你必须使用\setlength

\setlength{\lblwidth}{\widthof{8.88.\ }}

这是为什么呢?原始赋值\lblwidth= 需要之后的法律维度=,但事实\widthof并非如此。

顺便说一句, 的意义\widthof只有\ignorespaces在合法的calc表达式中才真正有用。该calc包进行了修改\setlength,以便能够理解calc表达式。原始赋值不能以这种方式处理。

相关内容