1

This MWE fails when I return a length and some string (I noticed it when I tried to debug some TikZ macros I wrote).

\documentclass{scrartcl}
\usepackage{etoolbox}

\newlength{\mylength}
\setlength{\mylength}{20mm}
\newcommand\getlength[1]{
  \ifnumcomp{#1}{=}{1}{\mylength}{}
  \ifnumcomp{#1}{=}{2}{\mylength + 10mm}{}
  \ifnumcomp{#1}{=}{3}{\mylength}{}
}
\begin{document}
\getlength{1}
\getlength{2} % As soon as this line exists, ...
\getlength{3} % ...this line returns: "Missing number, treated as zero."
\end{document}

Why is that so and how can I make it work?

  • I will accept an answer that also explains, where the problem comes from. – quazgar Oct 18 '18 at 13:06
  • 2
    \mylength expects a following number to assign the register. it doesn't output the current value. The first two commands do basically \mylength=\mylength and then print the + 10mm. And the last \mylength is missing its number. – Ulrike Fischer Oct 18 '18 at 13:12
  • So \mylength5cm would be equivalent to \setlength{\mylength}{5cm}? If you want the credit, I would take your comment as an answer. – quazgar Oct 18 '18 at 13:35
3

\mylength expects a following number to assign the register. It doesn't output the current value.

So the first two commands do basically \mylength=\mylength and then print the + 10mm. And the last \mylength is missing its number.

0

I found out that I can prevent the error by returning \the\mylength instead, but I don't know yet why the problem arises.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.