我希望能够定义一个宏,然后\def\testit{<something>}
测试一下它<something>
是什么。如果<something>
是维度(例如4in
),那么我可以这样做
\resizebox{4in}{<thing to be resized>}
否则(例如<something>=0.75
)我会这样做
\scalebox{0.75}{<thing to be scaled>}
答案1
这与 LaTeX 的操作类似\fontsize
:
\documentclass{article}
\makeatletter
\newcommand{\dimenorfactor}[3]{%
\afterassignment\dim@or@factor\skip@=#1pt@{#2}{#3}%
}
\def\dim@or@factor#1@#2#3{%
\if\relax\detokenize{#1}\relax#3\else#2\fi
}
\makeatother
\begin{document}
\newlength{\testdim}\setlength{\testdim}{4pt}
\newcommand\test[1]{%
\dimenorfactor{#1}{\typeout{#1 is a dimen}}{\typeout{#1 is not a dimen}}%
}
\test{123 }
\test{1.23}
\test{123.22 mm}
\test{-.2 pt }
\stop
终端上输出:
123 is not a dimen
1.23 is not a dimen
123.22 mm is a dimen
-.2 pt is a dimen
\testdim is a dimen