COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Add each line of verbatim env. to token register

• Follow

Hi there,

some previous post showed already me having problems with the
understanding of token register handling. And again I come not any
further without help (I tried and looked a lot :-) ).

Well, I try to get the contents of an environment stored verbatim in a
token register. To do so, I use the verbatim package. On each verbatim
line a macro gets called with the contents of the current line as
parameter. Within the macro the line (=the parameter) should be
appended to a previously "created" token register. In fact, the method
starting the verbatim reading does the initilization of the token
register:
\toks@{}

The verbatim line handling macro is the following:
\def\test@verbatimhandler#1{
toks@=\expandafter{\the\toks@,#1}
\message{TEST: \expandafter{\the\toks@}}
}

Lets's say my parsed verbatim lines are:
a
b
c

Now if this get parsed as described. I would like to have {a,b,c} in
my token register afterwards, the output of \message should be:
TEST: {,a}
TEST: {,a,b}
TEST: {,a,b,c}

Unfortunately is this not the case. The output is:
TEST: {,a}
TEST: {,b,b}
TEST: {,c,c,c}

This looks rather strange to me and I can't find the error in my code
and I would be happy to get some comments on that.

Tom

 0
Reply 2voodoo (4) 3/24/2010 10:19:49 PM

Tom Kazimiers <2voodoo@gmx.de> wrote:

> Hi there,
>
> some previous post showed already me having problems with the
> understanding of token register handling. And again I come not any
> further without help (I tried and looked a lot :-) ).
>
> Well, I try to get the contents of an environment stored verbatim in a
> token register. To do so, I use the verbatim package. On each verbatim
> line a macro gets called with the contents of the current line as
> parameter. Within the macro the line (=the parameter) should be
> appended to a previously "created" token register. In fact, the method
> starting the verbatim reading does the initilization of the token
> register:
> \toks@{}
>
> The verbatim line handling macro is the following:
> \def\test@verbatimhandler#1{
>   toks@=\expandafter{\the\toks@,#1}
>   \message{TEST: \expandafter{\the\toks@}}
> }
>
> Lets's say my parsed verbatim lines are:
> a
> b
> c
>
> Now if this get parsed as described. I would like to have {a,b,c} in
> my token register afterwards, the output of \message should be:
> TEST: {,a}
> TEST: {,a,b}
> TEST: {,a,b,c}
>
> Unfortunately is this not the case. The output is:
> TEST: {,a}
> TEST: {,b,b}
> TEST: {,c,c,c}
>
> This looks rather strange to me and I can't find the error in my code
> and I would be happy to get some comments on that.

It's impossible to say without the entire code. The following,
however, does what you are trying to achieve:

documentclass[a4paper]{article}
\usepackage{verbatim}

\newtoks\myverb
\makeatletter
\def\test@verbatimhandler{%
\global\myverb=\expandafter{%
\the\expandafter\myverb\expandafter,\the\verbatim@line}}
\let\verbatim@processline\test@verbatimhandler\verbatim}

\makeatother
\begin{document}
a
b
c
\showthe\myverb
\end{document}

Ciao
Enrico

 0

On Mar 24, 3:19=A0pm, Tom Kazimiers <2voo...@gmx.de> wrote:

> The verbatim line handling macro is the following:
> \def\test@verbatimhandler#1{
> =A0 toks@=3D\expandafter{\the\toks@,#1}
> =A0 \message{TEST: \expandafter{\the\toks@}}
> Unfortunately is this not the case. The output is:
> TEST: {,a}
> TEST: {,b,b}
> TEST: {,c,c,c}

Who knows how this "\test@verbatimhandler" fits into the
verbatim handling, but obviously parameter #1 is a *macro*
that contains the contents of the line, not the contents directly.
You can use more \expandafters or whatever.

Your definition is full of other mistakes, so you should have
pasted it rather than retyping it.

 0

Enrico, thanks fer the example. I was missing a \global statement in
front of my \newtoks. Now it works

On 25 Mrz., 22:48, Donald Arseneau <a...@triumf.ca> wrote:
> On Mar 24, 3:19=A0pm, Tom Kazimiers <2voo...@gmx.de> wrote:
>
> > The verbatim line handling macro is the following:
> > \def\test@verbatimhandler#1{
> > =A0 toks@=3D\expandafter{\the\toks@,#1}
> > =A0 \message{TEST: \expandafter{\the\toks@}}
> > Unfortunately is this not the case. The output is:
> > TEST: {,a}
> > TEST: {,b,b}
> > TEST: {,c,c,c}
>
> Who knows how this "\test@verbatimhandler" fits into the
> verbatim handling, but obviously parameter #1 is a *macro*
> that contains the contents of the line, not the contents directly.
> You can use more \expandafters or whatever.
>
> Your definition is full of other mistakes, so you should have
> pasted it rather than retyping it.

Well, with the verbatim package one can set a macro that gets "called"
every verbatim line. This macro is in my case the handler, it gets the
verbatim line as expanded token list register as parameter one (a
\expandafter is right in the verbatim handler setting) .
Anyway, you are probably right with saying I should paste the code and
not retype it. At least this requires (and forces me to provide a)
minimal example :-).

Cheers,
Tom

 0

On Wed, 24 Mar 2010 15:19:49 -0700 (PDT), Tom Kazimiers
<2voodoo@gmx.de> wrote:

>Hi there,
>
>some previous post showed already me having problems with the
>understanding of token register handling. And again I come not any
>further without help (I tried and looked a lot :-) ).
>
>Well, I try to get the contents of an environment stored verbatim in a
>token register. To do so, I use the verbatim package. On each verbatim
>line a macro gets called with the contents of the current line as
>parameter.

Not in my version of the verbatim package. A marco named
\verbatim@processline is called, which takes no argument.
But a token register named \verbatim@line contains the
contents of the current line, and \verbatim@processline
can do anything it likes with it.

>Within the macro the line (=the parameter) should be
>appended to a previously "created" token register. In fact, the method
>starting the verbatim reading does the initilization of the token
>register:
>\toks@{}
>
>The verbatim line handling macro is the following:
>\def\test@verbatimhandler#1{
>  toks@=\expandafter{\the\toks@,#1}
>  \message{TEST: \expandafter{\the\toks@}}
>}

We can't do much unless you say how
\test@verbatimhandler is defined and what exactly #1 is.
Something that _doesn't_ work (which would have the output
you mention below would be
\def\verbatim@processline{%
\test@verbatimhandler{\the\verbatim@line}}
This would add the literal code \the\verbatim@line to \toks@,
producing first
{,\the\verbatim@line}
then
{,\the\verbatim@line,\the\verbatim@line}
and then
{,\the\verbatim@line,\the\verbatim@line,\the\verbatim@line}
Printing this would produce the current line only (repeated
according to the line number).

To make this work, you would need to expand \the\verbatim@line
when it is encoiuntered (before \test@verbatimhandler is
processed):
\def\verbatim@processline{%
\expandafter\test@verbatimhandler%
\expandafter{\the\verbatim@line}}

>Unfortunately is this not the case. The output is:
>TEST: {,a}
>TEST: {,b,b}
>TEST: {,c,c,c}
>

Dan
To reply by email, change LookInSig to luecking

 0