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 %
80 \gdef\ltj@@cctb@org@def#1{%
81 \ifnum\lltxb@catcodetable@alloc<65535\relax
82 \global\advance\lltxb@catcodetable@alloc\tw@
83 \allocationnumber\lltxb@catcodetable@alloc
84 \global\chardef#1\allocationnumber
85 \luatexinitcatcodetable\allocationnumber
86 \begingroup\escapechar\m@ne
87 \luatexbase@directlua{luatexbase.catcodetabledef_from_tex(
88 '\luatexluaescapestring{\string#1}', '\number\allocationnumber')}%
90 \wlog{\string#1=\string\luatexcatcodetable\the\allocationnumber}%
92 \errmessage{No room for a new \string\luatexcatcodetable}%
96 \unless\ifx\ltj@@cctb@org@def\newluatexcatcodetable
97 % Failure: luatexbase-cctb is not of expected version!
98 %%% \bebo <- the meaning of this control sequence?
99 \ltj@@cctb@failure=3 %
102 \ifdefined\LuT@AllocAttribute
103 \ifnum\LuT@AllocAttribute>\ltj@@cctb@lower@stor@safemax
104 % Failure: luatex-pkg alloc pointer is too high!
105 \ltj@@cctb@failure=4 %
108 \ifdefined\CatcodeTableStack
109 \ifnum\CatcodeTableStack>\ltj@@cctb@lower@stor@safemax
110 % Failure: luatex-pkg cctb-stack pointer is too high!
111 \ltj@@cctb@failure=5 %
115 \ltj@@cctb@check@failure
118 \newluatexcatcodetable\cctb@seven
120 \luatexsavecatcodetable\cctb@seven
124 %% Save the register 7 (to a temporary register)
125 \unless\ifnum\lltxb@catcodetable@alloc<7 %
126 \ltj@@copy@cctb{7}{\ltj@@tempcctb@a}
134 \gdef\newluatexcatcodetable#1{%
135 \ifnum\lltxb@catcodetable@alloc<\ltj@cctb@limit\relax
136 \global\advance\lltxb@catcodetable@alloc\tw@
137 \allocationnumber\lltxb@catcodetable@alloc
138 \global\chardef#1\allocationnumber
139 \luatexinitcatcodetable\allocationnumber
140 \begingroup\escapechar\m@ne
141 \luatexbase@directlua{luatexbase.catcodetabledef_from_tex(
142 '\luatexluaescapestring{\string#1}', '\number\allocationnumber')}%
144 \wlog{\string#1=\string\luatexcatcodetable\the\allocationnumber}%
146 \errmessage{No room for a new \string\luatexcatcodetable}%
152 % The luatex package stores its preset settings to registers 1, 3, 5, 7
153 % and new user allocations go to odd number 9, 11, 13, etc.; registers
154 % with even number are reserved for the "category code table stack".
156 % I relocate all the future allocation by luatexbase-cctb to the "higher"
157 % area (number >= \ltj@cctb@lower@stor@size), which is simply done by
158 % moving the allocation pointer. And all the preset settings of
159 % luatexbase-cctb (those of luatex-pkg is a subset) are prepared again.
160 % The colliding user allocation cannot be helped, but in the fortunate
161 % case where luatex-pkg is not yet loaded or its allocating function
162 % is never invoked, the only endangered user allocation is register 7
163 % of luatexbase-cctb, which is rescued by simply reassining the table,
164 % since the all presets are migrated to the higher area.
166 \unless\ifdefined\LuT@AllocAttribute
168 \RequirePackage{luatex}[2010/03/01]
170 \input luatex.sty\relax
174 \edef\ltj@@tempa{\meaning\LuT@AllocAttribute}
175 \edef\ltj@@tempb{\meaning\lltxb@catcodetable@alloc}
176 \ifx\ltj@@tempa\ltj@@tempb
177 % Failure: luatexbase-cctb and luatex-pkg seem to be synchronized!
178 \ltj@@cctb@failure=6 %
180 \ltj@@cctb@check@failure
183 \ifdefined\CatcodeTableLaTeX \CatcodeTableLaTeX
185 % Failure: luatex-pkg is not of expected version!!
186 \ltj@@cctb@failure=100 %
189 \def\ltj@@cctb@org@def#1{
190 \ifnum\LuT@AllocCatcodeTable<1114110 %
191 \global\advance\LuT@AllocCatcodeTable by\tw@
192 \allocationnumber=\LuT@AllocCatcodeTable
193 \global\chardef#1=\allocationnumber
195 \string#1=\string\catcodetable\the\allocationnumber
198 \errmessage{No room for a new \string\catcodetable}
201 \unless\ifx\ltj@@cctb@org@def\newcatcodetable
202 % Failure: luatex-pkg is not of expected version!!
203 \ltj@@cctb@failure=100 %
206 \def\ltj@@cctb@org@def{%
207 \ifnum\CatcodeTableStack<65534\relax
208 \global\advance\CatcodeTableStack\tw@
210 \errmessage{CatcodeTableStack overflow}%
212 \unless\ifx\ltj@@cctb@org@def\IncCatcodeTableStack
213 % Failure: luatex-pkg is not of expected version!!
214 \ltj@@cctb@failure=100 %
216 \ltj@@cctb@check@failure
218 %% Restore the register 7 which is overwritten by luatex-pkg.
219 \unless\ifnum\lltxb@catcodetable@alloc<7 %
220 \ltj@@copy@cctb{\ltj@@tempcctb@a}{7}
223 %% Move the pointer of luatexbase-cctb to higher area.
224 \lltxb@catcodetable@alloc=\ltj@cctb@lower@stor@size
226 %% Restrict the allocation by luatex-pkg to lower area.
227 \chardef\ltj@@cctb@lower@stor@check=
228 \numexpr\ltj@cctb@lower@stor@size-2\relax
229 \def\newcatcodetable#1{
230 \ifnum\LuT@AllocCatcodeTable<\ltj@@cctb@lower@stor@check
231 \global\advance\LuT@AllocCatcodeTable by\tw@
232 \allocationnumber=\LuT@AllocCatcodeTable
233 \global\chardef#1=\allocationnumber
235 \string#1=\string\catcodetable\the\allocationnumber
238 \errmessage{No room for a new \string\catcodetable}
241 \def\IncCatcodeTableStack{%
242 \ifnum\CatcodeTableStack<\ltj@@cctb@lower@stor@check
243 \global\advance\CatcodeTableStack by\tw@
245 \@PackageError{luatex}{%
246 Catcode table stack overflow%
251 %------------------- Re-create the presets
253 \newluatexcatcodetable\CatcodeTableIniTeX
254 \newluatexcatcodetable\CatcodeTableString
255 \setluatexcatcodetable\CatcodeTableString{%
256 \luatexcatcodetable\CatcodeTableIniTeX
258 \catcode13 12 % carriage return
259 \catcode37 12 % percent
260 \SetCatcodeRange{65}{90}{12}% A-Z
261 \SetCatcodeRange{97}{122}{12}% a-z
262 \catcode92 12 % backslash
264 \newluatexcatcodetable\CatcodeTableOther
265 \setluatexcatcodetable\CatcodeTableOther{%
266 \luatexcatcodetable\CatcodeTableString
268 \newluatexcatcodetable\CatcodeTableLaTeX
269 \setluatexcatcodetable\CatcodeTableLaTeX{%
270 \luatexcatcodetable\CatcodeTableIniTeX
271 \SetCatcodeRange{0}{31}{15}%
273 \catcode12 13 % form feed
274 \catcode13 5 % carriage return
276 \catcode36 3 % dollar
277 \catcode38 4 % ampersand
278 \catcode94 7 % circumflex
279 \catcode95 8 % underscore
280 \catcode123 1 % brace left
281 \catcode125 2 % brace right
282 \catcode126 13 % tilde
284 \newluatexcatcodetable\CatcodeTableLaTeXAtLetter
285 \setluatexcatcodetable\CatcodeTableLaTeXAtLetter{%
286 \luatexcatcodetable\CatcodeTableLaTeX
288 \newluatexcatcodetable\CatcodeTableExpl
289 \setluatexcatcodetable\CatcodeTableExpl{%
290 \luatexcatcodetable\CatcodeTableLaTeX
291 \catcode126 10 % tilde is a space char
292 \catcode32 9 % space is ignored
293 \catcode9 9 % tab also ignored
294 \catcode95 11 % underscore letter
295 \catcode58 11 % colon letter
297 \luatexbase@directlua{luatexbase.catcodetable_do_shortcuts()}
299 %%------------------ all done