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}[2013/05/14]
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}
133 \gdef\newluatexcatcodetable#1{%
134 \ifnum\lltxb@catcodetable@alloc<\ltj@cctb@limit\relax
135 \global\advance\lltxb@catcodetable@alloc\tw@
136 \allocationnumber\lltxb@catcodetable@alloc
137 \global\chardef#1\allocationnumber
138 \luatexinitcatcodetable\allocationnumber
139 \begingroup\escapechar\m@ne
140 \luatexbase@directlua{luatexbase.catcodetabledef_from_tex(
141 '\luatexluaescapestring{\string#1}', '\number\allocationnumber')}%
143 \wlog{\string#1=\string\luatexcatcodetable\the\allocationnumber}%
145 \errmessage{No room for a new \string\luatexcatcodetable}%
151 % The luatex package stores its preset settings to registers 1, 3, 5, 7
152 % and new user allocations go to odd number 9, 11, 13, etc.; registers
153 % with even number are reserved for the "category code table stack".
155 % I relocate all the future allocation by luatexbase-cctb to the "higher"
156 % area (number >= \ltj@cctb@lower@stor@size), which is simply done by
157 % moving the allocation pointer. And all the preset settings of
158 % luatexbase-cctb (those of luatex-pkg is a subset) are prepared again.
159 % The colliding user allocation cannot be helped, but in the fortunate
160 % case where luatex-pkg is not yet loaded or its allocating function
161 % is never invoked, the only endangered user allocation is register 7
162 % of luatexbase-cctb, which is rescued by simply reassining the table,
163 % since the all presets are migrated to the higher area.
165 \unless\ifdefined\LuT@AllocAttribute
167 \RequirePackage{luatex}[2010/03/01]
169 \input luatex.sty\relax
173 \edef\ltj@@tempa{\meaning\LuT@AllocAttribute}
174 \edef\ltj@@tempb{\meaning\lltxb@catcodetable@alloc}
175 \ifx\ltj@@tempa\ltj@@tempb
176 % Failure: luatexbase-cctb and luatex-pkg seem to be synchronized!
177 \ltj@@cctb@failure=6 %
179 \ltj@@cctb@check@failure
182 \ifdefined\CatcodeTableLaTeX \CatcodeTableLaTeX
184 % Failure: luatex-pkg is not of expected version!!
185 \ltj@@cctb@failure=100 %
188 \def\ltj@@cctb@org@def#1{
189 \ifnum\LuT@AllocCatcodeTable<1114110 %
190 \global\advance\LuT@AllocCatcodeTable by\tw@
191 \allocationnumber=\LuT@AllocCatcodeTable
192 \global\chardef#1=\allocationnumber
194 \string#1=\string\catcodetable\the\allocationnumber
197 \errmessage{No room for a new \string\catcodetable}
200 \unless\ifx\ltj@@cctb@org@def\newcatcodetable
201 % Failure: luatex-pkg is not of expected version!!
202 \ltj@@cctb@failure=100 %
205 \def\ltj@@cctb@org@def{%
206 \ifnum\CatcodeTableStack<65534\relax
207 \global\advance\CatcodeTableStack\tw@
209 \errmessage{CatcodeTableStack overflow}%
211 \unless\ifx\ltj@@cctb@org@def\IncCatcodeTableStack
212 % Failure: luatex-pkg is not of expected version!!
213 \ltj@@cctb@failure=100 %
215 \ltj@@cctb@check@failure
217 %% Restore the register 7 which is overwritten by luatex-pkg.
218 \unless\ifnum\lltxb@catcodetable@alloc<7 %
219 \ltj@@copy@cctb{\ltj@@tempcctb@a}{7}
222 %% Move the pointer of luatexbase-cctb to higher area.
223 \lltxb@catcodetable@alloc=\ltj@cctb@lower@stor@size
225 %% Restrict the allocation by luatex-pkg to lower area.
226 \chardef\ltj@@cctb@lower@stor@check=
227 \numexpr\ltj@cctb@lower@stor@size-2\relax
228 \def\newcatcodetable#1{
229 \ifnum\LuT@AllocCatcodeTable<\ltj@@cctb@lower@stor@check
230 \global\advance\LuT@AllocCatcodeTable by\tw@
231 \allocationnumber=\LuT@AllocCatcodeTable
232 \global\chardef#1=\allocationnumber
234 \string#1=\string\catcodetable\the\allocationnumber
237 \errmessage{No room for a new \string\catcodetable}
240 \def\IncCatcodeTableStack{%
241 \ifnum\CatcodeTableStack<\ltj@@cctb@lower@stor@check
242 \global\advance\CatcodeTableStack by\tw@
244 \@PackageError{luatex}{%
245 Catcode table stack overflow%
250 %------------------- Re-create the presets
252 \newluatexcatcodetable\CatcodeTableIniTeX
253 \newluatexcatcodetable\CatcodeTableString
254 \setluatexcatcodetable\CatcodeTableString{%
255 \luatexcatcodetable\CatcodeTableIniTeX
257 \catcode13 12 % carriage return
258 \catcode37 12 % percent
259 \SetCatcodeRange{65}{90}{12}% A-Z
260 \SetCatcodeRange{97}{122}{12}% a-z
261 \catcode92 12 % backslash
263 \newluatexcatcodetable\CatcodeTableOther
264 \setluatexcatcodetable\CatcodeTableOther{%
265 \luatexcatcodetable\CatcodeTableString
267 \newluatexcatcodetable\CatcodeTableLaTeX
268 \setluatexcatcodetable\CatcodeTableLaTeX{%
269 \luatexcatcodetable\CatcodeTableIniTeX
270 \SetCatcodeRange{0}{31}{15}%
272 \catcode12 13 % form feed
273 \catcode13 5 % carriage return
275 \catcode36 3 % dollar
276 \catcode38 4 % ampersand
277 \catcode94 7 % circumflex
278 \catcode95 8 % underscore
279 \catcode123 1 % brace left
280 \catcode125 2 % brace right
281 \catcode126 13 % tilde
283 \newluatexcatcodetable\CatcodeTableLaTeXAtLetter
284 \setluatexcatcodetable\CatcodeTableLaTeXAtLetter{%
285 \luatexcatcodetable\CatcodeTableLaTeX
287 \newluatexcatcodetable\CatcodeTableExpl
288 \setluatexcatcodetable\CatcodeTableExpl{%
289 \luatexcatcodetable\CatcodeTableLaTeX
290 \catcode126 10 % tilde is a space char
291 \catcode32 9 % space is ignored
292 \catcode9 9 % tab also ignored
293 \catcode95 11 % underscore letter
294 \catcode58 11 % colon letter
296 \luatexbase@directlua{luatexbase.catcodetable_do_shortcuts()}
298 %%------------------ all done