calc 包给出许多错误

calc 包给出许多错误

我知道标题一点都不清楚;问题是我试图使用该calc包来计算某个计数器的值,并且根据我在代码中所做的一些小更改,我收到了两个不同的错误消息。我感觉这两个问题都来自我没有得到的一些共同点。我将把这个线程分成两点,每点描述一个不同的错误,并给出相应的 MWE。

1)以下代码应在页面上打印值 3(因为根据包装文档)我收到的是缺失数字,视为零错误。如果我无视警告运行代码,纸上就会打印出由字符组成的字符串2! 5

\documentclass[11pt, a4paper]{article}

\usepackage{calc}

\newcounter{a}

\begin{document}

\setcounter{a}{\ratio{7}{2}}
\thea

\end{document}

如果我运行此代码,终端中出现的完整消息如下。我将包括在告诉它忽略错误并以任何方式运行之后的内容(r)。

alex@Sargon:~/Documenti/Progetto Perturbator/bin/mwe$ pdflatex mwe.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./mwe.tex
LaTeX2e <2017/01/01> patch level 3
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size11.clo))
(/usr/share/texlive/texmf-dist/tex/latex/tools/calc.sty) (./mwe.aux)
! Missing number, treated as zero.
<to be read again> 
                   \ratio 
l.9     \setcounter{a}{\ratio{7}{2}}

? r
OK, entering \nonstopmode...

! Package calc Error: `7' invalid at this point.

See the calc package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.9     \setcounter{a}{\ratio{7}{2}}

[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./mwe.aux) )
(\end occurred inside a group at level 1)

### semi simple group (level 1) entered at line 9 (\begingroup)
### bottom level
(see the transcript file for additional information)</usr/share/texlive/texmf-d
ist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on mwe.pdf (1 page, 10687 bytes).
Transcript written on mwe.log.

2)如果我尝试将\ratio我会收到一条错误消息,提示计量单位非法(插入 pt)。MWE 非常相似,如下所示:

\documentclass[11pt, a4paper]{article}

\usepackage{calc}

\newcounter{a}

\begin{document}

\setcounter{a}{2*\ratio{7}{2}}
\thea

\end{document}

请注意,在这种情况下,尽管有警告,但如果我忽略警告运行代码,我实际上会看到纸上打印的预期值 (7)。再次,我将包括所有终端语音,包括 (r) 之后的部分。

alex@Sargon:~/Documenti/Progetto Perturbator/bin/mwe$ pdflatex mwe.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./mwe.tex
LaTeX2e <2017/01/01> patch level 3
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size11.clo))
(/usr/share/texlive/texmf-dist/tex/latex/tools/calc.sty) (./mwe.aux)
! Illegal unit of measure (pt inserted).
<to be read again> 
                   !
l.9     \setcounter{a}{2*\ratio{7}{2}}

? r
OK, entering \nonstopmode...
! Illegal unit of measure (pt inserted).
<to be read again> 
                   !
l.9     \setcounter{a}{2*\ratio{7}{2}}

[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./mwe.aux) )
(see the transcript file for additional information)</usr/share/texlive/texmf-d
ist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on mwe.pdf (1 page, 8364 bytes).
Transcript written on mwe.log.

该怎么办?我仔细阅读了软件包文档中与该命令相关的所有部分\ratio,至少是我能读到的部分,但我真的不知道这到底是什么问题。

答案1

\ratio需要使用维度值,例如\ratio{7pt}{2pt},但即使这样也不够。为了将其与\setcounter或一起应用\setlength,必须有一个明确的乘法,与某个数字或长度相乘,请参见下面的示例。

\documentclass[11pt, a4paper]{article}

\usepackage{calc}


\newlength{\foo}
\newcounter{a}
\newlength{\foobar}
\newlength{\foobarother}
\setlength{\foobar}{7pt}
\setlength{\foobarother}{2pt}



\begin{document}

\setcounter{a}{1*\ratio{7pt}{2pt}}
\setlength{\foo}{1pt*\ratio{\foobar}{\foobarother}}


\the\foo\ or \thea

\end{document}

结果3.5pt\the\foo3\thea

相关内容