summaryrefslogtreecommitdiff
path: root/luatexbase-cctb.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'luatexbase-cctb.dtx')
-rw-r--r--luatexbase-cctb.dtx89
1 files changed, 59 insertions, 30 deletions
diff --git a/luatexbase-cctb.dtx b/luatexbase-cctb.dtx
index 09ff77f..90dab94 100644
--- a/luatexbase-cctb.dtx
+++ b/luatexbase-cctb.dtx
@@ -8,7 +8,7 @@
%
% This work consists of the main source file luatexbase-cctb.dtx
% and the derived files
-% luatexbase-cctb.sty luatexbase.cctb.lua
+% luatexbase-cctb.sty cctb.lua
% test-cctb-plain.tex test-cctb-latex.tex
%
% Unpacking:
@@ -66,7 +66,7 @@ See source file '\inFileName' for details.
\generate{%
\usedir{tex/luatex/luatexbase}%
- \file{luatexbase.cctb.lua}{\from{luatexbase-cctb.dtx}{luamodule}}%
+ \file{cctb.lua}{\from{luatexbase-cctb.dtx}{luamodule}}%
}
\obeyspaces
@@ -75,7 +75,7 @@ See source file '\inFileName' for details.
\Msg{* To finish the installation you have to move the following}
\Msg{* files into a directory searched by TeX:}
\Msg{*}
-\Msg{* luatexbase-cctb.sty luatexbase.cctb.lua}
+\Msg{* luatexbase-cctb.sty cctb.lua}
\Msg{*}
\Msg{* Happy TeXing!}
\Msg{*}
@@ -127,6 +127,8 @@ See source file '\inFileName' for details.
% allocation just like Plain TeX and LaTeX do for other registers.
% \end{abstract}
%
+% \tableofcontents
+%
% \section{Documentation}
%
% The main macro defined here is |\newluatexcatcodetable|. It behaves the same
@@ -135,7 +137,7 @@ See source file '\inFileName' for details.
% (once they are allocated), two helper macros are available.
%
% \begin{quote}
-% \cs{luatexsetcatcoderange}\marg{from}\marg{to}\marg{value}
+% \cs{setcatcoderange}\marg{from}\marg{to}\marg{value}
% \end{quote}
% Set all characters code in the range \meta{from}--\meta{to} to the given
% catcode \meta{value}.
@@ -168,7 +170,7 @@ See source file '\inFileName' for details.
% catcode table. Since |\chardef| is used for the definition of the control
% sequence, this is rather easy to do. However, for extra ease of use, the
% numbers are also directly accessible from Lua as the value of the table
-% |luatextra.catcodetables|, whose keys is the name of the control sequence
+% |luatexbase.catcodetables|, whose keys is the name of the control sequence
% (without any leading backslash). Moreover, nickames are available for the
% predefined catcode tables:
% \begin{itemize}
@@ -244,7 +246,7 @@ See source file '\inFileName' for details.
\let\x\ProvidesPackage
\fi
\expandafter\endgroup
-\x{luatexbase-cctb}[2010/03/26 v0.1 Catcodetable allocation for LuaTeX (mpg)]
+\x{luatexbase-cctb}[2010/03/26 v0.1 Catcodetable allocation for LuaTeX]
% \end{macrocode}
%
% Make sure \luatex is used.
@@ -271,9 +273,10 @@ See source file '\inFileName' for details.
\fi
% \end{macrocode}
%
-% \subsubsection{Main content}
+% \subsubsection{Load supporting Lua module}
%
-% Load the supporting Lua module.
+% First load \pk{luatexbase-loader} (hence \pk{luatexbase-compat}), then
+% the supporting Lua module.
%
% \begin{macrocode}
\begingroup\expandafter\expandafter\expandafter\endgroup
@@ -282,9 +285,33 @@ See source file '\inFileName' for details.
\else
\RequirePackage{luatexbase-loader}
\fi
-\directlua{require('luatexbase.cctb.lua')}
+\luatexbase@directlua{require('luatexbase.cctb')}
+% \end{macrocode}
+%
+% \subsubsection{Primitives needed}
+%
+% Load \pk{luatexbase-compat}.
+%
+% \begin{macrocode}
+\begingroup\expandafter\expandafter\expandafter\endgroup
+\expandafter\ifx\csname RequirePackage\endcsname\relax
+ \input luatexbase-compat.sty
+\else
+ \RequirePackage{luatexbase-compat}
+\fi
+% \end{macrocode}
+%
+% Make sure the primitives we need are available.
+%
+% \begin{macrocode}
+\luatexbase@ensure@primitive{luaescapestring}
+\luatexbase@ensure@primitive{catcodetable}
+\luatexbase@ensure@primitive{initcatcodetable}
+\luatexbase@ensure@primitive{savecatcodetable}
% \end{macrocode}
%
+% \subsubsection{User macros}
+%
% The allocation macro. Allocate tables starting with 1, since table 0 is
% reserved for IniTeX catcodes by LuaTeX.
%
@@ -297,9 +324,10 @@ See source file '\inFileName' for details.
\allocationnumber\lltxb@catcodetable@alloc
\global\chardef#1\allocationnumber
\luatexinitcatcodetable\allocationnumber
- \begingroup\escapechar\m@ne \expandafter\endgroup
- \directlua{luatextra.catcodetabledef_from_tex(
+ \begingroup\escapechar\m@ne
+ \luatexbase@directlua{luatexbase.catcodetabledef_from_tex(
'\luatexluaescapestring{\string#1}', '\number\allocationnumber')}%
+ \endgroup
\wlog{\string#1=\string\luatexcatcodetable\the\allocationnumber}%
\else
\errmessage{No room for a new \string\luatexcatcodetable}%
@@ -320,7 +348,7 @@ See source file '\inFileName' for details.
% Set the catcodes for a range of characters.
%
% \begin{macrocode}
-\def\luatexsetcatcoderange#1#2#3{%
+\def\setcatcoderange#1#2#3{%
\edef\luaSCR@temp{%
\noexpand\@tempcnta=\the\@tempcnta
\noexpand\@tempcntb=\the\@tempcntb
@@ -346,6 +374,8 @@ See source file '\inFileName' for details.
\endgroup}
% \end{macrocode}
%
+% \subsubsection{Predefined tables}
+%
% The |IniTeX| catcode table needs no extra initialisation.
%
% \begin{macrocode}
@@ -361,8 +391,8 @@ See source file '\inFileName' for details.
\catcode0 12 % nul
\catcode13 12 % carriage return
\catcode37 12 % percent
- \luatexsetcatcoderange{65}{90}{12}% A-Z
- \luatexsetcatcoderange{97}{122}{12}% a-z
+ \setcatcoderange{65}{90}{12}% A-Z
+ \setcatcoderange{97}{122}{12}% a-z
\catcode92 12 % backslash
\catcode127 12 }
% \end{macrocode}
@@ -380,7 +410,7 @@ See source file '\inFileName' for details.
\newluatexcatcodetable\CatcodeTableLaTeX
\setluatexcatcodetable\CatcodeTableLaTeX{%
\luatexcatcodetable\CatcodeTableIniTeX
- \luatexsetcatcoderange{0}{31}{15}%
+ \setcatcoderange{0}{31}{15}%
\catcode9 10 % tab
\catcode12 13 % form feed
\catcode13 5 % carriage return
@@ -419,7 +449,7 @@ See source file '\inFileName' for details.
% Finally do the shortcuts.
%
% \begin{macrocode}
-\directlua{luatextra.catcodetable_do_shortcuts()}
+\luatexbase@directlua{luatexbase.catcodetable_do_shortcuts()}
% \end{macrocode}
%
% That's all, folks!
@@ -433,28 +463,26 @@ See source file '\inFileName' for details.
%
% \begin{macrocode}
%<*luamodule>
-module('luatextra', package.seeall)
+module('luatexbase', package.seeall)
% \end{macrocode}
%
-% In the same way, the table \texttt{tex.catcodetablenumber} contains the
-% numbers of the catcodetables registered with
-% \texttt{\string\newluacatcodetable}.
+% The number associated to a CS name is remembered in the |catcodetables|
+% table.
%
% \begin{macrocode}
catcodetables = {}
-tex.catcodetablenumber = catcodetables
function catcodetabledef_from_tex(name, number)
catcodetables[name] = tonumber(number)
end
% \end{macrocode}
%
-% With this function we create some shortcuts for a better readability in
-% lua code. This makes |tex.catcodetablenumber.latex| equivalent to
-% |tex.catcodetablenumber['CatcodeTableLaTeX']|.
+% The next function creates some shortcuts for better readability in lua
+% code. This makes |luatexbase.catcodetables.latex| equivalent to
+% |luatexbase.catcodetables.CatcodeTableLaTeX|.
%
% \begin{macrocode}
function catcodetable_do_shortcuts()
- local cat = luatextra.catcodetables
+ local cat = catcodetables
cat['latex'] = cat.CatcodeTableLaTeX
cat['latex-package'] = cat.CatcodeTableLaTeXAtLetter
cat['latex-atletter'] = cat.CatcodeTableLaTeXAtLetter
@@ -480,19 +508,20 @@ end
%<testplain>\input luatexbase-cctb.sty
%<testlatex>\RequirePackage{luatexbase-cctb}
%<*testplain,testlatex>
-\newluatexcatcodetable\testcctb
-\directlua{assert(luatextra.catcodetables.testcctb)}
+\begingroup \catcode64 11 \global\let\lua\luatexbase@directlua \endgroup
% \end{macrocode}
%
% Also check that the catcodetable's number is remembered well,
% independently of the current value of |\escapechar|.
% \begin{macrocode}
+\newluatexcatcodetable\testcctb
+\lua{assert(luatexbase.catcodetables.testcctb)}
\begingroup
\escapechar64
\newluatexcatcodetable\anothercctb
\endgroup
-\directlua{assert(luatextra.catcodetables.anothercctb)}
+\lua{assert(luatexbase.catcodetables.anothercctb)}
% \end{macrocode}
%
% Now, play a little bit with predefined tables.
@@ -503,9 +532,9 @@ end
\luatexcatcodetable\CatcodeTableLaTeX
\ifnum\catcode64=12 \else \ERROR \fi
%<testlatex>\documentclass{minimal}
-\directlua{%
+\lua{%
tex.sprint('\string\\setbox0=\string\\hbox{')
- tex.sprint(luatextra.catcodetables.string, "\string\\undef # _^&")
+ tex.sprint(luatexbase.catcodetables.string, "\string\\undef # _^&")
tex.sprint('}')
}
% \end{macrocode}