From: isozaki@ntt-20.ntt.jp (Hideki ISOZAKI)
Subject: Re: macro expanding filter
Organization: NTT Basic Research Laboratories
Distribution: fj
Date: 2 Oct 1992 09:15:18 GMT


>LaTeX $@$N%=!<%9$rDL$9$H!$(J(re)newcommand $@$K$h$k%f(J$@!<%6Dj5A$N%^%/%m$@$1(J
>$@E83+$7$F$/$l$k$h$&$J%U%#%k%?$O$J$$$G$7$g$&$+(J?

$@$$$o$f$k%U%#%k%?$G$O$"$j$^$;$s$,(J$@!$(J
$@$3$s$J$H$3$m$G$I$&$G$7$g$&!%(J

				$@0k:j=(<y(J  $@#N#T#T4pAC8&(J

% delatex.tex
% An example of ``delatex by tex''
%          by Hideki Isozaki @ NTT  1992.
% Please run 'tex' instead of 'latex' for this file.
%
% Input (in LaTeX) is given at the end of this file 
%   as the argument of \immediate\write1{...}.
% Braces { } in this argument should be balanced.
%
% Output will be written on delatex.dtx.
\immediate\openout1=delatex.dtx
% We don't need a .dvi file.
\output{}\nullfont

%  The following commands will be expanded in this example.
%
%  \newcommand{\LL}[2]{#1 Leslie Lamport #2}
%  \newcommand{\DEK}{\fbox{Donald E.~Knuth}}
%
%  Please move your commands to be expanded between *** and @@@.

% If you choose \empty, LaTeX commands will disappear.
% If you choose \relax, LaTeX commands will appear.

%\let\appearance\empty
\let\appearance\relax

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  \(re)newcommand from latex.tex by Leslie Lamport
\catcode`\@=11

\newcount\@tempcnta \newcount\@tempcntb 

\def\newcommand#1{\@ifnextchar [{\@argdef#1}{\@argdef#1[0]}}

\def\renewcommand#1{\edef\@tempa{\expandafter\@cdr\string 
  #1\@nil}\@ifundefined{\@tempa}{\message{\string#1\space undefined}%
    }{}\@ifnextchar [{\@reargdef#1}{\@reargdef#1[0]}}

\long\def\@argdef#1[#2]#3{\@ifdefinable #1{\@reargdef#1[#2]{#3}}}

\catcode`\?=11\relax
\long\def\@reargdef#1[#2]#3{\@tempcnta#2\relax\let#1\relax
\edef\@tempa{\long\def#1}\@tempcntb \@ne
\let\@?@?\relax\@whilenum\@tempcnta>\z@
\do{\edef\@tempa{\@tempa\@?@?\the\@tempcntb}\advance\@tempcntb \@ne \advance
\@tempcnta \m@ne}\let\@?@?##\@tempa{#3}}
\catcode`\?=12\relax

\def\@whilenoop#1{}
\def\@whilenum#1\do #2{\ifnum #1\relax #2\relax\@iwhilenum{#1\relax 
     #2\relax}\fi}
\def\@iwhilenum#1{\ifnum #1\let\@nextwhile=\@iwhilenum 
         \else\let\@nextwhile=\@whilenoop\fi\@nextwhile{#1}}

\long\def\@ifdefinable #1#2{\edef\@tempa{\expandafter\@cdr\string #1\@nil}%
\@ifundefined{\@tempa}{\edef\@tempb{\expandafter\@carcube \@tempa xxxx\@nil}%
\ifx \@tempb\@qend \@notdefinable\else  
\ifx \@tempa\@qrelax \@notdefinable\else  #2\fi\fi}{\@notdefinable}}

\long\def\@ifundefined#1#2#3{\expandafter\ifx\csname 
  #1\endcsname\relax#2\else#3\fi}

\def\@car#1#2\@nil{#1}
\def\@cdr#1#2\@nil{#2}

\def\@carcube#1#2#3#4\@nil{#1#2#3}

\edef\@qend{\expandafter\@cdr\string\end\@nil}
\edef\@qrelax{\expandafter\@cdr\string\relax\@nil}

\def\@notdefinable{Command name '\@tempa' already used}

\def\@ifnextchar#1#2#3{\let\@tempe #1\def\@tempa{#2}\def\@tempb{#3}\futurelet
    \@tempc\@ifnch}
\def\@ifnch{\ifx \@tempc \@sptoken \let\@tempd\@xifnch
      \else \ifx \@tempc \@tempe\let\@tempd\@tempa\else\let\@tempd\@tempb\fi
      \fi \@tempd}
\def\@ifnch{\ifx \@tempc \@sptoken \let\@tempd\@xifnch
      \else \ifx \@tempc \@tempe\let\@tempd\@tempa\else\let\@tempd\@tempb\fi
      \fi \@tempd}
\def\:{\let\@sptoken= } \:  % this makes \@sptoken a space token 

\def\:{\@xifnch} \expandafter\def\: {\futurelet\@tempc\@ifnch}

\catcode`\@=11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% To stop this file
\let\stopthisfile\end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  LaTeX commands 
%  (not an exhaustive list)

\let\ \appearance
\let\+\appearance
\let\,\appearance
\let\/\appearance
\let\;\appearance
\let\<\appearance
\let\=\appearance
\let\>\appearance
\let\[\appearance
\let\]\appearance
\let\(\appearance
\let\)\appearance
\let\{\appearance
\let\}\appearance
\let\$\appearance
\let\&\appearance
\let\#\appearance
\let\%\appearance
\let\@\appearance
\let\\\appearance
\let\^\appearance
\let\_\appearance

\let\LaTeX\appearance
\let\Large\appearance
\let\TeX\appearance
\let\ast\appearance
\let\author\appearance
\let\baselineskip\appearance
\let\baselinestretch\appearance
\let\begin\appearance
\let\bf\appearance
\let\bibitem\appearance
\let\bullet\appearance
\let\cdot\appearance
\let\chapter\appearance
\let\date\appearance
\let\ddots\appearance
\let\documentstyle\appearance
\let\em\appearance
\let\end\appearance
\let\fbox\appearance
\let\footnote\appearance
\let\footnotesize\appearance
\let\hline\appearance
\let\hspace\appearance
\let\it\appearance
\let\item\appearance
\let\kill\appearance
\let\large\appearance
\let\ldots\appearance
\let\left\appearance
\let\line\appearance
\let\makebox\appearance
\let\makeindex\appearance
\let\maketitle\appearance
\let\marginpar\appearance
\let\markboth\appearance
\let\markright\appearance
\let\mbox\appearance
\let\mid\appearance
\let\normalsize\appearance
\let\onecolumn\appearance
\let\overbrace\appearance
\let\pagestyle\appearance
\let\paragraph\appearance
\let\parbox\appearance
\let\part\appearance
\let\put\appearance
\let\raisebox\appearance
\let\right\appearance
\let\rm\appearance
\let\sc\appearance
\let\scriptsize\appearance
\let\section\appearance
\let\sf\appearance
\let\small\appearance
\let\subparagraph\appearance
\let\subsection\appearance
\let\subsubsection\appearance
\let\textheight\appearance
\let\textwidth\appearance
\let\thispagestyle\appearance
\let\tiny\appearance
\let\title\appearance
\let\twocolumn\appearance
\let\typein\appearance
\let\typeout\appearance
\let\underline\appearance
\let\unitlength\appearance
\let\vector\appearance
\let\verb\appearance
\let\vspace\appearance

\let~\appearance

\catcode`\_=12
\catcode`\&=12
\catcode`\^=12

% Here we go

%  *** Your commands
\newcommand{\LL}[2]{#1 Leslie Lamport #2}
\newcommand{\DEK}{\fbox{Donald E.~Knuth}}
%  @@@ Your commands

% Use LF instead of CR
\endlinechar=10 \newlinechar=10 
% To keep space
\catcode`\ =12 
% To show comments
\catcode`\%=12 
\immediate\write1{
% Your commands are expanded.
\LL{\DEK}{\DEK} 
% This is a sample LaTeX input file.  (Version of 9 April 1986)
%
% A '%' character causes TeX to ignore all remaining text on the line,
% and is used for comments like this one.

\documentstyle{article}    % Specifies the document style.

                           % The preamble begins here.
\title{A Sample Document}  % Declares the document's title.
\author{Leslie Lamport}    % Declares the author's name.
\date{December 12, 1984}   % Deleting this command produces today's date.

\begin{document}           % End of preamble and beginning of text.

\maketitle                 % Produces the title.

This is a sample input file.  Comparing it with the output it
generates can show you how to produce a simple document of
your own.

\section{Ordinary Text}  % Produces section heading.  Lower-level
                                    % sections are begun with similar 
                                    % \subsection and \subsubsection commands.

The ends  of words and sentences are marked 
  by   spaces. It  doesn't matter how many 
spaces    you type; one is as good as 100.  The
end of   a line counts as a space.

One   or more   blank lines denote the  end 
of  a paragraph.  

Since any number of consecutive spaces are treated like a single
one, the formatting of the input file makes no difference to
      \TeX,         % The \TeX command generates the TeX logo.
but it makes a difference to you.  
When you use
      \LaTeX,       % The \LaTeX command generates the LaTeX logo.
making your input file as easy to read as possible
will be a great help as you write your document and when you
change it.  This sample file shows how you can add comments to
your own input file.

Because printing is different from typewriting, there are a 
number of things that you have to do differently when preparing 
an input file than if you were just typing the document directly.  
Quotation marks like 
       ``this'' 
have to be handled specially, as do quotes within quotes: 
       ``\,`this'                  % \, separates the double and single quote.
        is what I just 
        wrote, not  `that'\,''.  

Dashes come in three sizes: an 
       intra-word 
dash, a medium dash for number ranges like 
       1--2, 
and a punctuation 
       dash---like 
this.

A sentence-ending space should be larger than the space between words
within a sentence.  You sometimes have to type special commands in
conjunction with punctuation characters to get this right, as in the
following sentence.
       Gnats, gnus, etc.\    % `\ ' makes an inter-word space.
       all begin with G\@.   % \@ marks end-of-sentence punctuation.
You should check the spaces after periods when reading your output to
make sure you haven't forgotten any special cases.
Generating an ellipsis 
       \ldots\    % `\ ' needed because TeX ignores spaces after 
                  % command names like \ldots made from \ + letters.
                  %
                  % Note how a `%' character causes TeX to ignore the 
                  % end of the input line, so these blank lines do not
                  % start a new paragraph.
with the right spacing around the periods 
requires a special  command.  

\TeX\ interprets some common characters as commands, so you must type
special commands to generate them.  These characters include the
following: 
       \$ \& \% \# \{ and \}.

In printing, text is emphasized by using an
       {\em italic\/}  % The \/ command produces the tiny extra space that
                       % should be added between a slanted and a following
                       % unslanted letter.
type style.  

\begin{em}
   A long segment of text can also be emphasized in this way.  Text within
   such a segment given additional emphasis 
          with\/ {\em Roman} 
   type.  Italic type loses its ability to emphasize and become simply
   distracting when used excessively.  
\end{em}

It is sometimes necessary to prevent \TeX\ from breaking a line where
it might otherwise do so.  This may be at a space, as between the
``Mr.'' and ``Jones'' in
       ``Mr.~Jones'',        % ~ produces an unbreakable interword space.
or within a word---especially when the word is a symbol like
       \mbox{\em itemnum\/} 
that makes little sense when hyphenated across 
       lines.

Footnotes\footnote{This is an example of a footnote.}
pose no problem.

\TeX\ is good at typesetting mathematical formulas like
       \( x-3y = 7 \) 
or
       \( a_{1} > x^{2n} / y^{2n} > x' \).
Remember that a letter like
       $x$        % $ ... $  and  \( ... \)  are equivalent
is a formula when it denotes a mathematical symbol, and should
be treated as one.

\section{Displayed Text}

Text is displayed by indenting it from the left margin.
Quotations are commonly displayed.  There are short quotations
\begin{quote}
   This is a short a quotation.  It consists of a 
   single paragraph of text.  There is no paragraph
   indentation.
\end{quote}
and longer ones.
\begin{quotation}
   This is a longer quotation.  It consists of two paragraphs
   of text.  The beginning of each paragraph is indicated
   by an extra indentation.

   This is the second paragraph of the quotation.  It is just
   as dull as the first paragraph.
\end{quotation}
Another frequently-displayed structure is a list.
The following is an example of an {\em itemized} list.
\begin{itemize}
   \item  This is the first item of an itemized list.  Each item 
          in the list is marked with a ``tick''.  The document
          style determines what kind of tick mark is used.

   \item  This is the second item of the list.  It contains another
          list nested inside it.  The inner list is an {\em enumerated}
          list.
          \begin{enumerate}
              \item This is the first item of an enumerated list that
                    is nested within the itemized list.

              \item This is the second item of the inner list.  \LaTeX\ %
                    allows you to nest lists deeper than you really should.
          \end{enumerate}
          This is the rest of the second item of the outer list.  It
          is no more interesting than any other part of the item.
   \item  This is the third item of the list.
\end{itemize}
You can even display poetry.
\begin{verse}
   There is an environment for verse \\    % The \\ command separates lines
   Whose features some poets will curse.   % within a stanza.

                           % One or more blank lines separate stanzas.

   For instead of making\\
   Them do {\em all\/} line breaking, \\
   It allows them to put too many words on a line when they'd 
   rather be forced to be terse.
\end{verse}

Mathematical formulas may also be displayed.  A displayed formula is
one-line long; multiline formulas require special formatting
instructions.
   \[  x' + y^{2} = z_{i}^{2}\]
Don't start a paragraph with a displayed equation, nor make
one a paragraph by itself.

\end{document}             % End of document.
}\stopthisfile