3

I'd like to be able to define a macro, say, \def\testit{<something>} and then test to see what <something> is. If <something> is a dimension (e.g, 4in) then I can do

\resizebox{4in}{<thing to be resized>} 

otherwise (e.g,. <something>=0.75) I'll do

\scalebox{0.75}{<thing to be scaled>}
sgmoye
  • 8,586

1 Answers1

3

This is similar to what LaTeX does for \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

Output on the terminal:

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
egreg
  • 1,121,712