我是 VTEX 新手。我该如何解决这个问题?
\documentclass{article}
\begin{document}
\the\hsize
\end{document}
输出:345.0 pt
但是我必须编写一个宏来计算以毫米为单位的 hsize,例如:\printdimen[mm]\hsize
如果我取 hsize 6.5in,那么以毫米为单位的输出是多少?
答案1
% arara: pdflatex
\documentclass[a4paper]{article}
\usepackage{xparse}
\usepackage{siunitx}
\usepackage{pgf}
\usepackage{mathtools}
\makeatletter
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother
\newcommand*{\getlength}[3]{%
\pgfmathsetmacro#1{#3*#2}
}
\DeclareDocumentCommand\printdimen { o m }{%
\getlength{\tmp}{\convertto{#1}{1pt}}{#2}\SI{\tmp}{#1}
}
\begin{document}
\begin{align*}
\text{\the\hsize} &\equiv \printdimen[mm]\hsize \\
&\equiv \printdimen[cm]\hsize \\
&\equiv \printdimen[ex]\hsize \\
&\equiv \printdimen[em]\hsize \\
&\equiv \printdimen[bp]\hsize \\
&\equiv \printdimen[dd]\hsize \\
&\equiv \printdimen[pc]\hsize \\
&\equiv \printdimen[in]\hsize
\end{align*}
\end{document}
答案2
像这样?
\documentclass{article}
\usepackage{printlen}
\begin{document}
\uselengthunit{mm}\printlength{\hsize}
\end{document}