summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/nicetext/makedoc.sty
blob: 292a44242d0db92fa723c12029cdfe26e7417464 (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
%% Macro package `makedoc.sty' for LaTeX2e, 

%% copyright (C) 2009 2010 Uwe L\"uck, 

%%   http://www.contact-ednotes.sty.de.vu 

%% -- author-maintained in the sense of LPPL below -- 

%% for preparing documentations from packages.



\def\fileversion{0.4} \def\filedate{2010/03/30} 



%% This file can be redistributed and/or modified under 

%% the terms of the LaTeX Project Public License; either 

%% version 1.3a of the License, or any later version.

%% The latest version of this license is in

%%     http://www.latex-project.org/lppl.txt

%% We did our best to help you, but there is NO WARRANTY. 

%%

%% Please report bugs, problems, and suggestions via 

%% 

%%   http://www.contact-ednotes.sty.de.vu 

%% 

\NeedsTeXFormat{LaTeX2e}[1994/12/01] 

% 1994/12/01: \newcommand* etc. 

\ProvidesPackage{makedoc}[\filedate\space v\fileversion\space

                          TeX input from *.sty (UL)] 

%%

%% |\PackageCodeTrue| and |\PackageCodeFalse| set `\ifPackageCode'

%% globally, so redefinition of `~' (playing a key role in 'fifinddo') 

%% may be kept local. Note the capital `T' and `F'!

\newcommand*{\PackageCodeTrue} {\global\let\ifPackageCode\iftrue}

\newcommand*{\PackageCodeFalse}{\global\let\ifPackageCode\iffalse}

%% |\ifPackageCode| is used to determine whether a listing environment 

%% must be `\beg'un or `\end'ed. You may also want to suppress empty 

%% code lines, while empty lines should issue a `\par' break in 

%% ``comment" mode.

%%

%% Since `\newif' is not used, `\ifPackageCode' must be declared 

%% explicitly. Declaration of new `\if's must be early in case 

%% they occur in code that is skipped by another `\if'\dots

%% [TODO!? cf. others 2010/03/15]

\PackageCodeFalse

%%

%% 'makedoc' is an extension of 'fifinddo' on which it depends.

\RequirePackage{fifinddo}[2009/04/13]

%% Both 'fifinddo' and 'makedoc' use the ``underscore" `_' 

%% as ``private letter" and restore its standard ``subscript" 

%% function ({\it \TeX book Chap.\,7}) at their end. 

%% Push\slash pop functionality as with `@' and `\RequirePackage' 

%% is missing here. So after loading 'fifinddo',

%% we need to declare our private letter (again). 

\catcode`\_=11 %% underscore used in control words

%%

%% \subsection{&\MakeDocCorrectHook\ (\dqtd{`txt2TeX'})}

%% |\MakeDocCorrectHook| is predefined to leave its argument without 

%% the enclosing braces, otherwise unchanged:

\let\MakeDocCorrectHook\@firstofone

%% Less efficiently, the same could have been set up as 

% \newcommand*{\MakeDocCorrectHook}[1]{\ProcessStringWith{#1}{LEAVE}}

%% according to 'fifinddo'. 

%%

%% It may be \emph{redefined} in a \emph{configuration} file like 

%% 'makedoc.cfg' or the 'makedoc' script file applying to a single 

%% package file in order to, e.g., converting plain text to \TeX\ input 

%% conforming to typographical conventions, making `$\dots$' from 

%% \qtd{&.&.&.}, %% dots should not be replaced!

%% e.g. 

%% Replace `LEAVE' in the previous suggestion by an identifier 

%% whose job you have defined before, and use `\renewcommand' 

%% in place of `\newcommand'. 

%% See an example in 'makedoc.cfg'.

%%

%% You can \emph{test} your own `\MakeDocCorrectHook' by 

%% \[`\typeout{\MakeDocCorrectHook{<test-string>}}'\]

%% ... provided (sometimes) `\MakeOther\ ' ...

%% You can even change it using `\IfInputLine' from 'fifinddo' in the 

%% midst of preprocessing a package documentation. 

%%

%% \subsection{Distinguishing package code from comments}%% <- wiki style breaks in self-doc. 

%% \label{sec:distinguish}

%% Use of comment marks is a matter of personal style. Only lines 

%% starting with the sequence |%% | %% box 2010/03/16

%% are typeset in \TeX\ quality 

%% under the present release. Lines just containing |%%|

%% (without the space) are used to suppress empty code lines 

%% preceding section titles (while keeping some visual space 

%% in the package file). There is a preferable way to do this, 

%% however not in the present release ...

%%

%% The parsing macros must be set up reading `%' and ` ' as ``other" 

%% characters. Using the optional arguments for this creates 

%% difficulties that can be somewhat avoided by redefining 

%% |\PatternCodes|.

\SetPatternCodes{\MakeOther\%\MakeOther\ }%% 2010/03/30

%%

%% The next line sets the ``sandbox" for the detecting macro, as it 

%% is coined in the documentation of 'fifinddo', with ``identifier" 

%% |PPScomment|.

\MakeSetupSubstringCondition{PPScomment}{%% }{{#1}} 

%% The last argument stores the expanded input line for reference by 

%% macros called. The next line is a test whether the setup works. 

%  \expandafter \show \csname \setup_substr_cond PPScomment\endcsname 

%% Here comes the definition of the corresponding testing macro. 

%% #3 is the expanded input line from above. The `\If'\dots commands, 

%% `\fdInputLine', `\fdInputLine', and `\RemoveDummyPatternArg' 

%% are from 'fifinddo'. 

\MakeSubstringConditional{PPScomment}{%% }#3{%% #3 entire test string 

    \DecideCommentCode{#1}{#2}{#3}\PPstring} 

%% |\DecideCommentCode{#1}{#2}{#3}{#4}| is shared with the parser 

%% for the \lq`% '\rq\ commenting style. %% new 2010/03/28

\newcommand*{\DecideCommentCode}[4]{%

  \IfFDinputEmpty{\OnEmptyInputLine}{%

%% The empty line test comes early to offer control with 

%% `\OnEmptyInputLine' both in code and comment mode. 

%% Maybe it should always? %% TODO 2009/04/13

    \IfFDempty{#1}%

              {\TreatAsComment{%

                 \RemoveDummyPatternArg\MakeDocCorrectHook{#2}}}%

              {\ifx\fdInputLine#4%

                 \ifPackageCode\else \WriteResult{}\fi%

%% ... allows paragraphs in comments.

               \else \TreatAsCode{#3}\fi}}}

%% Job |PScomment| deals with the |% | commenting style:

\MakeSetupSubstringCondition{PScomment}{% }{{#1}} 

\MakeSubstringConditional{PScomment}{% }#3{%

    \DecideCommentCode{#1}{#2}{#3}\PercentChar} 

%% `\PercentChar' is from 'fifinddo'.---Return to `\fdPatternCodes': 

\ResetPatternCodes    %% 2010/03/30

%% 

%% |\PPstring| stores the line suppressing empty code lines with 

%% the \lq`%% '\rq\ style: 

\newcommand*{\PPstring}{} \xdef\PPstring{\PercentChar\PercentChar}

%%

%% |comment| will be a ``generic" identifier to call a comment line 

%% detector. It might be predefined to issue an ``undefined" error; 

%% however this release predefines it to behave like `PPScomment':

\CopyFDconditionFromTo{PPScomment}{comment}

%% This means that the \lq`%% '\rq\ commenting style is assumed by 

%% default. \[`\CopyFDconditionFromTo{PScomment}{comment}'\]

%% switches to the \lq`% '\rq\ style (with the {\it Wikipedia} 

%% sectioning parser).

%% Or just choose \[`\ProcessInputWith{PScomment}'\] as <main-parser>

%% (without the {\it Wikipedia} feature).

%%

%% Alternative still to be considered: 

% \@namedef{\setup_substr_cond comment}{%

%   \PackageError{makedoc}{Job `comment' not defined}%

%   {Use \string\CopyFDconditionFromTo{comment}}}

%%

%% \subsection{Choice of package code environment}

%% With v0.3, we adopt the solution for typesetting package code

%% that was implemented in the former 'makedoc.cfg'. So we rely 

%% on the `listing' and `listingcont' environments of the 

%% 'moreverb' package. 

%% 

%% The earlier idea was that 'makedoc.sty' uses an undefined \LaTeX\ 

%% environment `packagecode' that will be defined in 'makedoc.cfg'. 

%% An accompanying idea was that 'makedoc' works before the 

%% `\documentclass' line inside a group, while 'makedoc.cfg' 

%% is read \emph{after} the `\documentclass' line. 

%%

%% We now want to simplify things. We replace 

%% \[`packagecode' \mbox{\quad by\quad } `mdPackageCode'\] 

%% and define the new environment globally here. 'moreverb'

%% and our choice for `\listinglabel' are

%% called at `\begin{document}'---outside the possible group. 

\gdef\mdPackageCode{%

  \small 

%% Get rid of 'niceverb' stuff:

  % \MakeOther\`\MakeOther\'%% probably OK with moreverb

  \MakeOther\<\MakeOther\|%

%% From the next occurrence of the environment onwards, 

%% `listing' must be replaced by `listingcont'. We must 

%% copy the previous code diligently. 

  \gdef\mdPackageCode{\small \MakeOther\<\MakeOther\|%

                      \listingcont}%

  \listing{1}}

\gdef\endmdPackageCode{%

  \endlisting

  \global\let\endmdPackageCode\endlistingcont}

\AtBeginDocument{%

  \RequirePackage{moreverb}%

  \renewcommand*{\listinglabel}[1]{%

    \llap{\scriptsize\rmfamily\the#1}\hskip\listingoffset\relax}%

}

%% |\ResetCodeLineNumbers| may be needed to \emph{reset} 

%% 'moreverb''s (global!) code line number settings 

%% (\emph{first} line number + {\it modulo} for displaying)

%% when combining documentations of \emph{more} than one package

%% with the present solution for implementing `mdPackageCode':

\newcommand*{\ResetCodeLineNumbers}{%

    \global\listing@line\@ne \gdef\listing@step{\@ne}}

%%

%% \subsection{Dealing with comments}

%% |\TreatAsComment{<text>}| writes <text> to the documentation 

%% file. If we had ``package code" (were in ``code mode") so far, 

%% the listing environment is ended first. 

\newcommand*{\TreatAsComment}[1]{%

  \ifPackageCode

    \WriteResult{\string\end{mdPackageCode\@empty}}%

%% The `\@empty' here is a lazy trick to save self-documentation 

%% fighting 'verbatim''s ``highlight" of finding ends of listings 

%% (to be improved). %% TODO 2010/03/09

%%

%% We always use `\string' to prevent macro expansion in `\write'ing 

%% in place of \LaTeX's `\protect', 

%% as long as 'fifinddo' simply uses the primitive `\write' in place 

%% of \LaTeX's `\proteced@write' ... %% todo 2009/04/08

    \PackageCodeFalse 

    \EveryComment

%     \_empty_code_lines_false

  \fi

  \WriteResult{#1}}

%% Here, |\EveryComment| is a macro hook for inserting material that should 

%% not appear in a listing environment, I had tried this %% 2010/03/18 

%% successfully: 

%% \begin{verbatim}

%%   \gdef\EveryComment{% 

%%        \global\let\EveryComment\relax

%%        \WriteResult{\string\AutoCmdVerbSyntax}}

%% \end{verbatim}

%% Initialized:

\global\let\EveryComment\relax %% should be changed globally.

%%

%% \subsection{Sectioning}

%% \label{sec:secparsers}

%% We provide a facility from 'wiki.sty' that imitates the sectioning 

%% syntax used in editing \emph{Wikipedia} pages, in a different 

%% implementation (better compatibility) and in a more general way. 

%% On Wikipedia, `== Definition ==' works similar as 

%% `\section{Definition}' does with \LaTeX. With the present 

%% implementation, you can type, e.g.,

%% \[`%%%%%%%%%%%%%%%%%%%%%% == Definition == %%%%%%%%%%%%%%%%%%%%%%'\] 

%% to get a similar result. The number of `%' characters doesn't 

%% matter, and there can be other stuff, however: additional `=' 

%% symbols may harm. Three sectioning levels are supported, through 

%% `==<text>==', `===<text>===', and `====<text>====' (deepest). 

%%

%% There are three detector macros made for programmers. 

%% The most general one is 

%% In the following definitions, there is a single tilde to prevent 

%% `=' symbols being gobbled by the test (realized by accident). 

%% %% 2009/04/13

%% \par\noindent %% 2010/03/11

%% |\SectionLevelThreeParseInput|:

\newcommand*{\SectionLevelThreeParseInput}{%

  \expandafter \test_sec_level_iii \fdInputLine ~========&}

%% |\SectionLevelTwoParseInput| 

\newcommand*{\SectionLevelTwoParseInput}{%

  \expandafter \test_sec_level_ii \fdInputLine    ~======&}

%% and |\SectionLevelOneParseInput| 

\newcommand*{\SectionLevelOneParseInput}{%

  \expandafter \test_sec_level_i \fdInputLine       ~====&}

%% allow skipping deeper levels for efficiency. 

%% % TODO in fifinddo: setup for 2 strings in 1 line 2009/04/13

%%

%% In the terminology of the 'fifinddo' documentation, the previous 

%% three commands are ``sandbox builders." The following three 

%% commands are the corresponding ``substring conditionals."

%% However, 'fifinddo' so far %% todo 2009/04/08

%% only deals with \emph{single} substrings, while here we are 

%% dealing with \emph{pairs} of substrings. We are not using 

%% general setup macros, but define the parsing macros ``manually,"

%% as it is typical in many other macros in 'latex.ltx' and other 

%% \LaTeX\ packages. You can fool our macros easily, there is 

%% no syntax check. %% todo 2009/04/08

\def\test_sec_level_iii#1====#2====#3&{%

  \IfFDempty{#2}%

            {\test_sec_level_ii #1======&}%

            {\WriteSection\mdSectionLevelThree{#2}}}

\def\test_sec_level_ii#1===#2===#3&{%

  \IfFDempty{#2}%

            {\test_sec_level_i    #1====&}%

            {\WriteSection\mdSectionLevelTwo{#2}}} 

\def\test_sec_level_i#1==#2==#3&{%

  \IfFDempty{#2}%

            {\RemoveTildeArg \ProcessStringWith{#1}{comment}}%

            {\WriteSection\mdSectionLevelOne{#2}}} 

%% `\ProcessStringWith' here passes the expanded `\fdInputLine' 

%% to the general comment detector.

%%

%% |\WriteSection{<command>}{<text>}| replaces an input line 

%% with a line \[`<command>{<text>}'\]

%% in the documentation file and switches into ``comment mode."

%% One possible space between `=' and the beginning of <text> 

%% and one possible space between the end of <text> and `=' 

%% are removed.

%% The method of dealing with surrounding blank 

%% spaces is new with v0.3, moreover we now rely on a new method in 

%% 'niceverb.sty' v0.3 to support its single right quote feature in 

%% section titles.\footnote{&\ignorespaces\ and &\unskip\ used 

%% previously do not work in PDF bookmarks.}

\newcommand*{\WriteSection}[2]{%

  \TreatAsComment{^^J#1{\trim_correct{#2}}^^J}}

%% Trimming ``other" spaces is a little more clumsy than 

%% what the 'trimspaces' package does whose code is by 

%% Morten H\o gholm. It still has inspired the following.

\begingroup \MakeOther\ %% CARE! we must not indent ...

\long\gdef\trim_correct#1{\trim_fosp$#1$ $}

\long\gdef\trim_fosp#1$ {%

\IfFDempty{#1}{\trim_losp$}{\trim_losp#1$ }}

%% So we have a string \lq`\trim_losp$<text>$ $'\rq.

\long\gdef\trim_losp$#1 ${\tidy_sp_trim#1$}

%% So we have a string \lq`\tidy_sp_trim<text>$ $'\rq 

%% or \lq`\tidy_sp_trim<text>$$'\rq.

\long\gdef\tidy_sp_trim#1$#2${\MakeDocCorrectHook{#1}}

\endgroup

%% We insert `\section' using |\mdSectionLevelOne| etc.\

%% which the programmer can redefine, e.g., when the 

%% documentation is part of a `\section' (or even deeper) 

%% according to the ``documentation driver" file. 

\newcommand*\mdSectionLevelOne  {\string\section}

\newcommand*\mdSectionLevelTwo  {\string\subsection}

\newcommand*\mdSectionLevelThree{\string\subsubsection}

%%

%% This sectioning feature is not used in (the documentation) of 

%% 'makedoc.sty'---\emph{definitions} of the parsing macros fool 

%% the same macros ...

%%

%% \subsection{Commented code}

%% |\TreatAsCode{<text>}| is the opposite to `\TreatAsComment{<text>}':

\newcommand*{\TreatAsCode}[1]{%

  \ifPackageCode

%     \_empty_code_lines_true

  \else

    \WriteResult{\string\begin{mdPackageCode}}%

    \PackageCodeTrue

  \fi

  \WriteResult{#1}%

%   \WriteResult{\maybe_result_empty_line #1}%

%   \let\maybe_result_empty_line\empty

}

%%

%% \subsection{Dealing with empty input lines} %% TODO use!? 2010/03/09 

%% \label{sec:emptylines} 

%% |\OnEmptyInputLine| is a default setting (or hook) for what to do 

%% with empty lines in the input file. The default is to insert an 

%% empty line in the output file: 

\newcommand*{\OnEmptyInputLine}{\WriteResult{}}

%% |\NoEmptyCodeLines| changes the setting to suppressing empty code 

%% lines, while in ``comment mode" an empty input line \emph{does} 

%% insert an empty line, for starting a new paragraph: 

\newcommand*{\NoEmptyCodeLines}{%% suppress empty code lines

  \renewcommand*{\OnEmptyInputLine}{%

    \ifPackageCode \else \WriteResult{}\fi}}

%% There is a better policy---didn't work so far ...

%%

%% \subsection{Bundling typical things: script commands}

%% \label{sec:script}

%% Practical experience suggested the following shorthands, 

%% combining commands from 'makedoc' and 'fifinddo'.

%%

%% \subsubsection{Output file and &\filelist\ entry}

%% |\LaTeXresultFile{<output>}| chooses <output> as name 

%% for the output file and saves you the extra line for inserting 

%% the `\ProvidesFile' line as with 'fifinddo''s 

%% `\WriteProvides'---however, it differs, actually it is 'makedoc'

%% that wants to be mentioned with `\ProvidesFile' ... 

%% %% (otherwise copied from 'fifinddo') ...

\newcommand*{\LaTeXresultFile}[1]{% 

  \ResultFile{#1}%%% \WriteProvides}

  \WriteResult{%

    \string\ProvidesFile{\result_file_name}% 

      [\the\year/\two@digits\month/\two@digits\day\space 

       automatically generated with makedoc.sty]}}%

%% \subsubsection{Choose input file and run!}

%% |\MakeDoc{<input>}| preprocesses <input> to render input for 

%% \LaTeX, considering what is typical for a \LaTeX\ package as the 

%% <input> one here:

\newcommand*{\MakeDoc}[1]{%

%% In case of a ``header" (see below) we change into ``code mode":

  \ifnum\header_lines>\z@

        \WriteResult{\string\begin{mdPackageCode}}%

        \PackageCodeTrue %% TODO both lines makedoc command!? 

                         %%      2009/04/08

  \else \PackageCodeFalse \fi

%% The loop follows. There is a placeholder `\makd_doc_line_body' 

%% that is predefined below and can be changed while processing the 

%% <input> file. 

  \ProcessFileWith{#1}{%

    \CountInputLines %% stepping line counter is standard

    \make_doc_line_body

    \process_line_message}%

%% Currently the ``VERSION HISTORY" or, more generally, 

%% a final part of the <input> file is typeset verbatim 

%% (for ``tabbing" in the version history), 

%% so we must leave ``code mode" finally:

  \ifPackageCode

    \WriteResult{\string\end{mdPackageCode\@empty}}%% self-doc-trick

    \PackageCodeFalse %% TODO both lines makedoc command!? 2009/04/08 

  \fi

%% When the <input> file has been processed, certain default settings 

%% might be restored---in case another <input> file is processed for the 

%% same documentation document: 

%   \HeaderLines{0}% 

%   \MainDocParser{\SectionLevelThreeParseInput}%% TODO!? 2009/04/08

}

%% |\MakeCloseDoc{<input>}| %% 2010/03/11

%% just is a shorthand for 

%% \[`\MakeClose{<input>}\CloseResultFile'\]

%% where `\CloseResultFile' is from 'fifinddo'.

\newcommand*{\MakeCloseDoc}[1]{\MakeDoc{#1}\CloseResultFile}

%% `\MakeDoc' and `\MakeCloseDoc' actually \emph{process} 

%% the <input> file, 

%% depending on certain \emph{parameters} some of which are set 

%% by the commands described next.

%%

%% \subsubsection{Preamble vs.\ main part of input file}

%% A \LaTeX\ package typically has a ``header" or ``preamble" 

%% (automatically inserted by 'docstrip') with very scarce information 

%% on which file it is and what it provides, and with much more Legalese. 

%% Typesetting it in \TeX\ quality may be more misleading than 

%% typesetting it \emph{verbatim}. So we typeset it \emph{verbatim}. 

%% Now: where does the ``header" end? 

%% `\NeedsTeXFormat' might be considered the border.---Yet it seems 

%% to be more simple and reliable just to act in terms of the 

%% \emph{number of lines} 

%% that the header should be long. This length <how-many-lines> is declared by 

%% |\HeaderLines{<how-many-lines>}|: 

\newcommand*{\HeaderLines}{\def\header_lines}

\HeaderLines{0}

%% So the default is that there aren't any header lines, unless 

%% another `\HeaderLines' is issued before some `\MakeDoc'.

%% The way input is parsed \emph{after} the ``header" is set by 

%% |\MainDocParser{<parsing-command>}|. 

\newcommand*{\MainDocParser}{\def\main_doc_parser}

%% `\SectionLevelThreeParseInput' from section~\ref{sec:secparsers}

%% is the default, two alternatives are defined there, another one is 

%% `\ProcessInputWith{comment}' from 'fifinddo' and 

%% %% clarified 2010/03/09 `\ref' 2010/03/10

%% section~\ref{sec:distinguish} 

%% (general dividing into code and comments). 

\MainDocParser{\SectionLevelThreeParseInput}

%% Here is how `\HeaderLines' and `\MainDocParser' act: 

\def\make_doc_line_body{%

  \IfInputLine{>\header_lines}%

              {\let\make_doc_line_body\main_doc_parser

                   \make_doc_line_body}%    %% switch to deciding

              {\TreatAsCode{\fdInputLine}}} %% header verbatim

%% \subsubsection{Screen messages}

%% |\ProcessLineMessage{<command>}| is designed to choose a screen 

%% (or log) message <command>. 

%% % A simple setting may be \[`\ProcessLineMessage{\message{.}}'\] with 

%% `\ProcessLineMessage{\message{.}}' has a result like with 'docstrip'. 

%% You just get one dot on screen per input line 

%% as a simple confirmation that 

%% the program is not hung up. %% TODO phrase!? 2009/04/08

%% However, the message may slow down a run considerably 

%% (if so, choose `\ProcessLineMessage{}' in the script). 

%% % , you really have to 

%% % wait about a second while you hardly notice the 'makedoc' run 

%% % without screen messages. Therefore, the default is \emph{not} 

%% % to issue any screen message.%% TODO more complex procedures!? 2009/04/08 

%% %---No! 

%% But it is better for beginner users of the package, 

%% so made default. %% 2009/04/09 

\newcommand*{\ProcessLineMessage}{\def\process_line_message}

% % \ProcessLineMessage{} %% no, still more efficient: 

% \let\process_line_message\relax

\ProcessLineMessage{\message{.}}

%%

%% \subsubsection{Bundling-bundling Standalones}

%% |\MakeInputJobDoc{<header-lines>}{<main-parser>}|

%% by default produces a file 

%% \[`\jobname.doc' \mbox{\quad from\quad } `\jobname.sty'\] 

%% with some standard settings.\footnote{This command is new with v0.3.}

%% 'mdoccorr.cfg' (for `.txt'$\to$\LaTeX\ functionality) is read, 

%% `\HeaderLines{<header-lines>}'

%% and `\MainDocParser{<main-parser>}' and finally 

%% `\MakeCloseDoc{\jobname.sty}{\jobname.doc}' 

%% % (with the arguments named before) 

%% are executed. 

%% Here `\jobname' expands to the file name base of the 

%% `.tex' file you are running. It is assumed that you are preparing 

%% documentation for `\jobname.tex' for your `\jobname.sty'. 

%% In order to produce `<my-job>.doc' from `<my-job>.sty' instead, 

%% \[`\renewcommand{\mdJobName}{<my-job>}'\]

%% If your input file has a different file name extension 

%% <in-ext> than \qtd{`sty'}, use an optional argument 

%% of `\MakeInputJobDoc':

%% \[|\MakeInputJobDoc[<in-ext>]{<header>}{<parser>}|\]

%% If the output file 

%% should have a different extension <out-ext> than \qtd{`doc'}, 

%% you must use \emph{two} optional arguments as follows: 

%% \[|\MakeInputJobDoc[<in-ext>][<out-ext>]{<header>}{<parser>}|\]

%% `\MakeInputJobDoc' does \emph{not} execute `\ProcessLineMessage', 

%% you can use the latter before so `\MakeInputJobDoc' respects it.

%%

%% |\MakeJobDoc| does the same as `\MakeInputJobDoc' apart from 

%% typesetting the <created> file, so the latter needs an additional 

%% `\input{<created>}'. 

%% 

%% My original idea was that all preprocessing of package files 

%% to be documented should <happen> \emph{before} 

%% `\documentclass'---loading

%% 'makedoc.sty' included---inside a group (\lq`{<happen>}'\rq---in 

%% order to avoid compatibility issues).

%% However, it now appears to me that loading 'makedoc' the usual way 

%% in the document \emph{preamble} 

%% and processing the package file (that is to be documented) 

%% within the `document' environment works well enough and 

%% will be easier to comprehend.

%%

%% This is the code for both `\MakeJobDoc' and `\MakeInputJobDoc':

\@ifdefinable{\mdJobName}{\let\mdJobName\jobname}

\newif\if_makedoc_input_

\newcommand*{\MakeInputJobDoc}{\_makedoc_input_true

                               \make_job_doc_read}

\newcommand*{\MakeJobDoc}     {\_makedoc_input_false

                               \make_job_doc_read}

\newcommand*{\make_job_doc_read}[1][sty]

            {\@testopt{\make_job_doc[#1]}{doc}}

%% Reading files as follows would fail with active 'niceverb' settings, 

%% so we issue `\noNiceVerb' if it is defined. We do it inside a group 

%% in case 'niceverb' settings are to be restored afterwards.

\def\make_job_doc[#1][#2]#3#4{%

  \begingroup

    \@ifundefined{noNiceVerb}{}%

                 {\let\MakeNormal\MakeNormalHere \noNiceVerb}%

    \input{mdoccorr.cfg}% 

    %% <- TODO warning if not found!? 

    %%         or if one from TEXMF/ used inadvertently!?

    %%         avoid reading twice!? 2010/03/11

    %% <- TODO stack danger in group!? 2010/03/13 

    %% <- TODO or read it from 'makedoc' already! 2010/03/13

    \LaTeXresultFile{\mdJobName.#2}%

    \HeaderLines{#3}%

    \MainDocParser{#4}%

    \MakeCloseDoc{\mdJobName.#1}%

%% For typesetting the file just created, some 'nicetext' features 

%% may be needed ... so restore the previous ones ...

  \endgroup

  \if_makedoc_input_\input{\mdJobName.#2}\fi

}

%% This feature may \emph{change}.

%%

%% \subsection{Leave the package}

\catcode`\_=8   %% restores underscore use for subscripts

\endinput 

%%

%% \subsection{VERSION HISTORY}



v0.1   2009/04/03   very first version, tested on morgan.sty

v0.2   2009/04/05   \OnEmptyInputLine, \NoEmptyCodeLines

                    comment -> PPScomment, \IfFDinputEmpty, 

                    \EveryComment, \PPstring may be par break 

       2009/04/08   \InputString -> \fdInputLine, 

                    \section -> \subsection; documentation!

       2009/04/08f. \MakeDoc

       2009/04/12   ``line too long'' w/o redefining \PatternCodes;

                    \MakeDocCorrectHook

       2009/04/13   tilde with sectioning 

v0.3   2010/03/08   \WriteSection 'trimspaces'-like

       2010/03/09   "fool" ("wiki" sectioning) nicer worded, 

                    more use of `...' in place of `\dots';

                    different treatment of package code environment

                    (new separate subsection); clarification on 

                    \ProcessInputWith{comment}

       2010/03/10   supplied `\ref'

       2010/03/11   \MakeCloseDoc; corrected "undifined";

                    \par\noindent in ``Sectioning"; \MakeJobDoc

       2010/03/12   &.&.&.; updated copyright

       2010/03/13   corr.: `_' not ``other"; tried to explain my 

                    earlier reasoning about `\ifPackageCode'; 

                    \MakeInputJobDoc

       2010/03/14   \make_doc_job without \niceverb_aux_cat

       2010/03/15   another remark to \ifPackageCode

       2010/03/16   use box with comment line markers; 

                    mdcorr -> mdoccorr

       2010/03/18   report on using \EveryComment

       2010/03/19   '' -> "

v0.4   2010/03/23   "Distinguishing"

       2010/03/24   "both in"

       2010/03/27   switch back to \fdPatternCodes

       2010/03/28   include `% ' commenting style 

       2010/03/29   \ResetCodeLineNumbers

       2010/03/30   use \SetPatternCodes, \ResetPatternCodes