• Tidak ada hasil yang ditemukan

The standard table

Dalam dokumen The Listings Package (Halaman 118-122)

15.3 Character tables

15.3.1 The standard table

\lst@ProcessFormFeed Here we execute some macros according to whether a new line has already begun or not. No \lst@EOLUpdate is used in the else branch anymore—Kalle Tuulos sent the bug report.

971\def\lst@ProcessFormFeed{%

972 \lst@XPrintToken

973 \ifnum\lst@newlines=\z@

974 \lst@EOLUpdate \lsthk@InitVarsBOL

975 \fi

976 \lst@formfeed

977 \lst@whitespacetrue}

Other than in \lst@CCPutMacro the \lccode settings weren’t local and caused the error.

985\def\lst@CCPut#1#2{%

986 \ifnum#2=\z@

987 \expandafter\@gobbletwo

988 \else

989 \begingroup\lccode‘\~=#2\lccode‘\/=#2\lowercase{\endgroup\lst@CCPut@~{#1/}}%

990 \fi

991 \lst@CCPut#1}

992\def\lst@CCPut@#1#2{\lst@lAddTo\lst@SelectStdCharTable{\def#1{#2}}}

Now we insert more standard characters.

993\lst@CCPut \lst@ProcessOther

994 {"21}{"22}{"28}{"29}{"2B}{"2C}{"2E}{"2F}

995 {"3A}{"3B}{"3D}{"3F}{"5B}{"5D}

996 \z@

997\lst@CCPut \lst@ProcessDigit

998 {"30}{"31}{"32}{"33}{"34}{"35}{"36}{"37}{"38}{"39}

999 \z@

1000\lst@CCPut \lst@ProcessLetter

1001 {"40}{"41}{"42}{"43}{"44}{"45}{"46}{"47}

1002 {"48}{"49}{"4A}{"4B}{"4C}{"4D}{"4E}{"4F}

1003 {"50}{"51}{"52}{"53}{"54}{"55}{"56}{"57}

