Re: What does xii.tex do?
- From: Jean-Côme Charpentier <Jean-Come.Charpentier@xxxxxxxxxx>
- Date: Fri, 15 Jun 2007 14:35:27 +0200
Robin Fairbairns a écrit :
Jean-Côme Charpentier <Jean-Come.Charpentier@xxxxxxxxxx> writes:
David Carlisle a écrit :
[...]It is a very good exercise (for TeX *and* french)! :-)
difficulty of understanding is relative, I was once pointed to a long
thread on fr.comp.text.tex going through that code line by line, I tried
to follow the thread but I reckon my TeX's easier to understand than
French (especially French that's discussing my TeX;-)
<http://groups.google.fr/group/fr.comp.text.tex/browse_thread/thread/b64c9a4585d05a74/bf463d14f9948c7d?lnk=st&q=carlisle+group%3Afr.comp.text.tex&rnum=10&hl=fr#bf463d14f9948c7d>
particularly the lines
C'est grandiose mais ignoble... J'espère qu'il n'y a aucun débutant qui
va regarder ce fil, sinon cela va en dégouter plus d'un ;=)
French exercise :-)
grandiose -> grandiose
ignoble -> ignoble
espérer -> hope
débutant -> newbie
regarder -> look at
fil -> here that means sequence of messages (with the same subject)
dégoûter -> disgust
Complete the translation :-)
that hope should apply to the op, perhaps...
I don't kow. Anyway, I take my courage in both hands, and I translate
the José Grimm message:
------ %< ------ %< ------ %< ------
in article <3AD16CA9.B1BFC...@xxxxxx>,
Etienne DECOSSIN <etienne.decos...@xxxxxx> writes:
Rhaaa!
Is there anybody who have a beginning of an explanation for a TeX
newbie like me?
Yet, it's as clear as spring water [not sure of this translation :-) ]
The only point to know is that, in TeX:
* there is no need to begin the document with a
\documentclass{xx}\begin{document}
* it ends with a \bye;
* \par ends a paragraph;
* \bigskip produces a vertical space;
* \catcode changes the category code;
* everything else is macro-expansion.
Note that, in vertical mode, spaces are ignored.
For instance, in \def\foo{foo} \def\bar{bar}, the space between the
definitions doesn't count. This trick is used to get constant-sized lines.
Here the text:
\let~\catcode~`76~`A13~`F1~`j00~`P2jdefA71F~`7113jdefPALLF
PA''FwPA;;FPAZZFLaLPA//71F71iPAHHFLPAzzFenPASSFthP;A$$FevP
A@@FfPARR717273F737271P;ADDFRgniPAWW71FPATTFvePA**FstRsamP
AGGFRruoPAqq71.72.F717271PAYY7172F727171PA??Fi*LmPA&&71jfi
Fjfi71PAVVFjbigskipRPWGAUU71727374 75,76Fjpar71727375Djifx
:76jelse&U76jfiPLAKK7172F71l7271PAXX71FVLnOSeL71SLRyadR@oL
RrhC?yLRurtKFeLPFovPgaTLtReRomL;PABB71 72,73:Fjif.73.jelse
B73:jfiXF71PU71 72,73:PWs;AMM71F71diPAJJFRdriPAQQFRsreLPAI
I71Fo71dPA!!FRgiePBt'el@ lTLqdrYmu.Q.,Ke;vz vzLqpip.Q.,tz;
;Lql.IrsZ.eap,qn.i. i.eLlMaesLdRcna,;!;h htLqm.MRasZ.ilk,%
s$;z zLqs'.ansZ.Ymi,/sx ;LYegseZRyal,@i;@ TLRlogdLrDsW,@;G
LcYlaDLbJsW,SWXJW ree @rzchLhzsW,;WERcesInW qt.'oL.Rtrul;e
doTsW,Wk;Rri@stW aHAHHFndZPpqar.tridgeLinZpe.LtYer.W,:jbye
To understand what happen, let parse the geinning of the first line. I
add some spaces to simplify the analysis.
\let~\catcode ~`76 ~`A13 ~`F1 ~`j00 ~`P2 jdefA71F~`7113jdefP
1) \let~\catcode
~ is \catcode.
2) ~`76
That is, \catcode`76. What follow \catcode is a character, given
either with a decimal number (e.g. 133), or a 8-base number (e.g. '177),
or 16-base number (e.g. "7f), or an ASCII code (e.g. `a). Here, we have
the character 7.
We give it the code 6. This code is usually the # one. Then we can
substitute all the 7 by #, it doesn't change anything.
3) ~`A13
The code of the letter A is 13 (then A is an active character).
4) ~`F1
The code of F is 1 (then F is like an open brace)
5) ~`j00
The code of j is 0, then j is like a backslash
The double 0 is for filling the line.
6) ~`P2
The code of P is 2 (the P is a closed brace)
7) jdefA71F~`7113jdefP
With the rules above, that is like \defA#1{\catcode `#113\def}
Then AxxY il like: \catcode `x13 \def x Y
Now What we will do, is to change all the 7 F j and P by #, {, \, }
respectively and then, when we see Axx for all letter x, we translate
from Axx to \def\x and, finally, change all the x by \x. However, we
have to note that, cause x is active, spaces which follow x aren't
discarted. On the contrary, those which follow \x are discarted. In the
other hand, if I see xy, I have to translate it to \x y, i.e. add a
space. In the case of x x, I can't simply write \x \x. Sometimes, I
wriet \space, sometimes {}. I translate from Z to + and from W to - in
order to avoid most of the problems.
All of that give the text below, as incomprehensible as before.
\def\L{
}\def\'{w}\def\;{}\def\Z{\L
a\L}\def\/#1{#1i}\def\H{\L}\def\+{en}\def\S{th}\;\def\${ev}
\def\@{f}\def\R#1#2#3{#3#2#1}\;\def\D{\R
gni}\def\-#1{}\def\T{ve}\def\*{st\R sam}
\def\G{\R ruo}\def\q#1.#2.{#1#2#1}\def\Y#1#2{#2#1#1}\def\?{i\*\L
m}\def\\fi
{\fi#1}\def\V{\bigskip\R}\-\G \def\U#1#2#3#4 #5,#6{\par#1#2#3#5\D\ifx
:#6\else\&\U#6\fi}\L\def\K#1#2{#1l#2#1}\def\X#1{\V\L nO\S e\L#1\S\L\R
yad\R\@o\L\space%
\R rhC\?y\L\R urt\K{e\L}{ov}ga\T\L t\R e\R om\L\;}\def\B#1
#2,#3:{\if.#3.\else
\B #3:\fi\X{#1}\U#1 #2,#3:}\-s\;\def\M#1{#1di}\def\J{\R dri}\def\Q{\R
sre\L}\def
\I#1{o#1d}\def\!{\R gie}\B t\'el\@ l\T\L\q dr\Y mu.\Q.,\K e\;v\+ v\+\L\q
pip.\Q.,t\+\;
\;\L\q l.\I rs\Z.eap,\q n.i. i.e\L l\M aes\L d\R cna,\;\!\;h ht\L\q
m.\M\R as\Z.ilk,%
s\$\;\+ \+\L\q s\'.ans\Z.\Y mi,\/sx \;\L\Y egse\Z\R yal,\@i\;\@ \T\L\R
logd\L r\D s\-,\@\;\G{}
\L c\Y la\D\L b\J s\-,\S\-\X\J\- ree \@r\+ch\L h\+s\-,\;\-E\R ces\I n\-
\q t.\'o\L.\R trul\;e
do\T s\-,\-k\;\R ri\@st\- a\H\def\H {nd\Z }p\q ar.tridge\L in\Z pe.\L
t\Y er.\-,:\bye
If we look carrefully, we see a sequence of \def, followed by \B and
strange stuffs. Between those \def, there is some \;, some \-\G, some
\L, some \-s\; which serves no purpose but given constant-sized lines.
What we have to do is to expand all the macros. But be carreful to the
order! For example \- ignores its argument. Then \-xy is y, but \-\S\W
is \W. If we had expanded \S before, we had have \-th\W, then h\W,
that's not the same.
It is important to not simplify the "\-": we have to leave they. In the
other hand, \; don't make anything but it's important to not expand too
early!
The simpler is to expand th \R first. This macro takes 3 arguments and
change the order. For instance \R yal is lay. Here is another example:
"t\R e\R om\L\;" gives "to\R em\L\;" then "to me" (\L is a space, \;
doesn't make anything).
For example, \X gives:
\def\X#1{\bigskip On the #1\S\L day of Christmas my true love gave to me\;}
Here, it's important to not expand the \S\L.
After some trials-errors, we see that the code above is equivalent to
\def\L{ }
\def\;{}
\def\H{\L}
\def\S{th}
\def\D{ing}
\def\-#1{}
\def\q#1.#2.{#1#2#1}
\def\\fi{\fi#1}
\def\U#1#2#3#4 #5,#6{\par#1#2#3#5\D\ifx :#6\else\&\U#6\fi}
\def\X#1{\bigskip On the #1\S\L day of Christmas my true love gave to me\;}
\def\B#1 #2,#3:{\if.#3.\else\B #3:\fi\X{#1}\U#1 #2,#3:}
\def\!{eig}
\B twelf lve \q drumm.ers .,eleven ven \q pip.ers .,ten\;
\; \q l.ords a .eap,\q n.i. i.e ladies danc,\;\!\;h ht \q m.aids a .ilk,%
sev\;en en \q sw.ans a .imm,six \; geese a lay,fi\;f ve gold rings\-,f\;our
calling birds\-,\S\-\X ird\- ree french hens\-,\;\-Esecond\- \q t.wo
..urtl\;e
doves\-,\-k\;first\- a\H\def\H {nd a }p\q ar.tridge in a pe. tree.\-,:\bye
In a définition as \def\q#1.#2.{#1#2#1}, arguments are dot-separated.
For instance "\q m.aids a .ilk" gives "maids a milk", "\q sw.ans a .imm"
gives "swans a swimm".
If we expand all the \q but one, we obtain:
\B twelf lve drummers drumm,%
eleven ven pipers pi,%
ten\; \; lords a leap,%
\q n.i. i.e ladies danc,%
\;\!\;h ht maids a milk,%
seven en swans a swimm,%
six \; geese a lay,%
fi\;f ve gold rings\-,%
f\;our calling birds\-,%
\S\-\X ird\- ree french hens\-,%
\;\-Esecond\- two turtl\;e doves\-,%
\-k\;first\- a\H\def\H {nd a }partridge in a pear tree.\-,%
:\bye
The code
\def\\fi{\fi#1}
\def\U#1#2#3#4 #5,#6{\par#1#2#3#5\D\ifx :#6\else\&\U#6\fi}
says that:
if I see some text, consisting of an A token, a B token, a C token, a
sequence of D tokens, a space, a sequence ofE tokens, a comma, and a
sequence of F token, then
execute A B C E \D.
if F=, nothing to do
else execute \&\U F
fi
The \& is a classical tricks: the macro scan all the tokens until a \fi
is reached, execute the \fi, then execute \U followed by F.
Then, if F isn't :, we excute \U followed by F.
Roughly speaking, suppose that \U see "A1 B1,A2 B2,A3 B3,A4 B4:". Then
\U typesets "\par A'1 B1 \par A'2 B2 \par A'3 B3 \par A'4 B4" where A'1
consistes of the three first character of A1.
The code
\def\X#1{\bigskip On the #1\S\L day of Christmas my true love gave to me\;}
\def\B#1 #2,#3:{\if.#3.\else\B #3:\fi\X{#1}\U#1 #2,#3:}
ca be explained like that
if \B sees A1 B1,A2 B2,A3 B3,A4 B4:
then do \X A1 \U A1 B1, A2 B2, A3 B3, A4 B4:
and after that \X A2 \U A2 B2, A3 B3, A4 B4:
and after that \X A3 \U A3 B3, A4 B4:
and after that \X A4 \Y A4 B4:
Recursion is obvious... and classical.
The first word of each line is
twelf, eleven, ten\;, \q n.i., \;\!\;h, seven, six, fi\;f, ??, \S\-\X
ird\-, \;\-Esecond\-, \-k\;first\-, respectively.
I write ??, because, proof-reading my text, I saw that I made a mistake
expanding the line
@;G<cr>LcYlaDLbJs-
I added {} in order to don't ignore the space after \G (in fact carriage
return). We have to read:
f\;\[ \; calling birds\-,%
where \[ is "our" (\G is "\R ruo" then "our")
If we expand (without the final \-), we obtain:
twelf, eleven, ten, nin, eigh, seven, six, fif, four,
third\-, second\-, first\-.
What \X does with this word is to add \S\L after, i.e. to delete the
final \-, or to add "th".
What \U does is to take the first three tokens,
twe, ele, ten, \q n., \;\!\;, sev, six, fi\;, f\;\[, \S\-\X ,\;\-E, \-k\;
and to add the word which follow. That gives:
twelve, eleven, ten\;, \q n.i.e, \;\!\;ht, seven, six\;, fi\;ve,
f\;\[\;, \S\-X ree, \;\-E two, \-k\; a
After expansion:
twelve, eleven, ten, nine, eight, seven, six, five, four, three, two, a.
As everybody understand, the use of \D and \U is to add "ing" for all
the lines which are ended with a \-.
Finally, the code: \H\def\H {nd a }
says that we have to insert \H before "partridge". At the first time, \H
is a space, then we obtain: "a partridge". Then \H is redefined and we
obtain: "and a partridge", for all the next lines.
To everybody who want to relax during five minutes, here it is...
It rather took me five hours than five minutes.
Jose'
------ %< ------ %< ------ %< ------
Maybe my english is not as good as French's David. Definitively, my
english is not as god as TeX's David :-)
Jean-Côme Charpentier
.
- Follow-Ups:
- Re: What does xii.tex do?
- From: Donald Arseneau
- Re: What does xii.tex do?
- References:
- What does xii.tex do?
- From: Andrew
- Re: What does xii.tex do?
- From: Robin Fairbairns
- Re: What does xii.tex do?
- From: David Carlisle
- Re: What does xii.tex do?
- From: Jean-Côme Charpentier
- Re: What does xii.tex do?
- From: Robin Fairbairns
- What does xii.tex do?
- Prev by Date: Re: How to remove document restriction from PDF file generated by LaTeX?
- Next by Date: Re: An easy way to instal Minion?
- Previous by thread: Re: What does xii.tex do?
- Next by thread: Re: What does xii.tex do?
- Index(es):
Relevant Pages
|