Post by Enrico GregorioPost by David RI have a slightly unrelated question about the verbatim package
typesets all the characters in the
Okay. now I am probably going to ask a stupid question, but is there any
take the contents elsewhere
\catcode`\'13 \def'{apost]
then put those back in
Sorry to waste your time if this is impossible.
I have tried hacking the verbatim package to make some catcodes active
but there are too many internals happening for this to work. Missing
number then missing control sequence or \string\end{#1} or something
similar is reported. no textual substitutions in the output occur.
Is my assumption that once something is in the token list it is
impossible to expand it any further correct?
The problem is that ' /is/ active in verbatim mode! That's done
in order to avoid combinations like '' triggering the ligature.
{\catcode`\'=\active
\gdef\doactivequoteinverbatim{\def'{<WHATEVER>}}}
\newenvironment{myverbatim}
{\verbatim\doactivequoteinverbatim}
{\endverbatim}
Do you see? The \verbatim command defines its version of the active
quote, but we reinstate the desired one afterwards.
I suspect that something will break, however. Try it.
Your statement about what's in a token list is incorrect: /category/
/codes/ of tokens already absorbed in a token list are immutable. The
meaning of control sequences can change till the last moment.
But, with e-TeX (which is used by standard distributions nowadays),
there is \scantokens ...
Ciao
Enrico
Thanks for the information.
I cannot find any mention of making \catcode`\'=\active in verbatim.sty
or even the latex source.
verbatim.sty
\def\@makeother#1{\catcode`#112\relax}
ltplain.dtx
Here is a list of the characters that have been specially catcoded:
13 \def\dospecials{\do\ \do\\\do\{\do\}\do\$\do\&%
14 \do\#\do\^\do\_\do\%\do\~}
(not counting ascii null, tab, linefeed, formfeed, return, delete) Each
symbol in
the list is preceded by , which can be defined if you want to do
something to every
item in the list.
We make @ signs act like letters, temporarily, to avoid conflict between
user
names and internal control sequences of plain format.
15 \catcode‘@=11
Some difficulty I have had was that \@sanitize seems to change the
catcode into 12, but I can't find any mention of what \do does except in
texcfg.sys
All others are \def\***@...
So \do on its own is a mystery to me.
ltdirchk.dtx
\def\***@d#1START^^M{\let\do\@makeother\dospecials\***@a}%
74 \catcode‘\%=12
75 \def\***@c{%END}
76 \***@d
ltdefns.dtx
\@sanitize The command \@sanitize changes the catcode of all special
characters except
for braces to ‘other’. It can be used for commands like \index that want
to write
their arguments verbatim. Needless to say, this command should only be
executed
within a group, or chaos will ensue.
277 \def\@sanitize{\@makeother\ \@makeother\\\@makeother\$\@makeother\&%
278 \@makeother\#\@makeother\^\@makeother\_\@makeother\%\@makeother\~}
NEVER MIND all this.
I tried what you suggested and it does work first time
Thanks
Further problems are controlling expansion and protection. I am not
very good at this.
Here is the problem
\documentclass{article}
\usepackage{verbatim}
\begin{document}
hello chuck
\makeatletter
{\catcode`\'=\active
\gdef\doactivequoteinverbatim{\let'\apostchar}}
\newenvironment{myverbatim}
{\verbatim\doactivequoteinverbatim}
{\endverbatim}
\def\apostchar{\ifx\protect\relax \expandafter\activeapost \else
\protect\apostchar\fi}
\def\activeapost{\ifx\protect\relax
\expandafter\afterassignment\expandafter\absorb\expandafter\let\expandafter\next=
\else\protect\activeapost}
\def\absorb{\ifx\protect \ifx\next=p next is a p\else next is not a p\fi
\expandafter\tryingtoprotectthree \else\protect\absorb}
\def\tryingtoprotectthree{\ifx\protect\relax \expandafter\laps \else
\protect\tryingtoprotectthree\fi}
\protected\def\laps{laps}
\begin{myverbatim}
This is original verbatim' environmemt and this apost is the answer
\end{myverbatim}
%\begin{verbatimwrite}{nancy.tex}
%Hello everybody this is a 'famous catchphrase.
%\end{verbatimwrite}
some more
\end{document}