-
Notifications
You must be signed in to change notification settings - Fork 0
/
fancyvrb.sty
1673 lines (1382 loc) · 44.8 KB
/
fancyvrb.sty
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
%% BEGIN fancyvrb.sty
%%
\def\fileversion{2.0-beta, with DG/SPQR fixes}
\def\filedate{1996/10/05}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{fancyvrb}[\filedate]
%%
%% COPYRIGHT 1992-1994, by Timothy Van Zandt, [email protected]
%%
%% DESCRIPTION:
%% fancyvrb.sty is a LaTeX style option, containing flexible
%% verbatim environments and commands and extensive documentation.
%%
%% This is a companion to fancybox.sty, which is probably available
%% from whereever you found fancyvrb.sty.
%%
%% INSTALLATION:
%% Put this file where your TeX looks for inputs.
%%
%% DOCUMENTATION:
%% See fancybox.doc, which might be appended to this file.
%%
%% COPYING:
%% Copying of part or all of this file is allowed under the following
%% conditions only:
%% (1) You may freely distribute unchanged copies of the file. Please
%% include the documentation when you do so.
%% (2) You may modify a renamed copy of the file, but only for personal
%% use or use within an organization.
%% (3) You may copy fragments from the file, for personal use or for
%% distribution, as long as credit is given where credit is due.
%%
%% You are NOT ALLOWED to take money for the distribution or use of
%% this file or modified versions or fragments thereof, except for
%% a nominal charge for copying etc.
%%
%% CODE:
\csname fancyvrb@loaded\endcsname
\let\fancyvrb@loaded\endinput
\typeout{Style option: `fancyvrb' v\fileversion \space <\filedate> (tvz)}
%% ERRORS:
\def\FV@Error#1#2{%
\edef\@tempc{#2}\expandafter\errhelp\expandafter{\@tempc}%
\errmessage{FancyVerb Error:^^J\space\space #1^^J}}
\def\FV@eha{Your command was ignored. Type <return> to continue.}
%% VERBATIM FOOTNOTES:
% Color has to be protected.
% Won't work for some definitions of \@makefntext.
% If it weren't for \@makefntext, I would do this properly by
% defining a footnote environment.
\def\VerbatimFootnotes{\let\@footnotetext\V@footnotetext}
\long\def\V@footnotetext{%
\afterassignment\V@@footnotetext
\let\@tempa}
\def\V@@footnotetext{%
\insert\footins\bgroup
\csname reset@font\endcsname
\footnotesize
\interlinepenalty\interfootnotelinepenalty
\splittopskip\footnotesep
\splitmaxdepth\dp\strutbox
\floatingpenalty \@MM
\hsize\columnwidth
\@parboxrestore
\edef\@currentlabel{\csname p@footnote\endcsname\@thefnmark}%
\@makefntext{}%
\rule{\z@}{\footnotesep}%
\bgroup
\aftergroup\V@@@footnotetext
\ignorespaces}
\def\V@@@footnotetext{\strut\egroup}
%% KEY=VALUE:
\RequirePackage{keyval}
% Extensions to keyval.sty:
% \define@booleankey{<family>}{<key>}{<iftrue>}{<iffalse>}
%
% Defines a <key> for <family> that executes:
% <iftrue> clause when value begins with `t' or `T', or is omitted.
% <iffalse> clause otherwise.
\def\define@booleankey#1#2#3#4{%
\@namedef{KV@#1@#2@default}{#3}%
\@namedef{KV@#1@#2@false}{#4}%
\@namedef{KV@#1@#2}##1{\KV@booleankey{##1}{#1}{#2}}}
\def\KV@booleankey#1#2#3{%
\edef\@tempa{#1}\expandafter\KV@@booleankey\@tempa\relax\@nil{#2}{#3}}
\def\KV@@booleankey#1#2\@nil#3#4{%
\@nameuse{KV@#3@#4@\if t#1default\else\if T#1default\else false\fi\fi}}
\def\FV@None{none}
\def\FV@Auto{auto}
\def\fvset#1{\setkeys{FV}{#1}}
% \FV@Command is for verbatim commands. Example:
%
% \def\VerbatimInput{\FV@Command{}{VerbatimInput}}
%
% \FV@Command{<key=value>}{<name>}:
%
% 1. Defines \FV@KeyValues to be <key=value>.
% 2. Looks for *, and adds `showspaces' to \FV@KeyValues if found.
% 3. Looks for [<key=value>] argument, and adds it to \FV@KeyValues if found.
% 4. Executes \FVC@<name>.
\def\FV@Command#1#2{%
\@ifstar
{\def\FV@KeyValues{#1,showspaces}\FV@@Command{#2}}%
{\def\FV@KeyValues{#1}\FV@@Command{#2}}}
\def\FV@@Command#1{%
\@ifnextchar[%
{\FV@GetKeyValues{\@nameuse{FVC@#1}}}%
{\@nameuse{FVC@#1}}}
\def\FV@GetKeyValues#1[#2]{%
\expandafter\def\expandafter\FV@KeyValues\expandafter{\FV@KeyValues,#2}#1}
\def\@CustomVerbatimCommand#1#2#3#4{%
\begingroup\fvset{#4}\endgroup % If there are errors, it easier to locate.
\def\@tempa##1##2\@nil{\def\@tempa{##2}}%
\expandafter\@tempa\string#3\@empty\@nil
\@ifundefined{FVC@\@tempa}%
{\FV@Error{Command `\string#3' is not a FancyVerb command.}\@eha}%
{#1{#2}{\FV@Command{#4}{#3}}}}
\def\CustomVerbatimCommand{\@CustomVerbatimCommand\newcommand}
\def\RecustomVerbatimCommand{\@CustomVerbatimCommand\renewcommand}
% \FV@Environment is for verbatim enviroments. Example:
%
% \def\Verbatim{\FV@Environment{}{Verbatim}}
% \@namedef{Verbatim*}{\FV@Environment{showspaces}{Verbatim}}
%
% \FV@Environment{<key=value>}{<name>}:
%
% 1. Defines \FV@KeyValues to be <key=value>.
% 2. Sets \catcode`\^^M=13, checks for `[', and resets \catcode``^^M=5.
% 3. Reads [<key=value>] and adds it to \FV@KeyValues if `[' was found.
% 4. Executes \FVB@<name>.
% \FV@Environment is like \FV@Command, except:
%
% - It omits step 2 (looking for *), and
% - It sets \catcode`\^^M=13 when checking for the `[' of the optional
% argument, so that it does not skip over ^^M if there is no `['.
\def\FV@Environment#1#2{%
\def\FV@KeyValues{#1}%
\catcode`\^^M=\active
\@ifnextchar[%
{\catcode`\^^M=5 \FV@GetKeyValues{\@nameuse{FVB@#2}}}%
{\catcode`\^^M=5 \@nameuse{FVB@#2}}}
\def\CustomVerbatimEnvironment{\@CustomVerbatimEnvironment\newenvironment}
\def\RecustomVerbatimEnvironment{\@CustomVerbatimEnvironment\renewenvironment}
\def\@CustomVerbatimEnvironment#1#2#3#4{%
\begingroup\fvset{#4}\endgroup % If there are errors, it easier to locate.
\@ifundefined{FVB@#3}%
{\FV@Error{`#3' is not a FancyVerb environment.}\@eha}%
{#1{#2}{\FV@Environment{#4}{#3}}{\@nameuse{FVE@#3}}%
#1{#2*}{\FV@Environment{#4,showspaces}{#3}}{\@nameuse{FVE@#3}}}}
\def\DefineVerbatimEnvironment#1#2#3{%
\@namedef{#1}{\FV@Environment{#3}{#2}}%
\@namedef{end#1}{\@nameuse{FVE@#2}}%
\@namedef{#1*}{\FV@Environment{#3,showspaces}{#2}}%
\@namedef{end#1*}{\@nameuse{FVE@#2}}}
% Then commands or environments set key values with \FV@UseKeyValues,
% within a group.
\def\FV@UseKeyValues{%
\ifx\FV@KeyValues\@empty\else
\def\KV@prefix{KV@FV@}%
\expandafter\KV@do\FV@KeyValues,\relax,%
\def\FV@KeyValues{}%
\fi}
%% SCANNING:
%
% Scanning macros
% - read a line at a time from an environment or a file,
% - save the line in \FV@Line, and
% - execute \FV@PreProcessLine.
%
% \FV@PreProcessLine
% - Determines whether line is in a user-specified ranges, and if so,
% - Strips the line of a user-specified no. of tokens, and
% - executes \FV@ProcessLine{<line>}.
%
% Two things are common to scanning an environment or reading a file:
% \FV@CatCodes --> Change \catcode's.
% \FV@PreProcessLine --> See above.
%% CODES:
\def\FV@CatCodes{%
\let\do\@makeother\dospecials
\FV@ActiveWhiteSpace % See below.
\FV@FontScanPrep % See below.
\FV@CatCodesHook % A style hook.
\FancyVerbCodes
} % A user-defined hook.
\def\FV@ActiveWhiteSpace{%
\catcode`\^^M=\active % End of line
\catcode`\ =\active % Space
\catcode`\^^I=\active} % Tab
% CM Ligatures:
% Left-quote: `` !` ?`
% Letter f: ff fi fl ffi ffl
% Hyphen: -- ---
\def\FV@CatCodesHook{}
\def\FV@AddToHook#1#2{%
\expandafter\def\expandafter#1\expandafter{#1#2\relax}}
\define@key{FV}{codes}[]{\def\FancyVerbCodes{#1\relax}}
\define@key{FV}{codes*}{%
\expandafter\def\expandafter\FancyVerbCodes\expandafter{%
\FancyVerbCodes#1\relax}}
\fvset{codes}
\define@key{FV}{commandchars}[\\\{\}]%
{\def\@tempa{#1}%
\ifx\@tempa\FV@None
\let\FV@CommandChars\relax
\else
\FV@DefineCommandChars#1\relax\relax\relax
\fi}
\def\FV@DefineCommandChars#1#2#3{%
\def\FV@CommandChars{%
\catcode`#1=0\relax\catcode`#2=1\relax\catcode`#3=2\relax}}
\FV@AddToHook\FV@CatCodesHook\FV@CommandChars
\define@key{FV}{commentchar}[\%]{%
\def\@tempa{#1}%
\ifx\@tempa\FV@None
\let\FV@CommentChar\relax
\else
\def\FV@CommentChar{\catcode`#1=14}%
\fi}
\FV@AddToHook\FV@CatCodesHook\FV@CommentChar
\fvset{commandchars=none,commentchar=none}
%% PREPROCESS LINE:
% These is tedious and takes up macro space, but it doesn't slow things
% down much when the parameters are not used.
% start, stop and gobble parameters:
% If value is a number, then after the assignment the next token is \relax.
\define@key{FV}{firstline}{%
\afterassignment\FV@ParseStart\@tempcnta=0#1\relax\@nil{#1}}
\def\FV@ParseStart#1\relax\@nil#2{%
\ifx\@nil#1\@nil
\edef\FancyVerbStartNum{\the\@tempcnta}%
\let\FancyVerbStartString\relax
\else
\edef\FancyVerbStartString{#2}%
\fi}
\def\KV@FV@firstline@default{%
\let\FancyVerbStartNum\z@
\let\FancyVerbStartString\relax}
\define@key{FV}{lastline}{%
\afterassignment\FV@ParseStop\@tempcnta=0#1\relax\@nil{#1}}
\def\FV@ParseStop#1\relax\@nil#2{%
\ifx\@nil#1\@nil
\edef\FancyVerbStopNum{\the\@tempcnta}%
\let\FancyVerbStopString\relax
\else
\edef\FancyVerbStopString{#2}%
\fi}
\def\KV@FV@lastline@default{%
\let\FancyVerbStopNum\z@
\let\FancyVerbStopString\relax}
\fvset{firstline,lastline}
\newcount\FV@CodeLineNo
% If \FV@FindStartStop determines the line should be printed, it
% executes \FV@@PreProcessLine
\def\FV@PreProcessLine{%
\global\advance\FV@CodeLineNo\@ne
\FV@FindStartStop}
\def\FV@@PreProcessLine{%
\FV@StepLineNo
\FV@Gobble
\expandafter\FV@ProcessLine\expandafter{\FV@Line}}
% The definition of \FV@FindStartStop changes, so that we don't
% have to check irrelevant conditions with each line.
\def\FV@FindStartStop{\FV@DefineFindStart\FV@FindStartStop}
% \def\FV@DefinePreProcessLine{%
% \setcounter{FancyVerbLine}{0}%
% \FV@DefineFindStart}
\def\FV@DefineFindStart{%
\ifx\FancyVerbStartString\relax
\ifnum\FancyVerbStartNum<\tw@
\FV@DefineFindStop
\else
\let\FV@FindStartStop\FV@FindStartNum
\fi
\else
\let\FV@FindStartStop\FV@FindStartString
\fi}
\def\FV@FindStartNum{%
\ifnum\FancyVerbStartNum>\FV@CodeLineNo\else
\FV@DefineFindStop
\expandafter\FV@@PreProcessLine
\fi}
\def\FV@FindStartString{%
\expandafter\FV@@FindStartString
{\meaning\FV@Line}%
{\meaning\FancyVerbStartString}%
}
\def\FV@@FindStartString#1#2{%
\edef\@fooA{#1}\edef\@fooB{#2}
\ifx\@fooA\@fooB
\FV@DefineFindStop
\fi
}
\def\FV@DefineFindStop{%
\ifx\FancyVerbStopString\relax
\ifnum\FancyVerbStopNum<\@ne
\let\FV@FindStartStop\FV@@PreProcessLine
\else
\let\FV@FindStartStop\FV@FindStopNum
\fi
\else
\let\FV@FindStartStop\FV@FindStopString
\fi}
\def\FV@FindStopNum{%
\ifnum\FancyVerbStopNum=\FV@CodeLineNo
\let\FV@FindStartStop\relax
\ifeof\FV@InFile\else
\immediate\closein\FV@InFile
\fi
\fi
\FV@@PreProcessLine}
\def\FV@FindStopString{%
\expandafter\FV@@FindStopString
{\meaning\FV@Line}%
{\meaning\FancyVerbStopString}%
}
\def\FV@@FindStopString#1#2{%
\edef\@fooA{#1}\edef\@fooB{#2}
\ifx\@fooA\@fooB
\let\FV@FindStartStop\relax
\ifeof\FV@InFile\else
\immediate\closein\FV@InFile
\fi
\else
\expandafter\FV@@PreProcessLine
\fi}
% Gobblings. \FV@Gobble does nothing, or strips some tokens from
% the line and stores the result in \FV@Line again. We use
% \LaTeX's renewcommand to define a command for gobbling up to
% 9 arguments. This is not the same as removing 9 tokens, but is
% easier.
\def\FV@@Gobble{%
\expandafter\expandafter\expandafter\FV@@@Gobble
\expandafter\FV@@@@Gobble\FV@Line
\@nil\@nil\@nil\@nil\@nil\@nil\@nil\@nil\@nil\@nil\@@nil}
\def\FV@@@Gobble#1\@nil#2\@@nil{\def\FV@Line{#1}}
\define@key{FV}{gobble}{%
\@tempcnta=#1\relax
\ifnum\@tempcnta<\@ne
\let\FV@Gobble\relax
\else
\ifnum\@tempcnta>9
\FV@Error{gobble parameter must be less than 10}\FV@eha
\else
\renewcommand{\FV@@@@Gobble}[\@tempcnta]{}%
\let\FV@Gobble\FV@@Gobble
\fi
\fi}
\def\FV@@@@Gobble{}
\def\KV@FV@gobble@default{\let\FV@Gobble\relax}
\fvset{gobble}
%% SCANNING ENVIRONMENTS:
\def\FV@Scan{%
\FV@CatCodes
\VerbatimEnvironment
\FV@DefineCheckEnd
\FV@BeginScanning}
% \VerbatimEnvironment:
%
% This saves the name of the current environment as
% \FV@EnvironName, if the latter is not already defined.
% Then \FV@CheckEnd knows how to find the end as long as either:
% * \begin and \end are not used within the definition of the environment, OR
% * \VerbatimEnvironment is used in the definition before the first \begin.
\def\VerbatimEnvironment{%
\ifx\FV@EnvironName\relax\xdef\FV@EnvironName{\@currenvir}\fi}
\let\FV@EnvironName\relax
%% CHECK END:
%
% We have to check the argument of the first \end{} in each line, compare it
% with \FV@EnvironName, and return \iftrue if it matches and \iffalse
% otherwise.
%
% There are four cases (R=regular):
%
% case : i ii iii iv
% catcode of \ : R 12 12 R
% catcode of {} : R R 12 12
%
% For uniformity, we use ![] instead of \{} in all the definitions.
%
% We first set the catcodes of \{} to those in effect in the
% verbatim environment. Then we define:
%
% !def!FV@CheckEnd#1[!FV@@CheckEnd#1\end{}!@nil]
%
% If {} have their usual catcodes, we define:
%
% !def!FV@@CheckEnd#1\end#2#3!@nil[!def!@tempa[#2]]
%
% If {} have catcode 12, we define:
%
% !def!FV@@CheckEnd#1\end{#2}#3!@nil[!def!@tempa[#2]]
\begingroup
\catcode`\!=0
\catcode`\[=1
\catcode`\]=2
% Case i:
!gdef!FV@CheckEnd@i#1[!FV@@CheckEnd#1\end{}!@nil]
!gdef!FV@@CheckEnd@i#1\end#2#3!@nil[!def!@tempa[#2]!def!@tempb[#3]]
!gdef!FV@@@CheckEnd@i[\end{}]
% Case ii:
\catcode`!\=12
!gdef!FV@CheckEnd@ii#1[!FV@@CheckEnd#1\end{}!@nil]
!gdef!FV@@CheckEnd@ii#1\end#2#3!@nil[!def!@tempa[#2]!def!@tempb[#3]]
!gdef!FV@@@CheckEnd@ii[\end{}]
% Case iii:
!catcode`!{=12
!catcode`!}=12
!gdef!FV@CheckEnd@iii#1[!FV@@CheckEnd#1\end{}!@nil]
!gdef!FV@@CheckEnd@iii#1\end{#2}#3!@nil[!def!@tempa[#2]!def!@tempb[#3]]
!gdef!FV@@@CheckEnd@iii[\end{}]
% Case iv:
!catcode`!\=0
!gdef!FV@CheckEnd@iv#1[!FV@@CheckEnd#1\end{}!@nil]
!gdef!FV@@CheckEnd@iv#1\end{#2}#3!@nil[!def!@tempa[#2]!def!@tempb[#3]]
!gdef!FV@@@CheckEnd@iv[\end{}]
\endgroup
\def\FV@BadCodes#1{%
\FV@Error
{\string\catcode\space of \expandafter\@gobble\string#1 is wrong:
\the\catcode`#1}%
{Only the following catcode values are allowed:
^^J\@spaces \expandafter\@gobble\string\\ \space\space --> 0 or 12.
^^J\@spaces \string{ \string} --> 1 and 2, resp., or both 12.
^^JTo get this error, either you are a hacker or you got bad advice.}%
\def\FV@CheckEnd##1{\iftrue}}
\def\FV@DefineCheckEnd{%
\ifnum\catcode`\\=\z@
\ifnum\catcode`\{=\@ne
\let\FV@CheckEnd\FV@CheckEnd@i
\let\FV@@CheckEnd\FV@@CheckEnd@i
\let\FV@@@CheckEnd\FV@@@CheckEnd@i
\else
\ifnum\catcode`\{=12
\let\FV@CheckEnd\FV@CheckEnd@iv
\let\FV@@CheckEnd\FV@@CheckEnd@iv
\let\FV@@@CheckEnd\FV@@@CheckEnd@iv
\else
\FV@BadCodes\{%
\fi
\fi
\else
\ifnum\catcode`\\=12
\ifnum\catcode`\{=\@ne
\let\FV@CheckEnd\FV@CheckEnd@ii
\let\FV@@CheckEnd\FV@@CheckEnd@ii
\let\FV@@@CheckEnd\FV@@@CheckEnd@ii
\else
\ifnum\catcode`\{=12
\let\FV@CheckEnd\FV@CheckEnd@iii
\let\FV@@CheckEnd\FV@@CheckEnd@iii
\let\FV@@@CheckEnd\FV@@@CheckEnd@iii
\else
\FV@BadCodes\{%
\fi
\fi
\else
\FV@BadCodes\\%
\fi
\fi}
%% LINE-BY-LINE SCANNING
% We first skip everything after the beginning of the environment.
\begingroup
\catcode`\^^M=\active
\gdef\FV@BeginScanning#1^^M{%
\def\@tempa{#1}\ifx\@tempa\@empty\else\FV@BadBeginError\fi
\FV@GetLine}%
\endgroup
\def\FV@BadBeginError#1{%
\expandafter\@temptokena\expandafter{\@tempa}%
\FV@Error
{Extraneous input `\the\@temptokena' between
\string\begin{\FV@EnvironName}[<key=value>] and line end}%
{This input will be discarded. Hit <return> to continue.}}
% If \FancyVerbGetLine does not find a ^^M, then we are at
% the end of the file, and \FV@EOF attempts to terminate the document.
% Otherwise, \FV@EOF is gobbled by \FancyVerbGetLine.
\def\FV@GetLine{\expandafter\FV@CheckScan\FancyVerbGetLine}
\begingroup
\catcode`\^^M=\active
\gdef\FancyVerbGetLine#1^^M{%
\@nil
\FV@CheckEnd{#1}%
\ifx\@tempa\FV@EnvironName% % True if end is found
\ifx\@tempb\FV@@@CheckEnd\else\FV@BadEndError\fi%
\let\next\FV@EndScanning%
\else%
\def\FV@Line{#1}%
\def\next{\FV@PreProcessLine\FV@GetLine}%
\fi%
\next}%
\endgroup
\def\FV@BadEndError{%
\expandafter\@temptokena\expandafter{\@tempb}%
\FV@Error
{Extraneous input `\the\@temptokena' between
\string\end{\FV@EnvironName} and line end}%
{This input will be discarded. Type <return> to continue.}}
\def\FV@EndScanning{%
\edef\next{\noexpand\end{\FV@EnvironName}}%
\global\let\FV@EnvironName\relax
\next}
\@ifundefined{@currenvline}{\let\@currenvline\@empty}{}
\def\FV@CheckScan#1{\@ifnextchar\@nil{\@gobble}{\FV@EOF}}
\def\FV@CheckScan#1{\ifx\@nil#1\@empty\else\expandafter\FV@EOF\fi}
\def\FV@EOF{%
\FV@Error{Couldn't find `\string\end{\FV@EnvironName}' to end
a verbatim environment\@currenvline.}%
{Probably you mistyped the environment name or included an extraneous
^^Jspace, or are using an improperly defined verbatim environment.
^^JHit return and I will try to terminate this job.}%
\FV@EndScanning
\end{document}}
%% INPUT:
\newread\FV@InFile
\def\FV@Input#1{%
\immediate\openin\FV@InFile #1\relax
\ifeof\FV@InFile
\FV@Error{No verbatim file #1}\FV@eha
\immediate\closein\FV@InFile
\else
\FV@CatCodes
\expandafter\FV@@Input
\fi}
% TeX reports EOF when reading after the last newline character.
% Thus, we read to InLine, and if TeX reports EOF:
% If InLine=Empty, previous line was last line in file (file ends nl).
% Otherwise, InLine holds last line in file (file doesn't end in nl).
% \FV@@Input handles both cases correctly.
\def\FV@@Input{%
\def\FV@Line{}%
\FV@ReadLine
\ifeof\FV@InFile
\ifx\FV@Line\@empty\else
\FV@PreProcessLine
\fi
\immediate\closein\FV@InFile
\else
\FV@PreProcessLine
\expandafter\FV@@Input
\fi}
% We also want to handle true comment characters correctly. This means that
% we keep accumulating text in InLine until we find a ^^M (indicating that
% the line did not contain a comment character).
\begingroup
\catcode`\^^M=\active
\gdef\FV@ReadLine{%
\ifeof\FV@InFile\else
\immediate\read\FV@InFile to\@tempa%
\expandafter\FV@@ReadLine\@tempa^^M\relax^^M\@nil%
\fi}
% #2 is empty if line ends in ^^M, #2=\relax otherwise
\gdef\FV@@ReadLine#1^^M#2^^M#3\@nil{%
\expandafter\def\expandafter\FV@Line\expandafter{%
\FV@Line#1}%
\ifx\relax#2\@empty\expandafter\FV@ReadLine\fi}%
\endgroup
%% FORMATTING - COMMON COMPONENTS:
% Some things that are common to all verbatim formatting:
\def\FV@FormattingPrep{%
\global\FV@CodeLineNo\z@
\frenchspacing % Cancels special punctuation spacing.
\FV@SetupFont % See below.
\FV@DefineWhiteSpace % See below.
\FancyVerbDefineActive
\FancyVerbFormatCom} % A user-defined hook (formatcom parameter).
% Fonts
\expandafter\ifx\csname selectfont\endcsname\relax
\def\FV@SetupFont{%
\FV@BaseLineStretch
\ifx\@currsize\small\normalsize\else\small\fi\@currsize
\FV@FontSize
\FV@FontFamily
}
\else
\def\FV@SetupFont{%
\FV@BaseLineStretch
\FV@FontSize
\FV@FontFamily
\FV@FontSeries
\FV@FontShape
%
% SPQR Jan 29 1996; added code to turn off ligatures
%
\selectfont\let\do\do@noligs\verbatim@nolig@list}
\fi
\define@key{FV}{fontsize}{%
\def\@tempa{#1}%
\ifx\@tempa\FV@Auto
\let\FV@FontSize\relax
\else
\def\FV@FontSize{#1}%
\fi}
\def\KV@FV@fontsize@default{\let\FV@FontSize\relax}
\define@key{FV}{baselinestretch}[auto]{%
\def\@tempa{#1}%
\ifx\@tempa\FV@Auto
\let\FV@BaseLineStretch\relax
\else
\def\FV@BaseLineStretch{\def\baselinestretch{#1}}%
\fi}
\def\KV@FV@baselinestretch@default{\let\FV@BaseLineStretch\relax}
\define@key{FV}{fontfamily}{%
\@ifundefined{FV@fontfamily@#1}%
{\def\FV@FontScanPrep{}\def\FV@FontFamily{\fontfamily{#1}}}
{\csname FV@fontfamily@#1\endcsname}}
\define@key{FV}{fontseries}{%
\def\@tempa{#1}%
\ifx\@tempa\FV@Auto
\let\FV@FontSeries\relax
\else
\def\FV@FontSeries{\fontseries{#1}}%
\fi}
\define@key{FV}{fontshape}{%
\def\@tempa{#1}%
\ifx\@tempa\FV@Auto
\let\FV@FontShape\relax
\else
\def\FV@FontShape{\fontshape{#1}}%
\fi}
% Font family styles have to define \FV@FontScanPrep and \FV@FontFamily.
\def\FV@MakeActive#1{%
\catcode`#1=\active
\def\next##1{\expandafter\def\expandafter\FV@MakeUnActive\expandafter{%
\FV@MakeUnActive\def##1{\string##1}}}%
\begingroup\lccode`~=`#1\relax\expandafter\next\expandafter~\endgroup}
\def\FV@MakeUnActive{}
\begingroup
\catcode`\`=\active
\gdef\FV@fontfamily@tt{%
\def\FV@FontScanPrep{\FV@MakeActive\`}%
\def\FV@FontFamily{\ttfamily\edef`{{\string`}}}}
\gdef\FV@fontfamily@cmtt{%
\def\FV@FontScanPrep{\FV@MakeActive\`}%
\def\FV@FontFamily{\edef`{{\string`}}\fontfamily{cmtt}}}
\endgroup
\@namedef{FV@fontfamily@cmtt-spanish}{%
\def\FV@FontScanPrep{}%
\def\FV@FontFamily{\fontfamily{cmtt}}}
%% FIX ME
\@namedef{FV@fontfamily@courier}{%
\def\FV@FontScanPrep{}%
\def\FV@FontFamily{\fontfamily{pcr}}}
\@namedef{FV@fontfamily@helvetica}{%
\def\FV@FontScanPrep{}%
\def\FV@FontFamily{\fontfamily{phv}}}
\fvset{fontfamily=tt,fontsize=auto,fontshape=auto,fontseries=auto,
baselinestretch=auto}
% \FV@DefineWhiteSpace
%
% We just define the active characters to be ordinary commands, which
% are easier to redefine. We do with any macros that use verbatim text.
\begingroup
\catcode`\ =\active
\catcode`\^^I=\active
\gdef\FV@DefineWhiteSpace{\def {\FV@Space}\def^^I{\FV@Tab}}%
\endgroup
\define@key{FV}{defineactive}[]{\def\FancyVerbDefineActive{#1\relax}}
\define@key{FV}{defineactive*}{%
\expandafter\def\expandafter\FancyVerbDefineActive\expandafter{%
\FancyVerbDefineActive#1\relax}}
\fvset{defineactive}
% \FV@Space:
\define@booleankey{FV}{showspaces}%
{\def\FV@Space{{\FancyVerbSpace}}}%
{\def\FV@Space{\ }}
{\catcode`\ =12 \gdef\FancyVerbSpace{\tt }}
\fvset{showspaces=false}
% \FV@Tab:
\def\FV@Tab{\hbox to\FancyVerbTabSize\fontdimen2\font{\hss\FV@TabChar}}
\define@key{FV}{tabsize}{%
\@tempcnta=#1\relax
\ifnum\@tempcnta>100
\FV@Error{Tab size too large: `\the\@tempcnta'. (Max size = 100)}\FV@eha
\else
\edef\FancyVerbTabSize{\the\@tempcnta}%
\fi}
\define@booleankey{FV}{showtabs}%
{\def\FV@TabChar{\FancyVerbTab}}%
{\let\FV@TabChar\relax}
\fvset{tabsize=8,showtabs=false}
% Here is a weak attempt at a tab character. It may exceed the width
% of a space character when the verbatim font is small. The only proper way
% to do this is making it part of the verbatim font.
\def\FancyVerbTab{%
\valign{%
\vfil##\vfil\cr
\hbox{$\scriptscriptstyle-$}\cr
\hbox to 0pt{\hss$\scriptscriptstyle\rangle\mskip -.8mu$}\cr
\hbox{$\scriptstyle\mskip -3mu\mid\mskip -1.4mu$}\cr}}
% Obey Tabs:
\newbox\FV@TabBox
\def\FV@@ObeyTabsInit{%
\@tempdimb=\FancyVerbTabSize\fontdimen\tw@\font
\edef\FV@ObeyTabSize{\number\@tempdimb}%
\advance\@tempdimb\fontdimen\tw@\font
\advance\@tempdimb-\FancyVerbTabSize sp % Allow for rounding errors.
\edef\FV@@ObeyTabSize{\number\@tempdimb}%
\let\FV@ObeyTabs\FV@@ObeyTabs
\let\FV@Tab\FV@TrueTab}
\def\FV@@ObeyTabs#1{\setbox\FV@TabBox=\hbox{#1}\box\FV@TabBox}
\let\FV@ObeyTabs\relax
\def\FV@TrueTab{%
\egroup
\@tempdima=\FV@ObeyTabSize sp\relax
\@tempcnta=\wd\FV@TabBox
\advance\@tempcnta\FV@@ObeyTabSize\relax
\divide\@tempcnta\@tempdima
\multiply\@tempdima\@tempcnta
\advance\@tempdima-\wd\FV@TabBox
\setbox\FV@TabBox=\hbox\bgroup
\unhbox\FV@TabBox\kern\@tempdima\hbox to\z@{\hss\FV@TabChar}}
\define@booleankey{FV}{obeytabs}%
{\let\FV@ObeyTabsInit\FV@@ObeyTabsInit}%
{\let\FV@ObeyTabsInit\relax}
\fvset{obeytabs=false}
% \FancyVerbFormatCom
\define@key{FV}{formatcom}[]{\def\FancyVerbFormatCom{#1\relax}}
\define@key{FV}{formatcom*}{%
\expandafter\def\expandafter\FancyVerbFormatCom\expandafter{%
\FancyVerbFormatCom#1\relax}}
\fvset{formatcom}
\def\FancyVerbFormatLine#1{\FV@ObeyTabs{#1}}
% LIST ENVIRONMENTS:
% Some parameters:
\define@key{FV}{xleftmargin}{\def\FV@XLeftMargin{#1}}
\let\FV@XLeftMargin\z@
\define@key{FV}{xrightmargin}{\def\FV@XRightMargin{#1}}
\let\FV@XRightMargin\z@
\define@booleankey{FV}{resetmargins}%
{\let\if@FV@ResetMargins\iftrue}
{\let\if@FV@ResetMargins\iffalse}
\fvset{resetmargins=false}
\define@key{FV}{listparameters}{\def\FV@ListParameterHook{#1}}
\def\FV@ListParameterHook{}
\define@key{FV}{hfuzz}{%
\@tempdima=#1\relax
\edef\FancyVerbHFuzz{\number\@tempdima sp}}
\fvset{hfuzz=2pt}
\define@booleankey{FV}{samepage}%
{\def\FV@InterLinePenalty{\interlinepenalty\@M}}%
{\let\FV@InterLinePenalty\relax}
\fvset{samepage=false}
% Lists:
% \FV@List{} is a rewriting of \list{}{}\item[].
% The rewrite gives me more control.
% I might not get the vertical spacing exactly the same, but it
% is more likely that it will get better than worse.
%
% The verbatim environment consists of a series of \hbox's inserted in
% vertical mode.
%
% We need to take care of the following:
%
% leftmargin
% rightmargin
% topskip
% botskip
% toppenalty
% botpenalty
% interlinepenalties
%
% Note: A verbatim environment immediately after an \item starts on
% the same line as the \item's label, unless we reset margins.
% The user can instead have the environment start on a new
% line by inserting `\ ' between \item and the environment.
\def\FV@List#1{%
\begingroup
\FV@UseKeyValues
\FV@LeaveVMode
\if@inlabel\else\setbox\@labels=\box\voidb@x\fi
\FV@ListNesting{#1}%
\FV@ListParameterHook
\FV@ListVSpace
\FV@SetLineWidth
\FV@InterLinePenalty
\let\FV@ProcessLine\FV@ListProcessLine@i
\FV@CatCodes
\FV@FormattingPrep
\FV@ObeyTabsInit
\FV@BeginListFrame}
% Cases where we need to leave vmode:
% - After an in-line section (\if@noskipsec=T).
% - After an \item command, if we reset margins.
% Then we end \vmode, using @noparlist as a flag if in vmode.
% (Not the usual meaning of @noparlist.)
\def\FV@LeaveVMode{%
\if@noskipsec
\leavevmode
\else
\if@FV@ResetMargins\if@inlabel\leavevmode\fi\fi
\fi
\ifvmode\@noparlisttrue\else\@noparlistfalse\unskip\par\fi}
\def\FV@ListNesting#1{%
\if@FV@ResetMargins
\@listdepth=\z@
\else
\ifnum\@listdepth>5\relax
\@toodeep
\else
\advance\@listdepth\@ne
\fi
\fi
\rightmargin\z@
\csname @list\romannumeral\the\@listdepth\endcsname
\ifnum#1=\z@
\rightmargin\z@
\leftmargin\z@
\fi}
% \FV@ListVSpace contains selected parts of \@trivlist and \@item.
% Here are the cases:
%
% VMODE NOT IN LABEL OR AFTER @NOBREAK:
% <topskip> = \topsep + \partopsep + \parskip
% <botskip> = \topsep + \partopsep
% <toppenalty> = \@beginparpenalty
% <botpenalty> = \@endparpenalty
% VMODE IN LABEL:
% <topskip> = \parskip % Expected anyway.
% <botskip> = \topsep + \partopsep % Omitted in LaTeX--a bug?
% <toppenalty> = None
% <botpenalty> = \@endparpenalty % Ditto.
% VMODE AFTER @NOBREAK:
% <topskip> = \parskip