OSDN Git Service

I forgot to include changes ^^;
[luatex-ja/luatexja.git] / src / patches / lltjp-listings.sty
1 %
2 % lltjp-listings.sty
3 %
4
5 \NeedsTeXFormat{LaTeX2e}
6 \def\filedate{2012/09/22}
7 \def\fileversion{0.6}
8 \ProvidesPackage{lltjp-listings}[\filedate\space\fileversion]
9 \RequirePackage{listings,luatexbase-cctb}
10
11 % catcode 対策
12 \newluatexcatcodetable\CatcodeTableLTJlistings
13 \setluatexcatcodetable\CatcodeTableLTJlistings{
14   \luatexcatcodetable\CatcodeTableLaTeXAtLetter
15   \catcode"FFFFF=9%"
16   \setcatcoderange{"0080}{"FFFF}{13}%   BMP
17   \setcatcoderange{"20000}{"2FFFF}{13}% SIP
18 }
19
20 % lowest level
21 \def\lst@kanjitrue{\let\lst@ifkanji\iftrue}
22 \def\lst@kanjifalse{\let\lst@ifkanji\iffalse}
23 \lst@AddToHook{InitVars}{\lst@kanjifalse}
24
25 \def\lst@AppendOther{%
26     \lst@ifletter\lst@Output\lst@letterfalse\fi\lst@kanjifalse
27     \futurelet\lst@lastother\lst@Append}
28
29 \def\ltj@lst@setletterflag{%
30   \lst@ifletter
31     \lst@ifkanji\lst@Output\lst@kanjifalse\fi
32   \else
33     \lst@lettertrue\lst@ifkanji\lst@kanjifalse\else\lst@OutputOther\fi
34   \fi}
35
36 \def\ltj@lst@setkanjiflag{%
37   \lst@ifletter
38     \lst@Output
39   \else
40     \lst@ifkanji\else\lst@OutputOther\fi\lst@lettertrue
41   \fi}
42
43 \def\ltj@lst@setopenflag{%
44   \lst@ifletter
45     \lst@letterfalse\lst@Output
46   \else
47     \lst@ifkanji\else\lst@OutputOther\fi
48   \fi\lst@kanjitrue}
49
50 \def\ltj@lst@setcloseflag{%
51   \lst@ifletter\else\lst@lettertrue\fi\lst@kanjitrue}
52
53 \def\lst@ProcessLetter#1{%
54   \lst@whitespacefalse
55   \ifnum\ltjgetparameter{jacharrange}{\ltjgetparameter{chartorange}{`#1}}=0
56     \ifnum\ltjgetparameter{postbreakpenalty}{`#1}>0
57       \ltj@lst@setopenflag    % 開き括弧類
58     \else
59       \ifnum\ltjgetparameter{prebreakpenalty}{`#1}>0
60         \ltj@lst@setcloseflag % 閉じ括弧類,句読点
61       \else
62         \ltj@lst@setkanjiflag % 通常の和文文字
63     \fi\fi
64     \advance\lst@length\@ne   % 和文文字は通常の2倍の幅
65   \else
66     \ltj@lst@setletterflag
67   \fi
68   \lst@Append#1}
69
70 \def\lst@ProcessJALetterHalf#1{%
71   \lst@whitespacefalse
72   \ifnum\ltjgetparameter{jacharrange}{\ltjgetparameter{chartorange}{`#1}}=0
73     \ifnum\ltjgetparameter{postbreakpenalty}{`#1}>0
74       \ltj@lst@setopenflag    % 開き括弧類
75     \else
76       \ifnum\ltjgetparameter{prebreakpenalty}{`#1}>0
77         \ltj@lst@setcloseflag % 閉じ括弧類
78       \else
79         \ltj@lst@setkanjiflag % 通常の和文文字
80     \fi\fi
81     \advance\lst@length\@ne   % 半角カナは欧文文字と同じ幅
82   \else
83     \ltj@lst@setletterflag
84   \fi
85   \lst@Append#1}
86
87
88 % loading lltjp-listing-jpt.tex
89 \def\ltj@@listing@jpset#1#2{% fast: #2-#1+1 must be a multiple of 16
90   \@tempcnta=#1 \@tempcntb=#2 \@temptokena{}%
91   \loop\relax\ifnum\@tempcnta<\@tempcntb\relax
92     \ltj@@listing@jpset@\global\advance\@tempcnta\sixt@@n\repeat
93   \ltj@@listing@jpset@after{#1}
94 }
95 \def\ltj@@listing@jpsetN#1#2#3{% for (not large) range
96   \@tempcnta=#1 \@tempcntb=\numexpr 1+#2\relax \@temptokena{}%
97   \loop \global\advance\@tempcnta\@ne\ifnum\@tempcnta<\@tempcntb\relax
98     \ltj@@listing@jpsetN@{\@tempcnta}{#3}\repeat
99   \ltj@@listing@jpset@after{#1}
100 }
101
102 \def\ltj@@listing@jpset@after#1{%
103   \expandafter\edef\csname ltj@@listing@jpcmd@i#1\endcsname{\the\@temptokena}%
104   \toks@\expandafter\expandafter\expandafter\expandafter%
105   \expandafter\expandafter\expandafter{\expandafter\expandafter%
106   \expandafter\the\expandafter\toks@\csname ltj@@listing@jpcmd@i#1\endcsname}%
107   \@temptokena{}%
108 }
109
110 \begingroup
111 \catcode`\^^a0=13\catcode`\^^a1=13\catcode`\^^a2=13\catcode`\^^a3=13
112 \catcode`\^^a4=13\catcode`\^^a5=13\catcode`\^^a6=13\catcode`\^^a7=13
113 \catcode`\^^a8=13\catcode`\^^a9=13\catcode`\^^aa=13\catcode`\^^ab=13
114 \catcode`\^^ac=13\catcode`\^^ad=13\catcode`\^^ae=13\catcode`\^^af=13
115 \catcode`\^^b0=12\catcode`\^^b1=12\catcode`\^^b2=12\catcode`\^^b3=12
116 \catcode`\^^b4=12\catcode`\^^b5=12\catcode`\^^b6=12\catcode`\^^b7=12
117 \catcode`\^^b8=12\catcode`\^^b9=12\catcode`\^^ba=12\catcode`\^^bb=12
118 \catcode`\^^bc=12\catcode`\^^bd=12\catcode`\^^be=12\catcode`\^^bf=12
119 \gdef\ltj@@listing@jpset@{%
120    {\lccode`\^^a0=\@tempcnta \lccode`\^^b0=\@tempcnta
121     \advance\@tempcnta\@ne\lccode`\^^a1=\@tempcnta \lccode`\^^b1=\@tempcnta
122     \advance\@tempcnta\@ne\lccode`\^^a2=\@tempcnta \lccode`\^^b2=\@tempcnta
123     \advance\@tempcnta\@ne\lccode`\^^a3=\@tempcnta \lccode`\^^b3=\@tempcnta
124     \advance\@tempcnta\@ne\lccode`\^^a4=\@tempcnta \lccode`\^^b4=\@tempcnta
125     \advance\@tempcnta\@ne\lccode`\^^a5=\@tempcnta \lccode`\^^b5=\@tempcnta
126     \advance\@tempcnta\@ne\lccode`\^^a6=\@tempcnta \lccode`\^^b6=\@tempcnta
127     \advance\@tempcnta\@ne\lccode`\^^a7=\@tempcnta \lccode`\^^b7=\@tempcnta
128     \advance\@tempcnta\@ne\lccode`\^^a8=\@tempcnta \lccode`\^^b8=\@tempcnta
129     \advance\@tempcnta\@ne\lccode`\^^a9=\@tempcnta \lccode`\^^b9=\@tempcnta
130     \advance\@tempcnta\@ne\lccode`\^^aa=\@tempcnta \lccode`\^^ba=\@tempcnta
131     \advance\@tempcnta\@ne\lccode`\^^ab=\@tempcnta \lccode`\^^bb=\@tempcnta
132     \advance\@tempcnta\@ne\lccode`\^^ac=\@tempcnta \lccode`\^^bc=\@tempcnta
133     \advance\@tempcnta\@ne\lccode`\^^ad=\@tempcnta \lccode`\^^bd=\@tempcnta
134     \advance\@tempcnta\@ne\lccode`\^^ae=\@tempcnta \lccode`\^^be=\@tempcnta
135     \advance\@tempcnta\@ne\lccode`\^^af=\@tempcnta \lccode`\^^bf=\@tempcnta
136     \lowercase{\gdef\@temp{%
137       \gdef^^a0{\lst@ProcessLetter^^b0}\gdef^^a1{\lst@ProcessLetter^^b1}%
138       \gdef^^a2{\lst@ProcessLetter^^b2}\gdef^^a3{\lst@ProcessLetter^^b3}%
139       \gdef^^a4{\lst@ProcessLetter^^b4}\gdef^^a5{\lst@ProcessLetter^^b5}%
140       \gdef^^a6{\lst@ProcessLetter^^b6}\gdef^^a7{\lst@ProcessLetter^^b7}%
141       \gdef^^a8{\lst@ProcessLetter^^b8}\gdef^^a9{\lst@ProcessLetter^^b9}%
142       \gdef^^aa{\lst@ProcessLetter^^ba}\gdef^^ab{\lst@ProcessLetter^^bb}%
143       \gdef^^ac{\lst@ProcessLetter^^bc}\gdef^^ad{\lst@ProcessLetter^^bd}%
144       \gdef^^ae{\lst@ProcessLetter^^be}\gdef^^af{\lst@ProcessLetter^^bf}%
145     }}%\message{\meaning\@temp}%
146   }%
147   \@temptokena\expandafter\expandafter\expandafter\expandafter%
148   \expandafter\expandafter\expandafter{\expandafter\expandafter%
149   \expandafter\the\expandafter\@temptokena\@temp}%
150 }
151 \gdef\ltj@@listing@jpsetN@#1#2{{%
152     \@tempcnta=#1 \lccode`\~=\@tempcnta \lccode`\/=\@tempcnta
153     \lowercase{\gdef\@temp{\gdef~{#2/}}}}%
154   \@temptokena\expandafter\expandafter\expandafter\expandafter%
155   \expandafter\expandafter\expandafter{\expandafter\expandafter%
156   \expandafter\the\expandafter\@temptokena\@temp}%
157 }
158 \endgroup
159
160
161 \toks@{}
162 \input lltjp-listings-jpt.tex
163 \edef\ltj@@listing@jpcmd{\the\toks@}
164 \toks@{}
165 \lst@AddToHook{Init}{%
166   \luatexcatcodetable\CatcodeTableLTJlistings
167   \ltj@@listing@jpcmd}
168
169
170 % 白線対策
171 \def\lst@OutputToken{%
172     \lst@TrackNewLines \lst@OutputLostSpace
173     \lst@ifgobbledws
174         \lst@gobbledwhitespacefalse
175         \lst@@discretionary
176     \fi
177     \lst@CheckMerge
178     {\lst@thestyle{\lst@FontAdjust
179      \setbox\@tempboxa\lst@hbox
180         {\lsthk@OutputBox
181          \lst@lefthss
182          \expandafter\lst@FillOutputBox\the\lst@token\@empty
183          \lst@righthss}%
184      \ht\@tempboxa=0pt\dp\@tempboxa=0pt
185      \lst@CalcLostSpaceAndOutput}}%
186     \lst@ResetToken}
187
188
189 %    \begin{修正事項}{1.3} from jlisting.sty
190 % ちょっとした修正
191 \gdef\lst@breakProcessOther#1{\lst@ProcessOther#1}
192 % ソースコード目次における文字と番号の空き
193 \let \l@lstlisting = \l@figure
194 % キャプションとソースコード目次に対する日本語対応
195 \def\lstlistingname{ソースコード}
196 \def\lstlistlistingname{ソースコード目次}
197 %    \end{修正事項}
198 \endinput