[texhax] remove `pt' from end of string

Robin Fairbairns Robin.Fairbairns at cl.cam.ac.uk
Wed Oct 5 13:24:31 CEST 2005


> I'm trying to write a macro that removes the `pt' unit from a string.
> While the macro \removept works on a hardcoded string, case (1)
> of attached example, it fails on a string which itself is a macro,
> although it is an \edef'ed one, case (2).
> 
> Would you please help me to adjust the macro so that it works in case
> (2) as well?
> 
> Thanks,
> Alexander
> 
> \documentclass{article}
> 
> \def\removept#1pt{%
>   #1%
> }
> 
> \def\bufa{ 1.31415pt}
> 
> \newdimen\mylength
> \mylength=1.31415pt
> \edef\bufb{ \the\mylength}
>   
> \begin{document}
>   (1) works:\expandafter\removept\bufa
>   
>   \typeout{bufb: \bufb} %indeed, it's 1.31415pt
> 
>   (2) doesn't:\expandafter\removept\bufb
> \end{document}

the latex internal macro \strip at pt will deal with case (2): the
problem is tex wittily puts "pt" there as tokens with catcode "other"
rather than "letter".  so your macro will work only when you've typed
the length, the latex macro will work only when the length comes from
\the.  fun, isn't it?



More information about the texhax mailing list