5 %! luatexbase と luatex パッケージのカテゴリコードテーブルの割当に
7 %! この衝突に関して「外部のパッチ」で解決しようとするのは, あまり
8 %! 筋が良くなく, できるなら避けたいが, 今のままだと LuaTeX-ja を
9 %! LaTeX + fontspec で用いた時に確実に影響が出る. また衝突を残した
10 %! ままだとカテゴリコードテーブルが実質的に使えない訳で, これも
12 %! 「近いうちに両パッケージの中で解決される」ことを期待しつつ,
13 %! 「衝突がない」という前提で開発を行いたいので, 暫定的処置として,
17 %% Avoid multiple loading.
18 \csname luatexjacctbregLoaded\endcsname
19 \edef\ltj@cctbreg@AtEnd{%
20 \endlinechar=\the\endlinechar
23 \def\luatexjacctbregLoaded{\endinput}
25 \ifltj@in@latex %<*LaTeX>
26 \NeedsTeXFormat{LaTeX2e}
27 \ProvidesPackage{ltj-cctbreg}[2012/04/21 v0.2]
30 % LS = Size of storage reserved for luatex-pkg.
31 \chardef\ltj@cctb@lower@stor@size=16384
33 % LL = (upper bound of cctb index used by luatexbase.sty and luatex.sty) - 1
34 \chardef\ltj@cctb@limit=32766
38 \newcount\ltj@@cctb@failure
41 \def\ltj@@cctb@check@failure{
42 \ifnum\ltj@@cctb@failure>0 %
43 \@PackageWarningNoLine{ltj-cctbreg}
44 {Cannot apply the patch (\the\ltj@@cctb@failure)}
46 \expandafter\endinput\fi\relax
49 \chardef\ltj@@cctb@lower@stor@max=
50 \numexpr\ltj@cctb@lower@stor@size-1\relax
51 \chardef\ltj@@cctb@lower@stor@safemax=
52 \numexpr\ltj@cctb@lower@stor@size-8\relax
54 \chardef\ltj@@tempcctb@a=\ltj@cctb@lower@stor@size
55 \chardef\ltj@@tempcctb@b=\numexpr\ltj@cctb@lower@stor@size+1\relax
56 \def\ltj@@copy@cctb#1#2{%
57 % Note: The current cctb number is supposed to be zero.
58 \luatexcatcodetable#1\relax
59 \luatexsavecatcodetable#2\relax
60 \luatexcatcodetable0\relax
65 % The luatexbase-cctb package stores its preset settings to
66 % registers 1--6, and new user allocations go to number 7, 8, ....
68 \ifdefined\lltxb@catcodetable@alloc
69 \ifnum\lltxb@catcodetable@alloc>\ltj@@cctb@lower@stor@safemax
70 % Failure: luatexbase-cctb alloc pointer is too high!
71 \ltj@@cctb@failure=2 %
74 % Failure: luatexbase-cctb not loaded!
75 \ltj@@cctb@failure=1 %
81 \gdef\ltj@@cctb@org@def#1{%
82 \ifnum\lltxb@catcodetable@alloc<65535\relax
83 \global\advance\lltxb@catcodetable@alloc\tw@
84 \allocationnumber\lltxb@catcodetable@alloc
85 \global\chardef#1\allocationnumber
86 \luatexinitcatcodetable\allocationnumber
87 \begingroup\escapechar\m@ne
88 \luatexbase@directlua{luatexbase.catcodetabledef_from_tex(
89 '\luatexluaescapestring{\string#1}', '\number\allocationnumber')}%
91 \wlog{\string#1=\string\luatexcatcodetable\the\allocationnumber}%
93 \errmessage{No room for a new \string\luatexcatcodetable}%
97 \unless\ifx\ltj@@cctb@org@def\newluatexcatcodetable
98 % Failure: luatexbase-cctb is not of expected version!
99 %%% \bebo <- the meaning of this control sequence?
100 \ltj@@cctb@failure=3 %
103 \ifdefined\LuT@AllocAttribute
104 \ifnum\LuT@AllocAttribute>\ltj@@cctb@lower@stor@safemax
105 % Failure: luatex-pkg alloc pointer is too high!
106 \ltj@@cctb@failure=4 %
109 \ifdefined\CatcodeTableStack
110 \ifnum\CatcodeTableStack>\ltj@@cctb@lower@stor@safemax
111 % Failure: luatex-pkg cctb-stack pointer is too high!
112 \ltj@@cctb@failure=5 %
116 \ltj@@cctb@check@failure
119 \newluatexcatcodetable\cctb@seven
121 \luatexsavecatcodetable\cctb@seven
125 %% Save the register 7 (to a temporary register)
126 \unless\ifnum\lltxb@catcodetable@alloc<7 %
127 \ltj@@copy@cctb{7}{\ltj@@tempcctb@a}
135 \gdef\newluatexcatcodetable#1{%
136 \ifnum\lltxb@catcodetable@alloc<\ltj@cctb@limit\relax
137 \global\advance\lltxb@catcodetable@alloc\tw@
138 \allocationnumber\lltxb@catcodetable@alloc
139 \global\chardef#1\allocationnumber
140 \luatexinitcatcodetable\allocationnumber
141 \begingroup\escapechar\m@ne
142 \luatexbase@directlua{luatexbase.catcodetabledef_from_tex(
143 '\luatexluaescapestring{\string#1}', '\number\allocationnumber')}%
145 \wlog{\string#1=\string\luatexcatcodetable\the\allocationnumber}%
147 \errmessage{No room for a new \string\luatexcatcodetable}%
153 % The luatex package stores its preset settings to registers 1, 3, 5, 7
154 % and new user allocations go to odd number 9, 11, 13, etc.; registers
155 % with even number are reserved for the "category code table stack".
157 % I relocate all the future allocation by luatexbase-cctb to the "higher"
158 % area (number >= \ltj@cctb@lower@stor@size), which is simply done by
159 % moving the allocation pointer. And all the preset settings of
160 % luatexbase-cctb (those of luatex-pkg is a subset) are prepared again.
161 % The colliding user allocation cannot be helped, but in the fortunate
162 % case where luatex-pkg is not yet loaded or its allocating function
163 % is never invoked, the only endangered user allocation is register 7
164 % of luatexbase-cctb, which is rescued by simply reassining the table,
165 % since the all presets are migrated to the higher area.
167 \unless\ifdefined\LuT@AllocAttribute
169 \RequirePackage{luatex}[2010/03/01]
171 \input luatex.sty\relax
175 \edef\ltj@@tempa{\meaning\LuT@AllocAttribute}
176 \edef\ltj@@tempb{\meaning\lltxb@catcodetable@alloc}
177 \ifx\ltj@@tempa\ltj@@tempb
178 % Failure: luatexbase-cctb and luatex-pkg seem to be synchronized!
179 \ltj@@cctb@failure=6 %
181 \ltj@@cctb@check@failure
184 \ifdefined\CatcodeTableLaTeX \CatcodeTableLaTeX
186 % Failure: luatex-pkg is not of expected version!!
187 \ltj@@cctb@failure=100 %
190 \def\ltj@@cctb@org@def#1{
191 \ifnum\LuT@AllocCatcodeTable<1114110 %
192 \global\advance\LuT@AllocCatcodeTable by\tw@
193 \allocationnumber=\LuT@AllocCatcodeTable
194 \global\chardef#1=\allocationnumber
196 \string#1=\string\catcodetable\the\allocationnumber
199 \errmessage{No room for a new \string\catcodetable}
202 \unless\ifx\ltj@@cctb@org@def\newcatcodetable
203 % Failure: luatex-pkg is not of expected version!!
204 \ltj@@cctb@failure=100 %
207 \def\ltj@@cctb@org@def{%
208 \ifnum\CatcodeTableStack<268435454 %
209 \global\advance\CatcodeTableStack by\tw@
211 \@PackageError{luatex}{%
212 Catcode table stack overflow%
216 \unless\ifx\ltj@@cctb@org@def\IncCatcodeTableStack
217 % Failure: luatex-pkg is not of expected version!!
218 \ltj@@cctb@failure=100 %
220 \ltj@@cctb@check@failure
222 %% Restore the register 7 which is overwritten by luatex-pkg.
223 \unless\ifnum\lltxb@catcodetable@alloc<7 %
224 \ltj@@copy@cctb{\ltj@@tempcctb@a}{7}
227 %% Move the pointer of luatexbase-cctb to higher area.
228 \lltxb@catcodetable@alloc=\ltj@cctb@lower@stor@size
230 %% Restrict the allocation by luatex-pkg to lower area.
231 \chardef\ltj@@cctb@lower@stor@check=
232 \numexpr\ltj@cctb@lower@stor@size-2\relax
233 \def\newcatcodetable#1{
234 \ifnum\LuT@AllocCatcodeTable<\ltj@@cctb@lower@stor@check
235 \global\advance\LuT@AllocCatcodeTable by\tw@
236 \allocationnumber=\LuT@AllocCatcodeTable
237 \global\chardef#1=\allocationnumber
239 \string#1=\string\catcodetable\the\allocationnumber
242 \errmessage{No room for a new \string\catcodetable}
245 \def\IncCatcodeTableStack{%
246 \ifnum\CatcodeTableStack<\ltj@@cctb@lower@stor@check
247 \global\advance\CatcodeTableStack by\tw@
249 \@PackageError{luatex}{%
250 Catcode table stack overflow%
255 %------------------- Re-create the presets
257 \newluatexcatcodetable\CatcodeTableIniTeX
258 \newluatexcatcodetable\CatcodeTableString
259 \setluatexcatcodetable\CatcodeTableString{%
260 \luatexcatcodetable\CatcodeTableIniTeX
262 \catcode13 12 % carriage return
263 \catcode37 12 % percent
264 \setcatcoderange{65}{90}{12}% A-Z
265 \setcatcoderange{97}{122}{12}% a-z
266 \catcode92 12 % backslash
268 \newluatexcatcodetable\CatcodeTableOther
269 \setluatexcatcodetable\CatcodeTableOther{%
270 \luatexcatcodetable\CatcodeTableString
272 \newluatexcatcodetable\CatcodeTableLaTeX
273 \setluatexcatcodetable\CatcodeTableLaTeX{%
274 \luatexcatcodetable\CatcodeTableIniTeX
275 \setcatcoderange{0}{31}{15}%
277 \catcode12 13 % form feed
278 \catcode13 5 % carriage return
280 \catcode36 3 % dollar
281 \catcode38 4 % ampersand
282 \catcode94 7 % circumflex
283 \catcode95 8 % underscore
284 \catcode123 1 % brace left
285 \catcode125 2 % brace right
286 \catcode126 13 % tilde
288 \newluatexcatcodetable\CatcodeTableLaTeXAtLetter
289 \setluatexcatcodetable\CatcodeTableLaTeXAtLetter{%
290 \luatexcatcodetable\CatcodeTableLaTeX
292 \newluatexcatcodetable\CatcodeTableExpl
293 \setluatexcatcodetable\CatcodeTableExpl{%
294 \luatexcatcodetable\CatcodeTableLaTeX
295 \catcode126 10 % tilde is a space char
296 \catcode32 9 % space is ignored
297 \catcode9 9 % tab also ignored
298 \catcode95 11 % underscore letter
299 \catcode58 11 % colon letter
301 \luatexbase@directlua{luatexbase.catcodetable_do_shortcuts()}
303 %%------------------ all done