4 % Modified from jlisting.sty (by Thor) for LuaTeX-ja.
7 \NeedsTeXFormat{LaTeX2e}
8 \def\filedate{2012/01/11}
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}%
18 \let\lst@@ProcessLetter\lst@ProcessLetter
19 \def\lst@ProcessLetter#1#2{%
20 \lst@check@chartype{#2}%
21 {\lst@@ProcessLetter{#1}}%
23 \let\lst@@ProcessDigit\lst@ProcessDigit
24 \def\lst@ProcessDigit#1#2{%
25 \lst@check@chartype{#2}%
26 {\lst@@ProcessDigit{#1}}%
28 \let\lst@@ProcessOther\lst@ProcessOther
29 \def\lst@ProcessOther#1#2{%
30 \lst@check@chartype{#2}%
31 {\lst@@ProcessOther{#1}}%
33 \let\lst@@ProcessTabulator\lst@ProcessTabulator
34 \def\lst@ProcessTabulator#1{%
35 \lst@check@chartype{#1}%
36 \lst@@ProcessTabulator
38 \def\lst@check@chartype#1#2#3{%
39 \edef\@tempa{\lst@nextchar=`\string#1\relax}%
40 \afterassignment\remove@to@nnil
43 \ifnum\lst@nextchar<\@cclvi
46 \lst@ifletter \else \lst@OutputOther \fi
48 \expandafter\lst@AppendJchar
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}}%
57 \def\lst@check@chartype@BOL#1{%
58 \edef\@tempa{\lst@nextchar=`\string#1\relax}%
59 \afterassignment\remove@to@nnil
61 \ifnum\lst@nextchar<\@cclvi\else
63 \expandafter\lst@AppendJchar
66 \def\lst@InputListing#1{%
68 \lsthk@PreSet \gdef\lst@intname{#1}%
69 \expandafter\lstset\expandafter{\lst@set}%
71 \catcode\active=\active
72 \lst@Init\relax \let\lst@gobble\z@
74 \lst@ifprint \def\lst@next{\lst@get@filecontents{#1}}%
75 \else \let\lst@next\@empty
81 \newread\lst@inputfile
82 \def\lst@get@filecontents#1{%
83 \let\lst@filecontents\@empty
84 \openin\lst@inputfile=#1\relax
85 \let\@lst@get@filecontents@prevline\relax
86 \lst@get@filecontents@loop
87 \closein\lst@inputfile
88 \lst@filecontents\empty}
89 \def\lst@get@filecontents@loop{%
90 \read\lst@inputfile to\@lst@get@filecontents@currline
91 \ifx\@lst@get@filecontents@prevline\relax\else
92 \expandafter\expandafter\expandafter\def
93 \expandafter\expandafter\expandafter\lst@filecontents
94 \expandafter\expandafter\expandafter{%
95 \expandafter\lst@filecontents\@lst@get@filecontents@prevline}%
97 \let\@lst@get@filecontents@prevline\@lst@get@filecontents@currline
98 \ifeof\lst@inputfile\else
99 \expandafter\lst@get@filecontents@loop
103 \ifnum\lst@gobble>\z@
104 \@tempcnta\lst@gobble\relax
105 \expandafter\lst@BOLGobble@
107 \expandafter\lst@check@chartype@BOL
109 \def\lst@BOLGobble@#1{%
111 \ifx \lst@next\relax\else
112 \ifx \lst@next\lst@MProcessListing\else
113 \ifx \lst@next\lst@ProcessFormFeed\else
114 \ifx \lst@next\lstenv@backslash
115 \let\lst@next\lstenv@BOLGobble@@
117 \let\lst@next\lst@BOLGobble@@
118 \ifx #1\lst@ProcessTabulator
119 \advance\@tempcnta-\lst@tabsize\relax
121 \lst@length-\@tempcnta \lst@PreGotoTabStop
124 \edef\@tempa{\lst@nextchar=`\string#1\relax}%
126 \ifnum\lst@nextchar<\@cclvi\else
127 \advance\@tempcnta\m@ne
129 \advance\@tempcnta\m@ne
133 \def\lst@BOLGobble@@{%
135 \expandafter\lst@BOLGobble@
137 \expandafter\lst@check@chartype@BOL
144 \gdef\lst@breakProcessOther#1{\lst@ProcessOther#1}
145 % ソースコード目次における文字と番号の空き
146 \let \l@lstlisting = \l@figure
147 % キャプションとソースコード目次に対する日本語対応
148 \def\lstlistingname{ソースコード}
149 \def\lstlistlistingname{ソースコード目次}
153 % Changes for LuaTeX-ja:
154 % 1. \char"FFFFF は通常行末用コメント文字として使われる.
155 % \catcode"FFFFF を変更しないと \lstnewenvironment{env}[1] ...
156 % による env 環境等が異常動作(x19290 さんの報告)
157 \lst@AddToHook{Init}{\catcode"FFFFF=9\relax}
158 \lst@AddToHook{EOL}{\catcode"FFFFF=14\relax}
160 % 2. listing な環境の処理中に \DeclareFontShape の (s)sub が実行されると,なぜか
161 % ! Use of set@size@funct@args@ doesn't match its definition.
163 % \ifnot@nil #1-> \def\reserved@a{#1}... の \reserved@a=\set@size@funct@args@
165 % ad hoc な対策として事前に必要な (s)sub は実行しておくことにする.
166 \lst@AddToHook{Init}{\begingroup\itshape\bfseries\upshape\endgroup}