Giving a length as width of a framebox in picture environment

27 Views Asked by At

My problem is rather simple, but difficult to circumvent.

Actually, I am using the picture environment and I want to set the width of a framebox using a length. I have the following Minimum Working Example.

\documentclass{article}

\begin{document}

\setlength{\unitlength}{1mm}
\newlength{\myWidth}
\setlength{\myWidth}{10mm}

\begin{picture}(0,0)(0,0)
  \put(0,0){\framebox(\myWidth,10){}}
\end{picture}

\end{document}

Interestingly, this works with Tex Live 2022, but not Tex Live 2019... Here is the log I get :

This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./mwe_picture.tex
LaTeX2e <2018-12-01>
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo)) (./mwe_picture.aux)
! Missing { inserted.
<to be read again> 
                   \unitlength 
l.10   \put(0,0){\framebox(\myWidth,10){}} 

I am running on Debian10 and, for some reasons, I want this piece of code to work with Tex Live 2019.

Because I thought the problem was related to length units, I tried replacing the length by a \def with the following code:

\documentclass{article}

\begin{document}

\setlength{\unitlength}{1mm}
\def\myWidth{10}

\begin{picture}(0,0)(0,0)
  \put(0,0){\framebox(\myWidth,10){}}
\end{picture}

\end{document}

It works. However, for my application, I want to be able to add or subtract lengths (I am trying to make a template more customizable) which doesn't work with \def :

\documentclass{article}

\begin{document}

\setlength{\unitlength}{1mm}
\def\myWidth{10}
\def\myOffset{5}

\begin{picture}(0,0)(0,0)
  \put(0,0){\framebox(\myWidth-\myOffset,10){}}
\end{picture}

\end{document}

Indeed, I get the following log:

This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./mwe_picture.tex
LaTeX2e <2018-12-01>
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo)) (./mwe_picture.aux)
! Illegal unit of measure (pt inserted).
<to be read again> 
                   -
l.10 ...t(0,0){\framebox(\myWidth-\myOffset,10){}}

If I try to specify the unit (mm) in the value of the \def, I get a Missing { error like in the first log. Once again, what I am trying to do is something like this:

\documentclass{article}

\begin{document}

\setlength{\unitlength}{1mm}
\newlength{\myWidth}
\setlength{\myWidth}{10mm}
\newlength{\myOffset}
\setlength{\myOffset}{5mm}

\begin{picture}(0,0)(0,0)
  \put(0,0){\framebox(\myWidth-\myOffset,10){}}
\end{picture}

\end{document}

which works fine with Tex Live 2022 and raise a Missing { error with Tex Live 2019...

0

There are 0 best solutions below