summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/sauerj/metainfo.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/sauerj/metainfo.dtx')
-rw-r--r--Master/texmf-dist/source/latex/sauerj/metainfo.dtx1242
1 files changed, 1242 insertions, 0 deletions
diff --git a/Master/texmf-dist/source/latex/sauerj/metainfo.dtx b/Master/texmf-dist/source/latex/sauerj/metainfo.dtx
new file mode 100644
index 00000000000..b4941dbffdf
--- /dev/null
+++ b/Master/texmf-dist/source/latex/sauerj/metainfo.dtx
@@ -0,0 +1,1242 @@
+% \iffalse meta-comment
+% Line endings: UNIX
+% Tab size: 4
+%
+% Copyright 2004 Jonathan Sauer
+%
+% This work may be distributed and/or modified under the
+% conditions of the LaTeX Project Public License, either version 1.3
+% of this license or (at your option) any later version.
+% The latest version of this license is in
+%
+% http://www.latex-project.org/lppl.txt
+%
+% and version 1.3 or later is part of all distributions of LaTeX
+% version 2003/12/01 or later.
+%
+% This work has the LPPL maintenance status "maintained".
+%
+% The Current Maintainer of this work is Jonathan Sauer
+% (<jonathan.sauer@gmx.de>).
+%
+% This work consists of the files metainfo.dtx and metainfo.ins
+% and the derived file metainfo.sty.
+%
+% \fi
+%
+% \iffalse
+%
+%<*driver>
+\documentclass{ltxdoc}
+\usepackage{metainfo}
+\EnableCrossrefs
+\CodelineIndex
+\RecordChanges
+% Modification of verbatim for tabs in listings
+\makeatletter
+{\catcode`\ =\active%
+\catcode`\^^I=\active%
+\gdef\@vobeyspaces{%
+\catcode`\ \active\let \@xobeysp%
+\catcode`\^^I\active\def^^I{~~}%
+}}%
+\makeatother
+\begin{document}
+ \DocInput{\jobname.dtx}
+\end{document}
+%</driver>
+%
+%<package>\NeedsTeXFormat{LaTeX2e}
+%<package>\ProvidesPackage{metainfo}
+%<package> [2004/11/25 v0.9.1 typeset document metainfo]
+%
+% \fi
+%
+% \CheckSum{386}
+% \CharacterTable
+% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
+% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
+% Digits \0\1\2\3\4\5\6\7\8\9
+% Exclamation \! Double quote \" Hash (number) \#
+% Dollar \$ Percent \% Ampersand \&
+% Acute accent \' Left paren \( Right paren \)
+% Asterisk \* Plus \+ Comma \,
+% Minus \- Point \. Solidus \/
+% Colon \: Semicolon \; Less than \<
+% Equals \= Greater than \> Question mark \?
+% Commercial at \@ Left bracket \[ Backslash \\
+% Right bracket \] Circumflex \^ Underscore \_
+% Grave accent \` Left brace \{ Vertical bar \|
+% Right brace \} Tilde \~}
+%
+% \DoNotIndex{\@@input,\|}
+% \DoNotIndex{\@ifundefined,\@ehc,\@empty,\@gobbletwo,\@nil}
+% \DoNotIndex{\@startsection,\@tempa,\active,\baselineskip}
+% \DoNotIndex{\begin,\bfseries,\bgroup,\catcode,\DeclareOption}
+% \DoNotIndex{\def,\egroup,\else,\end,\endinput,\expandafter}
+% \DoNotIndex{\fi,\futurelet,\gdef,\ifmmode,\ifcat,\ifx}
+% \DoNotIndex{\index,\item,\let,\long,\newcommand,\newif}
+% \DoNotIndex{\noexpand,\noindent,\normalfont,\normalsize}
+% \DoNotIndex{\PackageError,\par,\ProcessOptions,\relax,\space}
+% \DoNotIndex{\string,\textbf,\z@}
+%
+% \GetFileInfo{\jobname.sty}
+%
+% \title{The \textsf{metainfo} package\thanks{This document
+% corresponds to \textsf{\filename}~\fileversion, dated \filedate.}}
+%
+% \author{Jonathan Sauer \\ \texttt{jonathan.sauer@gmx.de}}
+%
+% \date{\filedate}
+%
+% \maketitle
+%
+% \begin{abstract}
+% This file describes the \textsf{metainfo} package that typesets only
+% special comments of a \TeX\ file.
+%
+% \end{abstract}
+%
+% \tableofcontents
+%
+% \section{Introduction}
+%
+% Suppose you write a text and include some annotations for yourself
+% that are not printed, i.e. an explanation of a pun or a short
+% summary of the current chapter in order to be able to later create a
+% summary of the whole text. Then it would be nice to be able to
+% extract these annotations and typeset them separately. This package
+% provides the macro |\typesetmetainfo| to typeset only these
+% annotations (herein called `metainfo', as they are information about
+% the information contained in the text).
+%
+%
+%
+%
+% \section{Macros}
+%
+% \DescribeMacro{\typesetmetainfo} Usage: |\typesetmetainfo|
+% \marg{file}.
+%
+% Typesets the metainfo of the \TeX\ file \meta{file}. Anything not a
+% metainfo---text, preamble---is skipped.
+%
+%
+%
+%
+% \section{Formatting}
+%
+% \subsection{Metainfo after a heading}
+%
+% Any comments following a line with a heading are considered a
+% metainfo and are typeset as if they were normal text. The first line
+% that does not begin with a percent sign finishes the metainfo.
+%
+% A heading is started by a macro defined in |\\mi@@MIbeginnings|.
+% Normally this macro contains |\chapter|, |\section|, |\subsection|,
+% and |\subsubsection|, but you can of course redefine it.
+%
+% The heading itself is typeset as well, before the metainfo,
+% resulting all metainfo being typeset using the outline of the normal
+% document. Note that when writing a heading, some restriction apply:
+%
+% \begin{enumerate}
+% \item The heading macro must be at the beginning of the line.
+%
+% \item Any parameters of the macro must be on the same line.
+% (parameters split over several lines might work, but they
+% are not guaranteed to)
+%
+% \end{enumerate}
+%
+%
+%
+%
+% \subsection{Local metainfo}
+%
+% There is another way to include metainfo in a document, that is as a
+% \emph{local metainfo}. A local metainfo is a metainfo not following
+% a heading; instead they can appear anywhere in the text. They start
+% with a double percent sign at the beginning of the line (|%%|); the
+% line itself is then typeset as a metainfo as well as all the
+% following lines beginning with a |%| (just as a metainfo following a
+% heading). The first line that does not begin with a percent sign
+% finishes the local metainfo.
+%
+% You can format a local metainfo using three macros. (see section
+% \ref{sec:ExLoMI} on page \pageref{sec:ExLoMI} for an example how to
+% customize them.)
+%
+% \begin{enumerate}
+% \item |\mi@@firstlocalMItext|: The contents of this macro is
+% inserted before the first local metainfo of a chapter.
+%
+% \item |\mi@@lastlocalMItext|: The contents of this macro is
+% inserted after the last local metainfo of a chapter.
+%
+% \item |\mi@@everylocalMItext|: The contents of this macro is
+% inserted before every local metainfo.
+%
+% \end{enumerate}
+%
+% \paragraph{Note} If you change these macros in your document
+% preamble or your main document opposed to a package file, you must
+% surround them with |\makeatletter| and |\makeatother|, as shown in
+% the example below.
+%
+%
+%
+%
+% \section{Package options}\label{sec:Options}
+%
+% The following package options exist:
+%
+% \begin{description}
+% \item[compactheadings] Changes the section headings to be more
+% compact in order to save some space.
+%
+% \item[indexshorthand] Provides shorthands for indexing.
+% |^|\marg{text} indexes and typesets \meta{text}, |^^|\marg{text}
+% only indexes it.\footnote{These shorthands have been inspired by
+% Donald E. Knuth's own index macros used for the \TeX book.}
+% For indexing, the standard index macro |\index| is used.
+%
+% These macros only work in text mode; in math mode, |^| is a
+% superscript as predefined in \LaTeX.
+%
+% \item[listlocalmetainfo] Changes the macros |\mi@@firstlocalMItext|,
+% |\mi@@lastlocalMItext| and |\mi@@everylocalMItext| (described in
+% the section above) to |itemize| the local metainfo.
+% \end{description}
+%
+%
+%
+%
+% \section{Driver files}
+%
+% In order to typeset only the metainfo of a document, a special
+% driver file is needed. This driver loads the packages necessary for
+% typesetting the metainfo (at least the package \textsf{metainfo})
+% and inputs the document to be typeset using |\typesetmetainfo|.
+%
+% \paragraph{Note} No package of the document processed using
+% |\typesetmetainfo| is loaded, as the |\usepackage| macros are
+% skipped. The same is true for any definitions in the document
+% preamble or elsewhere: They are skipped, so if the metainfo relies
+% on these definitions, they have to be included in the driver as
+% well.
+%
+%
+%
+%
+% \section{Examples}
+%
+% \subsection{Example driver file}
+%
+% The following driver file typesets the metainfo of the \TeX\ file
+% `example.tex' using compact headings:
+%
+% \begin{verbatim}
+% \documentclass{book}
+% \usepackage[compactheadings]{metainfo}
+%
+% \begin{document}
+% \typesetmetainfo{example}
+% \end{document}
+% \end{verbatim}
+%
+%
+%
+%
+% \subsection{Example document}
+%
+% If we save the following file as `example.tex' and process it using
+% the driver file in the example above \ldots
+%
+% \begin{verbatim}
+% \documentclass{minimal}
+% \usepackage{testpackage}
+%
+% \begin{document}
+%
+% \chapter{Chapter 1}
+% % Metainfo for chapter `Chapter 1'
+%
+% \section{Section 1}
+% % Metainfo for section `Section 1'
+%
+% This is some text.
+%
+% \chapter{Chapter 2}
+% \section{Section 2}
+% % Metainfo for section `Section 2'
+%
+% This is some more text.
+%
+% %% Local metainfo. This metainfo is a bit longer, but only
+% % a little bit.
+%
+% \section{Section 3}
+% % Metainfo for section `Section 3'
+% \end{document}
+% \end{verbatim}
+%
+% \ldots\ this results in:\footnote{Approximately, as the real
+% formatting will differ slightly from the text typeset here.}
+%
+% \addvspace{\baselineskip}
+% \textbf{Chapter 1}\par
+% Metainfo for chapter `Chapter 1'
+%
+% \addvspace{\baselineskip}
+% \textbf{Section 1}\par
+% Metainfo for section `Section 1'
+%
+% \addvspace{\baselineskip}
+% \textbf{Chapter 2}\par
+% \textbf{Section 2}\par
+% Metainfo for section `Section 2'
+%
+% \addvspace{\baselineskip}
+% Annotations:\par
+% Local metainfo. This metainfo is a bit longer, but only a little
+% bit.
+%
+% \addvspace{\baselineskip}
+% \textbf{Section 3}\par
+% Metainfo for section `Section 3'
+%
+%
+%
+%
+% \subsection{Example local metainfo formatting}\label{sec:ExLoMI}
+%
+% The following macros prefix local metainfo with `Annotations:' in
+% bold typeface and typesets the local metainfo in an |itemize|
+% environment:\footnote{Similar to the package option
+% \texttt{listlocalmetainfo}, described in section \ref{sec:Options}
+% on page \pageref{sec:Options} does.}
+%
+% \begin{verbatim}
+% \makeatletter
+% \def\mi@@firstlocalMItext{%
+% \addvspace{\baselineskip}%
+% \noindent\textbf{Annotations:}%
+% \begin{itemize}%
+% }
+% \def\mi@@lastlocalMItext{%
+% \end{itemize}%
+% }
+% \def\mi@@everylocalMItext{%
+% \item\relax%
+% }
+% \makeatother
+% \end{verbatim}
+%
+%
+%
+%
+% \section{Notes/Limitations}
+%
+% \begin{itemize}
+% \item Any text or macros on the same line as a heading are
+% processed as well, immediately after the heading. Thus
+% you can type |\section{foo}\label{sec:foo}| and refer
+% to this section inside a metainfo using the label
+% |sec:foo|.
+%
+% \item The document included using |\typesetmetainfo| must
+% be a valid \LaTeX\ document insofar as that it must
+% contain a |document| environment, because |\end{document}|
+% serves as the ending delimiter for typesetting the
+% metainfo.
+%
+% That also means that any metainfo following |\end{document}|
+% is \emph{not} typeset.
+%
+% \end{itemize}
+%
+%
+%
+%
+% \StopEventually{}
+%
+% \section{Implementation}
+%
+% \subsection{Main environments and macros}
+%
+% \begin{macro}{\typesetmetainfo}
+%
+% Usage: |\typesetmetainfo| \marg{file}.
+%
+% Typesets the metainfo of a document.
+%
+% \begin{macrocode}
+\newcommand{\typesetmetainfo}[1]{%
+ \bgroup%
+ \mi@activenewline%
+ \mi@emptyactivepercent%
+ \mi@otherbraces%
+ \ifmi@indexmacros\mi@activehat\fi%
+% \end{macrocode}
+%
+% We provide support for the standard \LaTeX\ |verbatim| environment:
+%
+% \begin{macrocode}
+ \let\mi@old@verbatim\@verbatim%
+ \def\@verbatim{%
+ \mi@old@verbatim%
+ \mi@verbatimnewline%
+ }%
+% \end{macrocode}
+%
+% We use the original \TeX\ definition of |\input| (saved by \LaTeX\
+% in |\@@input|), because we must continue with our special processing
+% immediately after \meta{file} has been opened. This is a job for the
+% original \TeX\ |\input|, as it simply switches the input stream to
+% \meta{file} and expands to nothing.
+%
+% The |\relax| delimits the filename.
+%
+% \begin{macrocode}
+ \expandafter\mi@skiplines\@@input#1\relax%
+ \egroup%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+%
+%
+% \subsection{Package customization}
+%
+% \begin{macro}{\mi@@MIbeginnings}
+%
+% Stores all the macros that can begin a metainfo.
+%
+% \begin{macrocode}
+\def\mi@@MIbeginnings{\chapter\section\subsection\subsubsection}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@@firstlocalMItext}
+%
+% Stores the text inserted before the first local metainfo.
+%
+% \begin{macrocode}
+\def\mi@@firstlocalMItext{\textbf{Annotations:}\par\noindent}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@@lastlocalMItext}
+%
+% Stores the text inserted after the last local metainfo.
+%
+% \begin{macrocode}
+\def\mi@@lastlocalMItext{}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@@everylocalMItext}
+%
+% Stores the text inserted before every local metainfo.
+%
+% \begin{macrocode}
+\def\mi@@everylocalMItext{}
+% \end{macrocode}
+% \end{macro}
+%
+%
+%
+%
+% \subsection{Package options}
+%
+% \subsubsection{Headings}
+%
+% We provide the possibility of changing the headings to a more
+% compact formatting:
+%
+% \begin{macrocode}
+\DeclareOption{compactheadings}{%
+ \@ifundefined{thechapter}{}{%
+ \def\chapter{\@startsection{chapter}{0}{\z@}{-2\baselineskip}%
+ {\baselineskip}{\normalfont\normalsize\bfseries}}%
+ }%
+ \def\section{\@startsection{section}{1}{\z@}{-2\baselineskip}%
+ {\baselineskip}{\normalfont\normalsize\bfseries}}%
+ \def\subsection{\@startsection{subsection}{2}{\z@}{-2\baselineskip}%
+ {\baselineskip}{\normalfont\normalsize\bfseries}}%
+ \def\subsubsection{\@startsection{subsubsection}{3}{\z@}%
+ {-2\baselineskip}{\baselineskip}%
+ {\normalfont\normalsize\bfseries}}%
+}
+% \end{macrocode}
+%
+%
+%
+%
+% \subsubsection{Index shorthand}
+%
+% \begin{macro}{\ifmi@indexmacros}
+%
+% |true|, if index shorthands specified using the package option
+% |indexshorthand| are used, otherwise |false|:
+%
+% \begin{macrocode}
+\newif\ifmi@indexmacros
+\mi@indexmacrosfalse
+% \end{macrocode}
+% \end{macro}
+%
+% We provide the possibility of using the shorthand |^| for an index
+% entry that is typeset, and |^^| for an index entry that is not
+% typeset:
+%
+% \begin{macrocode}
+\DeclareOption{indexshorthand}{%
+ \mi@indexmacrostrue%
+% \end{macrocode}
+%
+%
+% \begin{macro}{\mi@hat}
+%
+% We save the original meaning of |^|. We do not simply use |^| in the
+% |\mi@hat|\ldots-macros, because then we would assume that |^| is not
+% already an active character before our catcode change (which we will
+% make in |\typesetmetainfo|). Normally, |^| has catcode 7
+% (superscript), but if is was active (i.e. because of another package
+% changing |^|), we would store an active |^| in the definition of the
+% |\mi@hat|\ldots-macros. When later used this |^| would point to our
+% macro |\mi@hat|, resulting in an endless loop. So we save the
+% original meaning of |^| instead using |\let|, which, if |^| is
+% active, would save the macro |^| would have been |\let| to.
+%
+% \begin{macrocode}
+ \let\mi@@@hat^%
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@hat}
+%
+% Main macro for indexing and first step in deciding how to index:
+%
+% \begin{itemize}
+% \item Math mode: Expand to the original definition of |^|.
+%
+% \item Otherwise: Check the next token using |\mi@hat@|.
+%
+% \end{itemize}
+%
+% \begin{macrocode}
+ \def\mi@hat{%
+ \ifmmode%
+ \expandafter\mi@@@hat%
+ \else%
+ \expandafter\futurelet\expandafter\@tempa\expandafter\mi@hat@%
+ \fi%
+ }
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@hat@}
+%
+% Second step in deciding how to index. We know that we are not in
+% math mode. The token following the hat has been prefetched and
+% stored in |\@tempa|. (it has not been read yet)
+%
+% \begin{itemize}
+% \item A second hat (|^|): Check the next token using |\mi@hat@twohats|.
+%
+% \item Opening brace: Typeset the index word and index it using
+% it |\mi@indextypeset|.
+%
+% \item Otherwise: Display an error, as |^^| must be followed by
+% a parameter in braces.
+%
+% \end{itemize}
+%
+% \begin{macrocode}
+ \def\mi@hat@{%
+ \ifx\@tempa\mi@hat%
+ \expandafter\mi@hat@twohats%
+ \else\ifx\@tempa\bgroup%
+ \expandafter\expandafter\expandafter\mi@indextypeset%
+ \else%
+ \mi@hat@errbrace%
+ \fi\fi%
+ }
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@hat@twohats}
+%
+% First step in deciding how to index a word not typeset. We know we
+% have two hats in a row (|^^|), but the second hat is not read yet
+% (only prefetched using |\futurelet|). Therefore we gobble it using
+% |#1|.
+%
+% \begin{macrocode}
+ \def\mi@hat@twohats#1{%
+ \futurelet\@tempa\mi@hat@twohats@%
+ }
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@hat@twohats}
+%
+% Second step in deciding how to index a word not typeset. We know we
+% have two hats in a row, both read. The token following the two hats
+% has been prefetched and stored in |\@tempa|.
+%
+% Note that we could skip this step and simpy expand to |\index|,
+% letting |\index| take care that a proper parameter follows.
+%
+% \begin{macrocode}
+ \def\mi@hat@twohats@{%
+ \ifx\@tempa\bgroup%
+ \expandafter\index%
+ \else%
+ \mi@hat@errbrace%
+ \fi%
+ }
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@indextypeset}
+%
+% Usage: |\mi@indextypeset| \marg{word}. Typesets \meta{word} and
+% indexes it using |\index|.
+%
+% \begin{macrocode}
+ \def\mi@indextypeset#1{%
+ #1\index{#1}%
+ }
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@hat@errbrace}
+%
+% Error handling when a |^| or |^^| is not followed by a left brace.
+%
+% \begin{macrocode}
+ \def\mi@hat@errbrace{%
+ \PackageError{metainfo}{`\string^' or `\string^\string^' not %
+ followed by a left brace}\@ehc%
+ }
+% \end{macrocode}
+% \end{macro}
+%
+%
+% End of |\DeclareOption{index}|:
+%
+% \begin{macrocode}
+}
+% \end{macrocode}
+%
+%
+%
+%
+% \subsubsection{Other options}
+%
+% \begin{macrocode}
+\DeclareOption{listlocalmetainfo}{%
+ \def\mi@@firstlocalMItext{%
+ \begin{itemize}%
+ }%
+ \def\mi@@lastlocalMItext{%
+ \end{itemize}%
+ }%
+ \def\mi@@everylocalMItext{%
+ \item\relax%
+ }%
+}
+% \end{macrocode}
+%
+%
+%
+%
+% \begin{macrocode}
+\ProcessOptions\relax
+% \end{macrocode}
+%
+%
+%
+%
+% \subsection{Internal environments and macros}
+%
+% \subsubsection{General definitions and flags}
+%
+% \paragraph{Strategy for dealing with catcode changes} At the
+% beginning of the processing, the catcodes are changed as follows:
+%
+% \begin{tabular}{cl}
+% |^^M| & 13 (active), set in |\mi@activenewline| \\
+% |%| & 13, set in |\mi@emptyactivepercent| \\
+% |{| & 12 (other), set in |\mi@otherbraces| \\
+% |}| & 12, set in |\mi@otherbraces| \\
+% |^| & 13, optionally set in |\mi@activehat| \\
+% \end{tabular}
+%
+% If any macro changes the catcodes of these characters, it must reset
+% them to these values after processing. If any macro needs the braces
+% |{| and |}| for parameter grouping, it should use the macro
+% |\mi@normalbraces| to change the catcodes accordingly.
+%
+%
+% \begin{macro}{\ifmi@firstlocalMI}
+%
+% |true| if this is the first local metainfo, otherwise |false|. Used
+% to insert |\mi@@firstlocalMItext| and |\mi@@lastlocalMItext|.
+%
+% \begin{macrocode}
+\newif\ifmi@firstlocalMI
+\mi@firstlocalMItrue
+% \end{macrocode}
+% \end{macro}
+%
+%
+%
+%
+% \subsubsection{Modes}
+%
+% Three modes of processing exist:
+%
+% \begin{description}
+% \item[Skipping text] Text is skipped line after line. If two
+% percent signs are found at the beginning of a new line,
+% a local metainfo is begun and the mode changed to
+% `Typesetting a metainfo'.
+%
+% Main macro: |\mi@skiplines|.
+%
+% \item[Beginning metainfo] The appropriate heading is typeset
+% and the remaining line of text skipped. The mode is then
+% changed to `Typesetting a metainfo'.
+%
+% Main macro: |\mi@checkbeginMI|.
+%
+% \item[Typesetting a metainfo] The text is typeset. If a line does
+% not start with a percent sign, the metainfo is done. The
+% mode is then changed to `Skipping text'.
+%
+% Main macro: |\mi@typesetMI|.
+%
+% \end{description}
+%
+%
+% \begin{macro}{\mi@skiplines}
+%
+% Main macro. Skips lines and checks the first token of a line (stored
+% in |#1|) for two special cases:
+%
+% \begin{enumerate}
+% \item A percent sign |%|: We check if it starts a local metainfo
+% using |\mi@checkbeginlocalMI|.
+%
+% \item A control sequence: We check if it starts a new metainfo
+% using |\mi@checkbeginMI|.
+%
+% \end{enumerate}
+%
+% \begin{macrocode}
+\def\mi@skiplines#1{%
+ \ifx#1\mi@percentempty%
+% \end{macrocode}
+%
+% A percent sign: We check if it starts a local metainfo.
+%
+% \begin{macrocode}
+ \expandafter\mi@checkbeginlocalMI%
+ \else\ifcat\noexpand#1\relax%
+% \end{macrocode}
+%
+% A control sequence: We check if it starts a new metainfo.
+%
+% \begin{macrocode}
+ \expandafter\expandafter\expandafter\mi@checkbeginMI%
+ \else%
+% \end{macrocode}
+%
+% Anything else: We skip it and the remaining line of text. Note that
+% it could be a line ending (|^^M|), so it may be possible that we
+% gobble only |#1|, which will be re-inserted into the stream below.
+% That way we do not have to check if |#1| is a line ending.
+%
+% \begin{macrocode}
+ \expandafter\expandafter\expandafter\mi@gobbletolineend%
+ \fi\fi%
+% \end{macrocode}
+%
+% We always insert the first token of a line back into the stream,
+% even though it is not necessary for |\mi@checkbeginlocalMI|. But as
+% normally most of the lines of a text will be skipped, we optimize
+% for this case.
+%
+% \begin{macrocode}
+ #1%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% The following macros require |^^M| to be active:
+%
+% \begin{macrocode}
+\bgroup
+\catcode`\^^M=\active%
+% \end{macrocode}
+%
+%
+% \begin{macro}{\mi@typesetMI}
+%
+% Prepares the typesetting of a metainfo.
+%
+% \begin{macrocode}
+\gdef\mi@typesetMI{%
+ \mi@normalbraces%
+% \end{macrocode}
+%
+% Every CR we check if the next line continues the metainfo
+% using |\mi@typesetMI@checkend|.
+%
+% \begin{macrocode}
+ \let^^M\mi@typesetMI@checkend%
+% \end{macrocode}
+%
+% Now we start typesetting the text. We let \TeX\ take completely
+% control instead of reading one line after the other; we will regain
+% control at the end of each line using our redefinition of |^^M|.
+%
+% \begin{macrocode}
+ \ignorespaces%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@typesetMI@checkend}
+%
+% Called at a carriage return. If the token after the CR is equals to
+% |\mi@percentempty|, the next line starts with a |%|, thus continuing
+% the metainfo. Otherwise, the metainfo is finished.
+%
+% \begin{macrocode}
+\long\gdef\mi@typesetMI@checkend#1{%
+ \ifx#1\mi@percentempty%
+% \end{macrocode}
+%
+% The next line continues the comment. We check for an empty line:
+%
+% \begin{macrocode}
+ \expandafter\mi@typesetMI@checkend@%
+ \else%
+% \end{macrocode}
+%
+% The next line finishes the comment:
+%
+% \begin{macrocode}
+ \mi@otherbraces%
+ \let^^M\@empty%
+ \expandafter\mi@skiplines\expandafter#1%
+ \fi%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@typesetMI@checkend@}
+%
+% Checks if a |^^M| (CR) follows immediately after the |%|. Then we
+% insert a |\par|. Note that any spaces between the |%| and the CR
+% are automatically skipped by using a non-delimited parameter.
+%
+% \begin{macrocode}
+\long\gdef\mi@typesetMI@checkend@#1{%
+ \ifx#1\mi@typesetMI@checkend%
+ \par\expandafter\mi@typesetMI@checkend%
+ \else%
+% \end{macrocode}
+%
+% We assume the line is |% |\meta{text} instead of |%|\meta{text},
+% thus we insert back a space that was skipped before:
+%
+% \begin{macrocode}
+ \space%
+ \expandafter#1%
+ \fi%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@checkbeginMI}
+%
+% Usage: |\mi@checkbeginMI|\meta{cs}.
+%
+% First step in the check for the begin of a metainfo: Checks if
+% \meta{cs} is a control sequence that can begin a metainfo.
+%
+% \begin{macrocode}
+\gdef\mi@checkbeginMI#1{%
+% \end{macrocode}
+%
+% Handle |\end|:
+%
+% \begin{macrocode}
+ \ifx#1\end%
+ \expandafter\mi@checkdocumentend%
+ \else%
+% \end{macrocode}
+%
+% We check if \meta{cs} is a relevant control sequence. (these are
+% stored in |\mi@@MIbeginnings|) Then we use |\mi@checkbeginMI@| to
+% evaluate the result:
+%
+% \begin{macrocode}
+ \def\@tempa##1#1##2\@nil{\mi@checkbeginMI@{##2}#1}%
+ \expandafter\expandafter\expandafter\@tempa%
+ \expandafter\mi@@MIbeginnings\expandafter#1%
+ \expandafter\@nil%
+ \fi%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@checkbeginMI@}
+%
+% Support macro for |\mi@checkbeginMI|. Checks if |#2| is a relevant
+% control sequence by checking if |#1| is empty (|false|) or not
+% (|true|).
+%
+% \begin{macrocode}
+\gdef\mi@checkbeginMI@#1#2{%
+ \ifx^^M#1^^M%
+% \end{macrocode}
+%
+% Not a relevant control sequence: Skip till the end of the line.
+%
+% \begin{macrocode}
+ \expandafter\mi@gobbletolineend%
+ \else%
+% \end{macrocode}
+%
+% A relevant control sequence. If there has been any local metainfo
+% before this macro, we finish it by inserting |\mi@@lastlocalMItext|:
+%
+% \begin{macrocode}
+ \ifmi@firstlocalMI\else\mi@@lastlocalMItext\fi%
+% \end{macrocode}
+%
+% We restore all character catcodes except for |^^M|, which we use to
+% continue processing after the control sequence in question has been
+% executed: (this is the reason a heading must appear on a single
+% line, as otherweise |^^M| is executed more than once)
+%
+% \begin{macrocode}
+ \let^^M\mi@checkbeginMI@@%
+ \mi@normalbraces%
+ \mi@normalpercent%
+% \end{macrocode}
+%
+% In any case, a local metainfo following this macro is the first, so
+% we set the flag accordingly:
+%
+% \begin{macrocode}
+ \mi@firstlocalMItrue%
+ \expandafter#2%
+ \fi%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@checkbeginMI@@}
+%
+% Support macro for |\mi@checkbeginMI@|. Is called via |^^M| at the end
+% of a line.
+%
+% \begin{macrocode}
+\gdef\mi@checkbeginMI@@{%
+ \let^^M\@empty%
+ \mi@otherbraces%
+ \mi@emptyactivepercent%
+ \mi@checkbeginMI@@@%
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macrocode}
+\egroup
+% \end{macrocode}
+%
+%
+% \begin{macro}{\mi@checkbeginMI@@@}
+%
+% Support macro for |\mi@checkbeginMI| and the second step in the
+% check for the begin of a metainfo: Checks if the line after the
+% control sequence begins with a percent sign.
+%
+% \begin{macrocode}
+\def\mi@checkbeginMI@@@#1{%
+ \ifx#1\mi@percentempty%
+% \end{macrocode}
+%
+% A percent sign: It starts a metainfo. Change to metainfo.
+%
+% \begin{macrocode}
+ \par%
+ \expandafter\mi@typesetMI%
+ \else%
+% \end{macrocode}
+%
+% Anything else: No metainfo follows. Ignore it.
+%
+% \begin{macrocode}
+ \expandafter\mi@skiplines\expandafter#1%
+ \fi%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@checkbeginlocalMI}
+%
+% Usage: |\mi@checkbeginlocalMI|\meta{dummy}\meta{next token}.
+%
+% \meta{dummy} is the result of an optimization of |\mi@skiplines|.
+% (see above)
+%
+% \begin{macrocode}
+\def\mi@checkbeginlocalMI#1#2{%
+ \ifx#2\mi@percentempty%
+% \end{macrocode}
+%
+% A percent sign: It starts a local metainfo. Change to metainfo.
+%
+% \begin{macrocode}
+ \par%
+ \ifmi@firstlocalMI\mi@@firstlocalMItext\fi%
+ \mi@@everylocalMItext%
+% \end{macrocode}
+%
+% We have begun to typeset the local metainfo, therefore we take note
+% that any local metainfo following this one is not the first.
+%
+% \begin{macrocode}
+ \mi@firstlocalMIfalse%
+ \expandafter\mi@typesetMI%
+ \else%
+% \end{macrocode}
+%
+% Anything else: No, it is just a simple comment. Ignore it.
+%
+% \begin{macrocode}
+ \expandafter\mi@gobbletolineend\expandafter#2%
+ \fi%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@checkdocumentend}
+%
+% Checks if the |\end| just read ends the |document| environment.
+%
+% \begin{macrocode}
+\def\mi@checkdocumentend{%
+% \end{macrocode}
+%
+% We change the catcodes of braces back to normal in order to get the
+% name of the environment as the only parameter of |\mi@checkdocumentend@|
+% and not only the opening brace.
+%
+% \begin{macrocode}
+ \mi@normalbraces%
+ \mi@checkdocumentend@%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@checkdocumentend@}
+%
+% Support macro for |\mi@checkdocumentend|.
+%
+% \begin{macrocode}
+\def\mi@checkdocumentend@#1{%
+ \def\@tempa{#1}%
+ \ifx\@tempa\mi@textdocument%
+% \end{macrocode}
+%
+% If there has been any local metainfo before this macro, we finish it
+% by inserting |\mi@@lastlocalMItext|:
+%
+% \begin{macrocode}
+ \ifmi@firstlocalMI\else\mi@@lastlocalMItext\fi%
+ \expandafter\mi@gobbletolineend@any\expandafter\endinput%
+ \else%
+% \end{macrocode}
+%
+% As are not done yet, we better set the catcode of braces to
+% `letter':
+%
+% \begin{macrocode}
+ \mi@otherbraces%
+ \expandafter\mi@skiplines%
+ \fi%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@textdocument}
+%
+% The text `document' for |\mi@checkdocumentend|.
+%
+% \begin{macrocode}
+\def\mi@textdocument{document}
+% \end{macrocode}
+% \end{macro}
+%
+%
+%
+% \begin{macro}{\mi@percentempty}
+%
+% \begin{macrocode}
+\def\mi@percentempty{\@empty}
+% \end{macrocode}
+% \end{macro}
+%
+%
+%
+%
+% \subsubsection{Gobbling text}
+%
+% \begin{macrocode}
+\bgroup
+\catcode`\^^M=\active%
+% \end{macrocode}
+%
+%
+% \begin{macro}{\mi@gobbletolineend}
+%
+% Gobbles up any text till the end of the line. Continues with
+% |\mi@skiplines|. (specialization of |\mi@gobbletolineend@any|)
+%
+% \begin{macrocode}
+\gdef\mi@gobbletolineend{%
+ \mi@gobbletolineend@any\mi@skiplines%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@gobbletolineend@any}
+%
+% Usage: |\mi@gobbletolineend@any| \marg{macro}.
+%
+% Gobbles up any text till the end of the line. Continues with
+% \meta{macro}. The macro is |long| in case the line (stored in |#2|)
+% contains a |\par|.
+%
+% \begin{macrocode}
+\long\gdef\mi@gobbletolineend@any#1#2^^M{%
+ #1%
+}
+\egroup
+% \end{macrocode}
+% \end{macro}
+%
+%
+%
+% \subsubsection{Catcode changes}
+%
+% We define the macros for changing catcodes:
+%
+% \begin{macro}{\mi@activenewline}
+% \begin{macro}{\mi@verbatimnewline}
+% \begin{macro}{\mi@emptyactivepercent}
+% \begin{macro}{\mi@activehat}
+%
+% \begin{macrocode}
+\bgroup
+% \end{macrocode}
+%
+% We use \verb+|+ as the comment character as we make |%| active:
+%
+% \begin{macrocode}
+\catcode`\|=14 %
+\catcode`\^^M=\active%
+\catcode`\%=\active|
+\gdef\mi@activenewline{|
+ \catcode`\^^M=\active|
+ \let^^M\@empty|
+}|
+\gdef\mi@verbatimnewline{|
+ \catcode`\^^M=\active|
+ \def^^M{\par\@gobbletwo}|
+}|
+\gdef\mi@emptyactivepercent{|
+ \catcode`\%=\active|
+ \let%\mi@percentempty|
+}|
+\catcode`\^=\active|
+\gdef\mi@activehat{|
+ \catcode`\^\active|
+ \let^\mi@hat|
+}|
+\egroup
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@normalpercent}
+%
+% \begin{macrocode}
+\def\mi@normalpercent{%
+ \catcode`\%=14 %
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@otherbraces}
+%
+% \begin{macrocode}
+\def\mi@otherbraces{%
+ \catcode`\{=12 %
+ \catcode`\}=12 %
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\mi@normalbraces}
+%
+% \begin{macrocode}
+\def\mi@normalbraces{%
+ \catcode`\{=1 %
+ \catcode`\}=2 %
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+%
+% \Finale
+% \PrintChanges
+% \PrintIndex
+\endinput \ No newline at end of file