OSDN Git Service

Fix \ltj@@IsFontJapaneseX; the oid definition doesn't work with listings.sty.
[luatex-ja/luatexja.git] / src / patches / lltjp-listings.sty
1 %
2 % lltjp-listings.sty
3 %
4 % Modified from jlisting.sty (by Thor) for LuaTeX-ja. 
5 %
6
7 \NeedsTeXFormat{LaTeX2e}
8 \def\filedate{2012/01/11}
9 \def\fileversion{0.4}
10 \ProvidesPackage{lltjp-listings}[\filedate\space\fileversion]
11 \RequirePackage{listings}
12 \newcount\lst@nextchar
13 \let\lst@@ProcessSpace\lst@ProcessSpace
14 \def\lst@ProcessSpace#1{%
15    \lst@check@chartype{#1}%
16       \lst@@ProcessSpace
17       \lst@whitespacetrue}
18 \let\lst@@ProcessLetter\lst@ProcessLetter
19 \def\lst@ProcessLetter#1#2{%
20    \lst@check@chartype{#2}%
21       {\lst@@ProcessLetter{#1}}%
22       \relax}
23 \let\lst@@ProcessDigit\lst@ProcessDigit
24 \def\lst@ProcessDigit#1#2{%
25    \lst@check@chartype{#2}%
26       {\lst@@ProcessDigit{#1}}%
27       \relax}
28 \let\lst@@ProcessOther\lst@ProcessOther
29 \def\lst@ProcessOther#1#2{%
30    \lst@check@chartype{#2}%
31       {\lst@@ProcessOther{#1}}%
32       \relax}
33 \let\lst@@ProcessTabulator\lst@ProcessTabulator
34 \def\lst@ProcessTabulator#1{%
35    \lst@check@chartype{#1}%
36       \lst@@ProcessTabulator
37       \relax}
38 \def\lst@check@chartype#1#2#3{%
39    \edef\@tempa{\lst@nextchar=`\string#1\relax}%
40    \afterassignment\remove@to@nnil
41    \@tempa\@nnil
42    #2%
43    \ifnum\lst@nextchar<\@cclvi
44       #3%
45    \else
46       \lst@ifletter \else \lst@OutputOther \fi
47       \lst@whitespacefalse
48       \expandafter\lst@AppendJchar
49    \fi
50    #1}
51 \def\lst@Append#1{\advance\lst@length\@ne%
52                   \lst@token=\expandafter{\the\lst@token#1}}
53 \def\lst@AppendJchar#1#2{%
54    \lst@check@chartype{#2}%
55       {\advance\lst@length\@ne\lst@Append{#1}}%
56       \relax}
57 \def\lst@check@chartype@BOL#1{%
58    \edef\@tempa{\lst@nextchar=`\string#1\relax}%
59    \afterassignment\remove@to@nnil
60    \@tempa\@nnil
61    \ifnum\lst@nextchar<\@cclvi\else
62       \lst@whitespacefalse
63       \expandafter\lst@AppendJchar
64    \fi
65    #1}
66 \def\lst@InputListing#1{%
67    \begingroup
68       \lsthk@PreSet \gdef\lst@intname{#1}%
69       \expandafter\lstset\expandafter{\lst@set}%
70       \lsthk@DisplayStyle
71       \catcode\active=\active
72       \lst@Init\relax \let\lst@gobble\z@
73       \lst@SkipToFirst
74       \lst@ifprint \def\lst@next{\lst@get@filecontents{#1}}%
75       \else        \let\lst@next\@empty
76       \fi
77       \lst@next
78       \lst@DeInit
79    \endgroup}
80 \newread\lst@inputfile
81 \def\lst@get@filecontents#1{%
82    \let\lst@filecontents\@empty
83    \openin\lst@inputfile=#1\relax
84    \let\@lst@get@filecontents@prevline\relax
85    \lst@get@filecontents@loop
86    \closein\lst@inputfile
87    \lst@filecontents\empty}
88 \def\lst@get@filecontents@loop{%
89    \read\lst@inputfile to\@lst@get@filecontents@currline
90    \ifx\@lst@get@filecontents@prevline\relax\else
91       \expandafter\expandafter\expandafter\def
92       \expandafter\expandafter\expandafter\lst@filecontents
93       \expandafter\expandafter\expandafter{%
94          \expandafter\lst@filecontents\@lst@get@filecontents@prevline}%
95    \fi
96    \let\@lst@get@filecontents@prevline\@lst@get@filecontents@currline
97    \ifeof\lst@inputfile\else
98       \expandafter\lst@get@filecontents@loop
99    \fi}
100 %%% [この処理も,相当強引です.]
101 \def\lst@BOLGobble{%
102    \ifnum\lst@gobble>\z@
103       \@tempcnta\lst@gobble\relax
104       \expandafter\lst@BOLGobble@
105    \else
106       \expandafter\lst@check@chartype@BOL
107    \fi}
108 \def\lst@BOLGobble@#1{%
109    \let\lst@next#1%
110    \ifx \lst@next\relax\else
111    \ifx \lst@next\lst@MProcessListing\else
112    \ifx \lst@next\lst@ProcessFormFeed\else
113    \ifx \lst@next\lstenv@backslash
114       \let\lst@next\lstenv@BOLGobble@@
115    \else
116       \let\lst@next\lst@BOLGobble@@
117       \ifx #1\lst@ProcessTabulator
118          \advance\@tempcnta-\lst@tabsize\relax
119          \ifnum\@tempcnta<\z@
120             \lst@length-\@tempcnta \lst@PreGotoTabStop
121          \fi
122       \else
123          \edef\@tempa{\lst@nextchar=`\string#1\relax}%
124          \@tempa
125          \ifnum\lst@nextchar<\@cclvi\else
126             \advance\@tempcnta\m@ne
127          \fi
128          \advance\@tempcnta\m@ne
129       \fi
130    \fi \fi \fi \fi
131    \lst@next}
132 \def\lst@BOLGobble@@{%
133    \ifnum\@tempcnta>\z@
134       \expandafter\lst@BOLGobble@
135    \else
136       \expandafter\lst@check@chartype@BOL
137    \fi
138 }
139
140 %
141 %    \begin{修正事項}{1.3}
142 % ちょっとした修正
143 \gdef\lst@breakProcessOther#1{\lst@ProcessOther#1}
144 % ソースコード目次における文字と番号の空き
145 \let \l@lstlisting = \l@figure
146 % キャプションとソースコード目次に対する日本語対応
147 \def\lstlistingname{ソースコード}
148 \def\lstlistlistingname{ソースコード目次}
149 %    \end{修正事項}
150
151
152 % Changes for LuaTeX-ja:
153 % 1. \char"FFFFF は通常行末用コメント文字として使われる.
154 %    \catcode"FFFFF を変更しないと \lstnewenvironment{env}[1] ... 
155 %    による env 環境等が異常動作(x19290 さんの報告)
156 \lst@AddToHook{Init}{\catcode"FFFFF=9\relax}
157 \lst@AddToHook{EOL}{\catcode"FFFFF=14\relax}
158
159 % 2. listing な環境の処理中に \DeclareFontShape の (s)sub が実行されると,なぜか
160 %        ! Use of set@size@funct@args@ doesn't match its definition.
161 %    のエラーが出る.
162 %    \ifnot@nil #1-> \def\reserved@a{#1}... の \reserved@a=\set@size@funct@args@
163 %    がなぜか実行される?
164 %    ad hoc な対策として事前に必要な (s)sub は実行しておくことにする.
165 %\lst@AddToHook{Init}{\begingroup\itshape\bfseries\upshape\bfseries\mdseries\endgroup}
166 \endinput