1004 {"58}{"59}{"5A}

1005 {"61}{"62}{"63}{"64}{"65}{"66}{"67}

1006 {"68}{"69}{"6A}{"6B}{"6C}{"6D}{"6E}{"6F}

1007 {"70}{"71}{"72}{"73}{"74}{"75}{"76}{"77}

1008 {"78}{"79}{"7A}

1009 \z@

\lst@CCPutMacro Now we come to a delicate point. The characters not inserted yet aren’t printable (_,$, . . . ) or aren’t printed well (*,-, . . . ) if we enter these characters. Thus we use proper macros to print the characters. Works perfectly. The problem is that the current character string is printable for speed, for example_is already replaced by a macro version, but the new keyword tests need the original characters.

The solution: We define \def _{\lst@ProcessLetter\lst@um_} where the first underscore is active and the second belongs to the control sequence. Moreover we have \def\lst@um_{\lst@UM _} where the second underscore has the usual meaning. Now the keyword tests can access the original character simply by making\lst@UMempty. The default definition gets the following token and builds the control sequence\lst@um_@, which we’ll define to print the character. Easy, isn’t it?

The following definition does all this for us. The first parameter gives the character class, the second the character code, and the last the definition which actually prints the character. We build the names \lst@um_and\lst@um_@and give them to a submacro.

1010\def\lst@CCPutMacro#1#2#3{%

1011 \ifnum#2=\z@ \else

1012 \begingroup\lccode‘\~=#2\relax \lccode‘\/=#2\relax

1013 \lowercase{\endgroup\expandafter\lst@CCPutMacro@

1014 \csname\@lst @um/\expandafter\endcsname

1015 \csname\@lst @um/@\endcsname /~}#1{#3}%

1016 \expandafter\lst@CCPutMacro

1017 \fi}

The arguments are now\lst@um_,\lst@um_@, nonactive character, active charac- ter, character class and printing definition. We add\def _{ \lst@ProcessLetter

\lst@um_}to\lst@SelectStdCharTable(and similarly other special characters), define\def\lst@um_{\lst@UM _} and\lst@um_@.

1018\def\lst@CCPutMacro@#1#2#3#4#5#6{%

1019 \lst@lAddTo\lst@SelectStdCharTable{\def#4{#5#1}}%

1020 \def#1{\lst@UM#3}%

1021 \def#2{#6}}

The default definition of\lst@UM:

1022\def\lst@UM#1{\csname\@lst @um#1@\endcsname}

And all remaining standard characters.

1023\lst@CCPutMacro

1024 \lst@ProcessOther {"23}\#

1025 \lst@ProcessLetter{"24}\textdollar

1026 \lst@ProcessOther {"25}\%

1027 \lst@ProcessOther {"26}\&

1028 \lst@ProcessOther {"27}{\lst@ifupquote \textquotesingle

1029 \else \char39\relax \fi}

1030 \lst@ProcessOther {"2A}{\lst@ttfamily*\textasteriskcentered}

Ulrike Fischer pointed out the incompatibility betweenflexisymandlistings: flex- isym changes the math code while listings changes the meaning. So the minus character vanishes. Replacing the original$-$by\textminusshould remedy the problem.

1031 \lst@ProcessOther {"2D}{\lst@ttfamily{-{}}{\textminus}}

1032 \lst@ProcessOther {"3C}{\lst@ttfamily<\textless}

1033 \lst@ProcessOther {"3E}{\lst@ttfamily>\textgreater}

1034 \lst@ProcessOther {"5C}{\lst@ttfamily{\char92}\textbackslash}

1035 \lst@ProcessOther {"5E}\textasciicircum

1036 \lst@ProcessLetter{"5F}{\lst@ttfamily{\char95}\textunderscore}

1037 \lst@ProcessOther {"60}{\lst@ifupquote \textasciigrave

1038 \else \char96\relax \fi}

1039 \lst@ProcessOther {"7B}{\lst@ttfamily{\char123}\textbraceleft}

1040 \lst@ProcessOther {"7C}{\lst@ttfamily|\textbar}

1041 \lst@ProcessOther {"7D}{\lst@ttfamily{\char125}\textbraceright}

1042 \lst@ProcessOther {"7E}\textasciitilde

1043 \lst@ProcessOther {"7F}-

1044 \@empty\z@\@empty

\lst@ttfamily What is this ominous macro? It prints either the first or the second argument.

In\ttfamily it ensures that---- is typeset---- and not −−−− as in version 0.17. Bug encountered by Dr. Jobst Hoffmann. Furthermore I added\relaxafter receiving an error report from Magnus Lewis-Smith

1045\def\lst@ttfamily#1#2{\ifx\f@family\ttdefault#1\relax\else#2\fi}

\ttdefault is defined \long, so the \ifx doesn’t work since \f@family isn’t

\long! We go around this problem by redefining\ttdefault locally:

1046\lst@AddToHook{Init}{\edef\ttdefault{\ttdefault}}

upquote is used above to decide which quote to print. We print an error message if the necessary textcomp commands are not available. This key has been added after an email from Frank Mittelbach.

1047\lst@Key{upquote}{false}[t]{\lstKV@SetIf{#1}\lst@ifupquote

1048 \lst@ifupquote

1049 \@ifundefined{textasciigrave}%

1050 {\let\KV@lst@upquote\@gobble

1051 \lstKV@SetIf f\lst@ifupquote \@gobble\fi

1052 \PackageError{Listings}{Option ‘upquote’ requires ‘textcomp’

1053 package.\MessageBreak The option has been disabled}%

1054 {Add \string\usepackage{textcomp} to your preamble.}}%

1055 {}%

1056 \fi}

If anupquotepackage is loaded, theupquoteoption is enabled by default.

1057\AtBeginDocument{%

1058 \@ifpackageloaded{upquote}{\RequirePackage{textcomp}%

1059 \lstset{upquote}}{}%

1060 \@ifpackageloaded{upquote2}{\lstset{upquote}}{}}

\lst@ifactivechars A simple switch.

1061\def\lst@activecharstrue{\let\lst@ifactivechars\iftrue}

1062\def\lst@activecharsfalse{\let\lst@ifactivechars\iffalse}

1063\lst@activecharstrue

\lst@SelectCharTable We select the standard character table and switch to active catcodes.

1064\def\lst@SelectCharTable{%

1065 \lst@SelectStdCharTable

1066 \lst@ifactivechars

1067 \catcode9\active \catcode12\active \catcode13\active

1068 \@tempcnta=32\relax

1069 \@whilenum\@tempcnta<128\do

1070 {\catcode\@tempcnta\active\advance\@tempcnta\@ne}%

1071 \fi

1072 \lst@ifec \lst@DefEC \fi

The following line and the according macros below have been added after a bug report from Fr´ed´eric Boulanger. The assignment to \do@noligs was changed to

\doafter a bug report from Peter Ruckdeschel. This bugfix was kindly provided by Timothy Van Zandt.

1073 \let\do\lst@do@noligs \verbatim@nolig@list

There are two ways to adjust the standard table: inside the hook or with

\lst@DeveloperSCT. We use these macros and initialize the backslash if neces- sary. \lst@DefRange has been moved outside the hook after a bug report by Michael Bachmann.

1074 \lsthk@SelectCharTable

1075 \lst@DeveloperSCT

1076 \lst@DefRange

1077 \ifx\lst@Backslash\relax\else

1078 \lst@LetSaveDef{"5C}\lsts@backslash\lst@Backslash

1079 \fi}

SelectCharTable MoreSelectCharTable

The keys to adjust\lst@DeveloperSCT.

1080\lst@Key{SelectCharTable}{}{\def\lst@DeveloperSCT{#1}}

1081\lst@Key{MoreSelectCharTable}\relax{\lst@lAddTo\lst@DeveloperSCT{#1}}

1082\lst@AddToHook{SetLanguage}{\let\lst@DeveloperSCT\@empty}

\lst@do@noligs To prevent ligatures, this macro inserts the token \lst@NoLig in front of

\lst@Processhwhateverihspec. tokeni. This is done by \verbatim@nolig@list for certain characters. Note that the submacro is a special kind of a local

\lst@AddToAtTop. The submacro definition was fixed thanks to Peter Bartke.

1083\def\lst@do@noligs#1{%

1084 \begingroup \lccode‘\~=‘#1\lowercase{\endgroup

1085 \lst@do@noligs@~}}

1086\def\lst@do@noligs@#1{%

1087 \expandafter\expandafter\expandafter\def

1088 \expandafter\expandafter\expandafter#1%

1089 \expandafter\expandafter\expandafter{\expandafter\lst@NoLig#1}}

\lst@NoLig When this extra macro is processed, it adds \lst@nolig to the output queue without increasing its length. For keyword detection this must expand to nothing if\lst@UMis empty.

1090\def\lst@NoLig{\advance\lst@length\m@ne \lst@Append\lst@nolig}

1091\def\lst@nolig{\lst@UM\@empty}%

But the usual meaning of \lst@UM builds the following control sequence, which prevents ligatures in the manner of LATEX’s\do@noligs.

1092\@namedef{\@lst @um@}{\leavevmode\kern\z@}

\lst@SaveOutputDef To get thehspec. tokenimeaning of character#1, we look for\def‘active character

#1’ in\lst@SelectStdCharTable, get the replacement text, strip off the charac- ter class via \@gobble, and assign the meaning. Note that you get a “runaway argument” error if an illegalhcharacter codei=#1is used.

1093\def\lst@SaveOutputDef#1#2{%

1094 \begingroup \lccode‘\~=#1\relax \lowercase{\endgroup

1095 \def\lst@temp##1\def~##2##3\relax}{%

1096 \global\expandafter\let\expandafter#2\@gobble##2\relax}%

1097 \expandafter\lst@temp\lst@SelectStdCharTable\relax}

\lstum@backslash A commonly used character.

1098\lst@SaveOutputDef{"5C}\lstum@backslash

Dalam dokumen The Listings Package (Halaman 118-122)