[texhax] A couple of questions

Philip Taylor (Webmaster, Ret'd) P.Taylor at Rhul.Ac.Uk
Sat Dec 25 23:36:31 CET 2010



Seyed Naser Hoseini wrote:

> Dear Lady/Gentleman: I am writing a macro in tex but it is not working.
> This is what I want to do:
> 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.

For this, e-TeX is to be preferred; you will then be able to make use
of \readline, which is defined as follows :

"\readline is analogous to \read, but treats each character as if it
  were currently of \catcode 10 (space) or 12 (other); the text thus
  read is therefore suitable for being scanned and re-scanned
  (using \scantokens, q.v.) under different \catcode régimes."

> 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.

I think you want something like this (for B)

\newread \A
\openin \A = A
\loop
     \readline \A to \a
     \unless \ifeof \A
         \readline \A to \b
     \else
         \let \b = \empty
     \fi
     a: \a \endgraf
     b: \b \endgraf
     \ifx \a \b Success\endgraf \else Failure\endgraf \fi
\unless
     \ifeof \A
\repeat
\end

and here is some sample text (for A)

Now is the time for all good men to come to the aid of the party
Now is the time for all good men to come to the aid of the party
Now is the time for some good men to come to the aid of the party
Now is the time for all good men to come to the aid of the party
Now is the time for some good men to come to the aid of the party
Now is the time for some good men to come to the aid of the party

Philip Taylor


More information about the texhax mailing list