I'm curious as to whether there is a way to pass a small amount of LaTeX code to a compiler at the command line and return the string corresponding to the value of a variable or length.
For instance I would like to pass this code
\usepackage{calc}
\def\contnt{\tt{I wish I knew how much space was occupied by this string when typeset...}
\settowidth{\contntwdth}{\contnt}
and I'd like to indicate that the string output I'm after is the width of the content e.g.
\the\contntwdth
Any suggestions are greatly appreciated.


.logor a dedicated text file. The latter avoids needing to parse the log: does that sound about right? – Joseph Wright♦ Dec 29 '12 at 14:49texdefwritten by me does something very similar, i.e. returning the definition of macros and also values, but your example might be already be to complicated. (Also, your use of\ttis incorrect and\ttis outdated altogether, use{\ttfamily ..}or\texttt{..}instead.) – Martin Scharrer♦ Dec 29 '12 at 14:51printlenpackage can be used to convert to display the length in different units. – Peter Grill Dec 29 '12 at 14:52