I know that the title is not clear at all; the issue is that I'm trying to use the calc
package to compute the value of a certain counter, and I receive two different error messages, according to some little changes that I do in the code. I have the impression both these issues come from something common that I'm not getting. I'll divide this thread into two points, each of them describing a different error, with the relative MWE.
1) The following code should print on the page the value 3 (because the decimal numbers disappear, according to the package documentation). Instead I receive the Missing number, treated as zero error. If I run the code despite the warning, on the paper will be printed a string composed by the characters 2! 5
.
\documentclass[11pt, a4paper]{article}
\usepackage{calc}
\newcounter{a}
\begin{document}
\setcounter{a}{\ratio{7}{2}}
\thea
\end{document}
The complete message that appears in the terminal if I run this code is the following. I'll include what goes after I tell it to ignore the error and run either way (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) If I try to multiply the result of the \ratio
command I receive an error which says Illegal unit of measure (pt inserted). The MWE, very similar, is the following:
\documentclass[11pt, a4paper]{article}
\usepackage{calc}
\newcounter{a}
\begin{document}
\setcounter{a}{2*\ratio{7}{2}}
\thea
\end{document}
Notice that in this case, despite the warning, if I run the code ignoring the alert I will actually see the expected value (7) printed on the paper. Again I'll include all the terminal's speech, including the part after (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.
How to proceed? I carefully read all the parts related to the \ratio
command on the package documentation, at least the ones I could get, and I really don't know what's wrong with this.
\ratio
requieres a dimension, not a number. See documentation.\fpeval
fromxfp
would be easier, perhaps