[texhax] detect characters in strings
Brandon Kuczenski
brandon at 301south.net
Wed Jul 7 22:10:13 CEST 2010
Philip Taylor (Webmaster, Ret'd) wrote:
> Maybe Brandon can pick something useful out of this :
>
> \documentclass {minimal}
>
> \def \head #1e#2\relax {#1}
> \def \mantissa #1{\head #1e\relax}
>
> \begin {document}
> \mantissa {0.00346}\par
> \mantissa {3.46e-03}\par
> \end {document}
That's remarkable- it will definitely assist my effort. Thanks!
Uwe Lueck wrote:
>
> Somewhere earlier I wrote that the macros from substr.sty are not expandable. This really means that they break in an \edef as well as in a \typeout, sorry. And BTW, a pair of braces seems to be missing with the first \typeout ... and what are you doing with #1 in \SciToFP? Please tell what you expect \SciToFP to do ...
>
> Cheers,
>
> Uwe.
>
>
Apologies! I do not really understand plain TeX yet (at least I finally
bought the TeXbook about a month ago). It is a peculiar language.. I
love the fact that there are macros called, e.g., \the.
Here's a bit of background. Recently, through this list, I learned
about \arrayjob[x] and, in combination with fixed point math in fp.sty
it has revolutionized my use of TeX-- I'm now migrating to PStricks for
all my data visualization. (I once used Matlab, but due to
circumstances lately I'm trapped in excel.)
I made a simple command to extract array data into a macro which is
fp-friendly (i.e. trimmed whitespace):
\usepackage{arrayjobx,fp,trimspaces}
\def\trimspace#1{\trim at spaces@in{#1}}
\def\ArraytoFP#1{\trimspace\cachedata\FPclip#1\cachedata}
Usage would be:
\checkMyArray(index1,...)\ArraytoFP\myarrayvalue
Now I'm modifying that to respond to the presence of scientific
notation:
\usepackage{substr}
\def\ArrayStoFP#1{\trimspace\cachedata%
\IfCharInString{e}{\cachedata}{\SciToFP#1\cachedata}{\FPclip#1\cachedata}}
So \SciToFP would assign to #1 a macro that expands to the fixed-point
version of \cachedata.
My task now is to extract exponent, convert it into a 1 and a decimal
point with the proper number of zeros between them, and \FPmul by the
mantissa. Philip's comments look helpful, as well as the code of
substr, coolstr, etc. I still don't understand how I may use \loop to
accomplish this, though. But that's ok- I'm on a tight deadline so I'm
going to have to wait until later to finish that puzzle.
-Brandon
More information about the texhax
mailing list