0

Here is a minimal working example:

\documentclass{article}

\begin{document}

\newdimen\somelength \somelength=1pt

\begin{picture}(0,0) \put(\somelength,0){Some text} \end{picture}

\end{document}

The above code compiles successfully on Linux (on WSL 2 Ubuntu and on my laptop running Deepin Linux), but not on Windows. On Windows 10 the compiler gives an error message:

Illegal unit of measure (pt inserted). \put(\somelength,0){3}

I tried pdfLaTeX and XeLaTeX, and they both work on Linux, while giving the same error message on Windows. I tried adding

\setlength{\unitlength}{1pt}

before the picture environment, but I still got the error message. But if I change

\put(\somelength,0){Some text}

to

\put(3,0){Some text}

it works just fine. It seems that the \put command doesn't accept variables as its coordinates.

[EDIT]

As it turns out, the problem was actually caused by me using an older version of TeX (before Oct 2020), and in that version only numbers are allowed as coordinates, so something like

\put(1.2em,1.5ex){text}

would result in an error. However, in later versions it became valid (which is why I have been using it for so many times), and updating TeX would solve the problem. It has nothing to do with different operating systems.

XCG-2
  • 43
  • Please share some details about the TeX distribution you are using. I guess your distribution on Windows is older (before October 2020). – campa Jul 07 '22 at 14:04
  • I was using the April 6, 2020 version, and upgrading TeX Live to the latest version actually solved the problem. Thanks for the information! @campa – XCG-2 Jul 07 '22 at 14:16
  • While it seems indeed strange that TeX would output different results on different platforms, the error seems quite clear to me: You are trying to feed \put with a dimension that has a unit. But \put expects a value without unit at this position. If you type \put(1pt,0){Some text}, this should output the same error. – Jasper Habicht Jul 07 '22 at 14:17
  • You are right! TeX 2021 indeed seems to accept dimensions with units for \put. – Jasper Habicht Jul 07 '22 at 14:20
  • Glad that you found a solution. Please post the solution as an answer and not inside the question, so that this answer can be accepted and the question marked as answered. Thank you. – Miyase Jul 07 '22 at 15:06
  • 2
    @JasperHabicht Prior to the kernel update in October 2020, \put expected just a number. The code was changed to accept etex length expressions. (ltnews 32). – campa Jul 07 '22 at 15:33
  • @campa Thank you for clarification! – Jasper Habicht Jul 07 '22 at 15:50

1 Answers1

0

As it turns out, the problem was actually caused by me using an older version of TeX (before Oct 2020), and in that version only numbers are allowed as coordinates, so something like

\put(1.2em,1.5ex){text}

would result in an error. However, in later versions it became valid (which is why I have been using it for so many times), and updating TeX would solve the problem. It has nothing to do with different operating systems.

By the way, on older versions, one may use (a part of the code copied from How to find the ratio of a length command (e.g., \textwidth) to a reference value (e.g., 6cm) ?)

\documentclass{article}

\makeatletter \newcommand{@DivideLengths}[2]{% \strip@pt\dimexpr\number\numexpr\number\dimexpr#1\relax*65536/\number\dimexpr#2\relax\relax sp\relax } \newcommand\LengthToFloat[1]{@DivideLengths{#1}{1pt}} \makeatother

\begin{document}\noindent \setlength{\unitlength}{1pt} \begin{picture}(0,0) \put(\LengthToFloat{12.35pt},0){Some text} \end{picture} \end{document}

(Though I don't think the command name \LengthToFloat is accurate — TeX/LaTeX does not have a type system...)

XCG-2
  • 43