You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TeX Live 2019中picture环境下framebox长度变量及运算适配问题

解决TeX Live 2019中picture环境framebox长度变量及运算适配问题

TeX Live 2022的LaTeX内核更新了picture环境语法,允许直接在\framebox的尺寸参数中使用长度变量和加减运算,但TeX Live 2019(对应LaTeX2e <2018-12-01>)不支持该特性,必须将长度转换为相对于\unitlength的纯数值才能传入。

适配后的代码示例

\documentclass{article}

\begin{document}

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

% 计算最终宽度:将长度差转换为相对于\unitlength的数值
\def\finalWidth{\the\dimexpr(\myWidth-\myOffset)/\unitlength\relax}

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

\end{document}

直接内联运算的写法

也可以不定义额外变量,直接在\framebox参数中完成计算:

\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(\the\dimexpr(\myWidth-\myOffset)/\unitlength\relax,10){}}
\end{picture}

\end{document}

原理说明

  • 旧版LaTeX中,\framebox(w,h)的w和h要求是纯数值,表示\unitlength的倍数,不能直接传入带单位的长度变量
  • \dimexpr用于执行长度加减运算,(\myWidth-\myOffset)得到最终长度
  • 除以\unitlength将长度转换为相对于单位长度的倍数,\the命令把长度表达式的结果转换为纯数值

验证结果

上述代码在TeX Live 2019中可正常编译,生成宽度为5mm(10mm-5mm)的方框,与TeX Live 2022中目标代码的效果一致。

内容的提问来源于stack exchange,提问作者Vost

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 23:54:51