1

When I wanted to compare a dimension variable with the current linewidth, I use the follow MWE code:

\documentclass{article}
\begin{document}
\ExplSyntaxOn
\dim_new:N \l_line_width_dim
\dim_set_eq:NN \l_line_width_dim \linewidth
\ExplSyntaxOff
\linewidth
\end{document}

But I found that after using \dim_set_eq, \linewidth and \textwidth failed, and the message was

Missing number,treated as zero.

and

Illegal unit of measure (pt inserted).

I don't know what's wrong with it.

3
  • 1
    \linewidth has no fixed value: it will be reset in various occasions. Maybe you want \columnwidth? Anyway, the error does not depend on any added code, in particular \dim_set_eq:NN. If you want to print the current value, you need \the\linewidth.
    – egreg
    Dec 17, 2021 at 15:16
  • 1
    Your issue is not related to \dim_set_eq, you get the same error if you remove the entire \ExplSyntaxOn...\ExplSyntaxOff block. You can't use \linewidth on it's own. What are you trying to do? Dec 17, 2021 at 15:17
  • Thanks a lot, I remembered to use \linewidth directly, maybe I didn't use it very often, so I made a mistake.
    – xdyy
    Dec 17, 2021 at 15:34

1 Answer 1

3

If you remove the code from \ExplSyntaxOn to \ExplSyntaxOff, you get the same error.

This is because \linewidth is the name of a length register; you can use it alone when TeX is expecting a length, for instance in

\setlength{\mylength}{0.5\linewidth}

or

\parbox{\linewidth}{...}

Of course also in

\dim_set_eq:NN \l_line_width_dim \linewidth

because a length register is expected.

If used out of context, the syntax rules of TeX make it into thinking that you want to assign a value to \linewidth, hence the error message that a number is missing.

If you want to print the current value of \linewidth, you need

\the\linewidth
1
  • Thanks so so much, you explained it very clearly.
    – xdyy
    Dec 17, 2021 at 15:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .