Steve Litt napsal(a):
> What I want to know is this: where does \enddescription come from? Does every
> environment named \foo also have an \endfoo that refers to the stuff that
> gets done after the last piece of text covered from the environment? If so,
> how does that happen? If not, how does Matej's code above work (I tried it 2
> years ago and indeed it did work).
>
> [snip]
>
> Does LaTeX's \newenvironment{myenvironment} automatically create not only
> \myenvironment, but also \endmyenvironment?
Let's take a look. Go to $TEXMF/tex/latex/base (it is
/usr/share/texmf/tex/latex/base on my RHEL) and open latex.ltx in
vim. Then make search for this regexp
\\def.*newenvironment
{I guess, you can understand why to do that.}
My vim stopped on line 659 on something like this
[EMAIL PROTECTED]@[EMAIL PROTECTED]@environment}
[EMAIL PROTECTED]
[EMAIL PROTECTED]@newenva#1}0}
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]@newenv{#1}{[#2]}}}
[EMAIL PROTECTED]@newenv{#1}{[#2][{#3}]}}
[EMAIL PROTECTED]@[EMAIL PROTECTED]@environment}
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]@error{Environment #1 [EMAIL PROTECTED]
}\relax
\expandafter\let\csname#1\endcsname\relax
\expandafter\let\csname end#1\endcsname\relax
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]
{\expandafter\let\csname#1\expandafter\endcsname
\csname end#1\endcsname}%
\relax
[EMAIL PROTECTED]
\csname #1\endcsname#2{#3}%
[EMAIL PROTECTED]@x\expandafter\def\csname
end#1\endcsname{#4}}
OK, this looks REALLY ugly. Of course, I except you to know that
what is done in LaTeX with \[re]newcommand could be done
(roughly, this is terrible oversimplification, but it should
suffice for our purposes) with TeX primitive \def, i.e., that
\def\macro#1{replacement using value of #1} replaces every
occurrence of \macro with parameter by the replacement.
If you look at this mess for a moment (and ignore things like
[EMAIL PROTECTED]@[EMAIL PROTECTED] -- I have no idea what does it mean, and
hopefully
it won't be important for us) you can see that it boils all down
to the macro [EMAIL PROTECTED], which ...
Hold on, this is insane. Why to do all this when we have fully
documented sources for whole LaTeX? Every writer of LaTeX
packages knows (or certainly should know), that LaTeX supports a
version of original Knuth's idea of "literate programming" (i.e.,
source code is mixed with the documentation;
http://en.wikipedia.org/wiki/Literate_programming). Whole LaTeX
source code documentation is produced by LaTeXing source2e.tex.
Unfortunately, it is quite often not included in most
distributions (some of them, like Debian, have special package
for it), so it is usually easier to download source2e.pdf
somewhere from the web (use Google). Just brief search in it lead
me to page numbered 30 (which is 40th page of my document), which
says:
\newenvironment
equivalent to:
\newcommand{\FOO}[i]{DEF1} \def{\endFOO}{DEF2}
(or the appropriate star forms).
Appropriate definitions in well-commented source code start on
page 34 (44th page of the document).
Best,
Matěj
--
http://www.ceplovi.cz/matej/blog/, Jabber: ceplma<at>jabber.cz
GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC
signature.asc
Description: OpenPGP digital signature
