[texhax] detect characters in strings

Brandon Kuczenski brandon at 301south.net
Wed Jul 7 19:59:46 CEST 2010

On Wed, 7 Jul 2010, Uwe Lueck wrote:

> Brandon Kuczenski <brandon at 301south.net>, 07.07.2010 13:58:08:
>> Say I have a macro \mymacro which expands to a number, like
>> '0.00346'.  Due to circumstances beyond my control, this macro sometimes
>> contains something unsightly, like '3.46e-03', which causes later commands
>> (in fp.sty) to barf.
>> Is there a way I can detect an 'e' in a macro expansion?
> 1. see substr.sty,
>    http://ctan.org/pkg/substr,
> some enhanced documentation is
>    http://tug.ctan.org/tex-archive/macros/latex/contrib/nicetext/demo/substr.pdf

This looks really nice!

At least my urgent problem is solved-- the numbers that happen to come up 
in scientific notation are all very small and I'm now replacing them with 
zero for the time being.  But ultimately I want to convert them to fixed 
point.  I'd like to use \BeforeSubString and \BehindSubString, except I 
can't figure out how to use them:

\BeforeSubString{substring}{string} "Returns" the part of <string> that is 
before <substring>-- how does it "return" anything?  The following doesn't 

   % ... do something with mantissa and FP

it fails with the error:
! Undefined control sequence.
\su at BeforeSubString #1#2->\def \su at rest

I tried with \let too and that didn't work:


gives me
! Argument of \mantissa has an extra }.
<inserted text>

Then I have the problem of turning '-06' into '0.000001' which I was going 
to try to do with a \loop statement, but so far THAT doesn't play nice 
with fp either..

> 2. with LaTeX internals \in@, \ifin@:
>    \expandafter\in@\expandafter e\expandafter{\mymacro}
>    \ifin at ...\else...\fi
> ... these tests are not expandable

My macros have to be expanded since I'm storing the results in an array. 
At the moment, it looks like the right thing for me is to use substring.

> 3. The coolstr package
>    http://ctan.org/pkg/coolstr
> serves more general purposes regarding numbers.

Some helpful material-- I will study it.


More information about the texhax mailing list