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=32768
35 \newcount\ltj@@cctb@failure
38 \def\ltj@@cctb@check@failure{
39 \ifnum\ltj@@cctb@failure>0 %
40 \@PackageWarningNoLine{ltj-cctbreg}
41 {Cannot apply the patch (\the\ltj@@cctb@failure)}
43 \expandafter\endinput\fi\relax
46 \chardef\ltj@@cctb@lower@stor@max=
47 \numexpr\ltj@cctb@lower@stor@size-1\relax
48 \chardef\ltj@@cctb@lower@stor@safemax=
49 \numexpr\ltj@cctb@lower@stor@size-8\relax
51 \chardef\ltj@@tempcctb@a=\ltj@cctb@lower@stor@size
52 \chardef\ltj@@tempcctb@b=\numexpr\ltj@cctb@lower@stor@size+1\relax
53 \def\ltj@@copy@cctb#1#2{%
54 % Note: The current cctb number is supposed to be zero.
55 \luatexcatcodetable#1\relax
56 \luatexsavecatcodetable#2\relax
57 \luatexcatcodetable0\relax
62 % The luatexbase-cctb package stores its preset settings to
63 % registers 1--6, and new user allocations go to number 7, 8, ....
65 \ifdefined\lltxb@catcodetable@alloc
66 \ifnum\lltxb@catcodetable@alloc>\ltj@@cctb@lower@stor@safemax
67 % Failure: luatexbase-cctb alloc pointer is too high!
68 \ltj@@cctb@failure=2 %
71 % Failure: luatexbase-cctb not loaded!
72 \ltj@@cctb@failure=1 %
78 \gdef\ltj@@cctb@org@def#1{%
79 \ifnum\lltxb@catcodetable@alloc<65535\relax
80 \global\advance\lltxb@catcodetable@alloc\@ne
81 \allocationnumber\lltxb@catcodetable@alloc
82 \global\chardef#1\allocationnumber
83 \luatexinitcatcodetable\allocationnumber
84 \begingroup\escapechar\m@ne
85 \luatexbase@directlua{luatexbase.catcodetabledef_from_tex(
86 '\luatexluaescapestring{\string#1}', '\number\allocationnumber')}%
88 \wlog{\string#1=\string\luatexcatcodetable\the\allocationnumber}%
90 \errmessage{No room for a new \string\luatexcatcodetable}%
94 \unless\ifx\ltj@@cctb@org@def\newluatexcatcodetable
95 % Failure: luatexbase-cctb is not of expected version!
96 %%% \bebo <- the meaning of this control sequence?
97 \ltj@@cctb@failure=3 %
100 \ifdefined\LuT@AllocAttribute
101 \ifnum\LuT@AllocAttribute>\ltj@@cctb@lower@stor@safemax
102 % Failure: luatex-pkg alloc pointer is too high!
103 \ltj@@cctb@failure=4 %
106 \ifdefined\CatcodeTableStack
107 \ifnum\CatcodeTableStack>\ltj@@cctb@lower@stor@safemax
108 % Failure: luatex-pkg cctb-stack pointer is too high!
109 \ltj@@cctb@failure=5 %
113 \ltj@@cctb@check@failure
116 \newluatexcatcodetable\cctb@seven
118 \luatexsavecatcodetable\cctb@seven
122 %% Save the register 7 (to a temporary register)
123 \unless\ifnum\lltxb@catcodetable@alloc<7 %
124 \ltj@@copy@cctb{7}{\ltj@@tempcctb@a}
129 % The luatex package stores its preset settings to registers 1, 3, 5, 7
130 % and new user allocations go to odd number 9, 11, 13, etc.; registers
131 % with even number are reserved for the "category code table stack".
133 % I relocate all the future allocation by luatexbase-cctb to the "higher"
134 % area (number >= \ltj@cctb@lower@stor@size), which is simply done by
135 % moving the allocation pointer. And all the preset settings of
136 % luatexbase-cctb (those of luatex-pkg is a subset) are prepared again.
137 % The colliding user allocation cannot be helped, but in the fortunate
138 % case where luatex-pkg is not yet loaded or its allocating function
139 % is never invoked, the only endangered user allocation is register 7
140 % of luatexbase-cctb, which is rescued by simply reassining the table,
141 % since the all presets are migrated to the higher area.
143 \unless\ifdefined\LuT@AllocAttribute
145 \RequirePackage{luatex}[2010/03/01]
147 \input luatex.sty\relax
151 \edef\ltj@@tempa{\meaning\LuT@AllocAttribute}
152 \edef\ltj@@tempb{\meaning\lltxb@catcodetable@alloc}
153 \ifx\ltj@@tempa\ltj@@tempb
154 % Failure: luatexbase-cctb and luatex-pkg seem to be synchronized!
155 \ltj@@cctb@failure=6 %
157 \ltj@@cctb@check@failure
160 \ifdefined\CatcodeTableLaTeX \CatcodeTableLaTeX
162 % Failure: luatex-pkg is not of expected version!!
163 \ltj@@cctb@failure=100 %
166 \def\ltj@@cctb@org@def#1{
167 \ifnum\LuT@AllocCatcodeTable<1114110 %
168 \global\advance\LuT@AllocCatcodeTable by\tw@
169 \allocationnumber=\LuT@AllocCatcodeTable
170 \global\chardef#1=\allocationnumber
172 \string#1=\string\catcodetable\the\allocationnumber
175 \errmessage{No room for a new \string\catcodetable}
178 \unless\ifx\ltj@@cctb@org@def\newcatcodetable
179 % Failure: luatex-pkg is not of expected version!!
180 \ltj@@cctb@failure=100 %
183 \def\ltj@@cctb@org@def{%
184 \ifnum\CatcodeTableStack<268435454 %
185 \global\advance\CatcodeTableStack by\tw@
187 \@PackageError{luatex}{%
188 Catcode table stack overflow%
192 \unless\ifx\ltj@@cctb@org@def\IncCatcodeTableStack
193 % Failure: luatex-pkg is not of expected version!!
194 \ltj@@cctb@failure=100 %
196 \ltj@@cctb@check@failure
198 %% Restore the register 7 which is overwritten by luatex-pkg.
199 \unless\ifnum\lltxb@catcodetable@alloc<7 %
200 \ltj@@copy@cctb{\ltj@@tempcctb@a}{7}
203 %% Move the pointer of luatexbase-cctb to higher area.
204 \lltxb@catcodetable@alloc=\ltj@cctb@lower@stor@size
206 %% Restrict the allocation by luatex-pkg to lower area.
207 \chardef\ltj@@cctb@lower@stor@check=
208 \numexpr\ltj@cctb@lower@stor@size-2\relax
209 \def\newcatcodetable#1{
210 \ifnum\LuT@AllocCatcodeTable<\ltj@@cctb@lower@stor@check
211 \global\advance\LuT@AllocCatcodeTable by\tw@
212 \allocationnumber=\LuT@AllocCatcodeTable
213 \global\chardef#1=\allocationnumber
215 \string#1=\string\catcodetable\the\allocationnumber
218 \errmessage{No room for a new \string\catcodetable}
221 \def\IncCatcodeTableStack{%
222 \ifnum\CatcodeTableStack<\ltj@@cctb@lower@stor@check
223 \global\advance\CatcodeTableStack by\tw@
225 \@PackageError{luatex}{%
226 Catcode table stack overflow%
231 %------------------- Re-create the presets
233 \newluatexcatcodetable\CatcodeTableIniTeX
234 \newluatexcatcodetable\CatcodeTableString
235 \setluatexcatcodetable\CatcodeTableString{%
236 \luatexcatcodetable\CatcodeTableIniTeX
238 \catcode13 12 % carriage return
239 \catcode37 12 % percent
240 \setcatcoderange{65}{90}{12}% A-Z
241 \setcatcoderange{97}{122}{12}% a-z
242 \catcode92 12 % backslash
244 \newluatexcatcodetable\CatcodeTableOther
245 \setluatexcatcodetable\CatcodeTableOther{%
246 \luatexcatcodetable\CatcodeTableString
248 \newluatexcatcodetable\CatcodeTableLaTeX
249 \setluatexcatcodetable\CatcodeTableLaTeX{%
250 \luatexcatcodetable\CatcodeTableIniTeX
251 \setcatcoderange{0}{31}{15}%
253 \catcode12 13 % form feed
254 \catcode13 5 % carriage return
256 \catcode36 3 % dollar
257 \catcode38 4 % ampersand
258 \catcode94 7 % circumflex
259 \catcode95 8 % underscore
260 \catcode123 1 % brace left
261 \catcode125 2 % brace right
262 \catcode126 13 % tilde
264 \newluatexcatcodetable\CatcodeTableLaTeXAtLetter
265 \setluatexcatcodetable\CatcodeTableLaTeXAtLetter{%
266 \luatexcatcodetable\CatcodeTableLaTeX
268 \newluatexcatcodetable\CatcodeTableExpl
269 \setluatexcatcodetable\CatcodeTableExpl{%
270 \luatexcatcodetable\CatcodeTableLaTeX
271 \catcode126 10 % tilde is a space char
272 \catcode32 9 % space is ignored
273 \catcode9 9 % tab also ignored
274 \catcode95 11 % underscore letter
275 \catcode58 11 % colon letter
277 \luatexbase@directlua{luatexbase.catcodetable_do_shortcuts()}
279 %%------------------ all done