summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/sauerj/metainfo.dtx
blob: b4941dbffdf640b5b08df5ca7ed2b45549353787 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
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