[texhax] Fwd: Re: A couple of questions

Seyed Naser Hoseini nhoseini at mail.uk.ac.ir
Mon Jan 3 09:53:31 CET 2011


Thanks for the help. It worked. However when I read each line by \readline, 
I get a comma at the end of each line. How can I get rid of the comma. Best 
regards, S. N. Hosseini.
 


-----Original Message-----
From: "Philip Taylor (Webmaster, Ret'd)" <P.Taylor at Rhul.Ac.Uk>
To: Seyed Naser Hoseini <nhoseini at mail.uk.ac.ir>
Cc: support at tug.org
Date: Sat, 25 Dec 2010 22:36:31 +0000
Subject: Re: [texhax] A couple of questions




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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/texhax/attachments/20110103/0be384e2/attachment.html>


More information about the texhax mailing list