[texhax] A couple of questions
Uwe Lueck
uwe.lueck at web.de
Sat Dec 25 22:27:41 CET 2010
"Seyed Naser Hoseini" <nhoseini at mail.uk.ac.ir>, 25.12.2010 11:09:01:
> I have a tex file A.tex. In another file, B.tex,
> I want to read A.tex line by line.
> First problem is when I read the file to,
> say \a (a token variable), it does not read
> some of tex characters such as %.
> I want to read everything on the line including
> all the characters.
In my sweet humble way: my fifinddo.sty, see
http://ctan.org/pkg/nicetext
does this, i.e., by default it reads files line by line "in text mode", but you can choose portions of "TeX mode" at options.
It is not very well-developed now, I have sat hours trying to understand my documentation.
But you could just focus on the so-called "file handling commands", there is a "cheat sheet" about them. The macros can perhaps serve for learning how to do it.
Anyway, difficult for a newbie, perhaps.
> Now suppose I am reading the first line to \a
> and the second line to \b. I would like to compare
> \a and \b and get a true value if they are equal.
> I am using the following macro unsuccesfully.
>
> \newif\ifthesame
> \def\isthesame#1#2{\def\one{#1}\def\two{#2}\ifx\one\two\thesametrue\else\thesamefalse}
>
> I always get false for \isthesame{\a}{\b}, even when the two have the same values!
> I appreciate your help.
In general: as some weeks earlier: read something like the TeXbook to learn how TeX works!
>From own experience I conclude, however, that certain passages need to be read many times ..., or that one must ask Donald Arseneau ...
... or google for the free electronic version of Victor Eijkhout's TeX by Topic!
(Please report what you prefer!)
Now for the specific matter:
\ifx\a\b seems to be the test that may do what you expect.
So you could replace \def\one{#1} by \let\one#1 etc.
But your macro as it is may be good for other purposes.
What you are rather lacking may be a clear idea of what you want.
If you expect that the result should be true because \a and \b have the same expansion, you might prefer a variant of your macro where you replace \def by \edef ...
This would compare "ultimate expansions".
So you need to make up your mind if you want to compare token lists that are given as macro arguments, or compare first-level expansions, or "ultimate" expansions, ... and you could combine ...
These are not the only possibilities. Instead of expansions, you may be interested in arithmetic evaluations, or typesetting results ...
Cheers,
Uwe.
More information about the texhax
mailing list