summaryrefslogtreecommitdiff
path: root/luatexbase-cctb.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'luatexbase-cctb.dtx')
-rw-r--r--luatexbase-cctb.dtx136
1 files changed, 79 insertions, 57 deletions
diff --git a/luatexbase-cctb.dtx b/luatexbase-cctb.dtx
index abcd6da..14988bc 100644
--- a/luatexbase-cctb.dtx
+++ b/luatexbase-cctb.dtx
@@ -1,8 +1,5 @@
% \iffalse meta-comment
%
-% Template : look for cctb DATE DESC VERSION !!!
-% and 'derived files' !!!
-%
% Written in 2009, 2010 by Manuel Pégourié-Gonnard and Élie Roux.
% <mpg@elzevir.fr>
% <elie.roux@telecom-bretagne.eu>
@@ -11,18 +8,14 @@
%
% This work consists of the main source file luatexbase-cctb.dtx
% and the derived files
-% luatexbase-cctb.sty cctb.lua ...
+% luatexbase-cctb.sty luatexbase.cctb.lua
+% test-cctb-plain.tex test-cctb-latex.tex
%
% Unpacking:
% tex luatexbase-cctb.dtx
% Documentation:
% pdflatex luatexbase-cctb.dtx
%
-% The class ltxdoc loads the configuration file ltxdoc.cfg
-% if available. Here you can specify further options, e.g.
-% use A4 as paper format:
-% \PassOptionsToClass{a4paper}{article}
-%
%<*ignore>
\begingroup
\def\x{LaTeX2e}%
@@ -51,7 +44,8 @@ This work is under the CC0 license.
This work consists of the main source file luatexbase-cctb.dtx
and the derived files
- luatexbase-cctb.sty cctb.lua ...
+ luatexbase-cctb.sty luatexbase.cctb.lua
+ test-cctb-plain.tex test-cctb-latex.tex
\endpreamble
@@ -94,12 +88,8 @@ and the derived files
\fi
%</ignore>
%<*driver>
-\NeedsTeXFormat{LaTeX2e}
-\ProvidesFile{luatexbase-cctb.drv}
- [DATE DESC]
\documentclass{ltxdoc}
-\EnableCrossrefs
-\CodelineIndex
+\input{lltxb-dtxstyle}
\begin{document}
\DocInput{luatexbase-cctb.dtx}%
\end{document}
@@ -124,10 +114,8 @@ and the derived files
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
%
-% \GetFileInfo{luatexbase-cctb.drv}
-%
-% \title{The \textsf{luatexbase-cctb} package}
-% \date{DATE}
+% \title{The \pk{luatexbase-cctb} package}
+% \date{v0.1 2010-03-26}
% \author{%
% Manuel P\'egouri\'e-Gonnard \\ \texttt{mpg@elzevir.fr} \and
% \'Elie Roux \\ \texttt{elie.roux@telecom-bretagne.eu}}
@@ -141,53 +129,101 @@ and the derived files
%
% \section{Implementation}
%
-% \subsection{\TeX\ package}
+% \subsection{\tex package}
%
% \begin{macrocode}
%<*texpackage>
% \end{macrocode}
%
-% Here we allocate catcodetables the same way we handle attributes.
+% \subsubsection{Preliminaries}
+%
+% Reload protection, especially for \plaintex.
+%
+% \begin{macrocode}
+ \csname lltxb@cctb@loaded\endcsname
+\expandafter\let\csname lltxb@cctb@loaded\endcsname\endinput
+% \end{macrocode}
+%
+% Package declaration.
+%
+% \begin{macrocode}
+\begingroup
+ \expandafter\ifx\csname ProvidesPackage\endcsname\relax
+ \def\x#1[#2]{\immediate\write16{Package: #1 #2}}
+ \else
+ \let\x\ProvidesPackage
+ \fi
+\expandafter\endgroup
+\x{luatexbase-attr}[2010/03/26 v0.1 Catcodetable allocation for LuaTeX (mpg)]
+% \end{macrocode}
+%
+% Make sure \luatex is used.
+%
+% \begin{macrocode}
+\begingroup\expandafter\expandafter\expandafter\endgroup
+\expandafter\ifx\csname RequirePackage\endcsname\relax
+ \input ifluatex.sty
+\else
+ \RequirePackage{ifluatex}
+\fi
+\ifluatex\else
+ \begingroup
+ \expandafter\ifx\csname PackageWarningNoLine\endcsname\relax
+ \def\x#1#2{\begingroup\newlinechar10
+ \immediate\write16{Package #1 warning: #2}\endgroup}
+ \else
+ \let\x\PackageWarningNoLine
+ \fi
+ \expandafter\endgroup
+ \x{luatexbase-cctb}{LuaTeX is required for this package.^^J
+ Aborting package loading.}
+ \expandafter\endinput
+\fi
+% \end{macrocode}
+%
+% Make sure the catcode of @ is correct, especially for \plaintex.
+%
+% \begin{macrocode}
+\expandafter\edef\csname lltxb@cctb@AtEnd\endcsname{%
+ \catcode64 \the\catcode64\relax}
+\catcode64 11
+% \end{macrocode}
+%
+% \subsubsection{Main content}
+%
+% Load the supporting Lua module.
+%
+% \begin{macrocode}
+\directlua{dofile(kpse.find_file('luatexbase.cctb.lua', 'lua'))}
+% \end{macrocode}
+%
+% The allocation macro.
%
% \begin{macrocode}
-
\newcount\luatexcatcodetabledefcounter
-
\luatexcatcodetabledefcounter = 1
-
\def\newluatexcatcodetable#1{%
\ifnum\luatexcatcodetabledefcounter<1114110\relax % 0x10FFFF is maximal \chardef
- \global\advance\luatexcatcodetabledefcounter by 1\relax %
- \allocationnumber=\luatexcatcodetabledefcounter %
- \global\chardef#1=\allocationnumber %
+ \global\advance\luatexcatcodetabledefcounter by 1\relax
+ \allocationnumber=\luatexcatcodetabledefcounter
+ \global\chardef#1=\allocationnumber
\luadirect{%
luatextra.catcodetabledef_from_tex([[\noexpand#1]], '\number\allocationnumber')}%
\wlog{\string#1=\string\catcodetable\the\allocationnumber}%
- \else %
+ \else
\errmessage{No room for a new \string\catcodetable}%
- \fi %
-}
-
+ \fi}
% \end{macrocode}
%
-% A small patch to manage the catcode of \@ in Plain, and to get two new
-% counters in Plain too.
+% A small patch to get two new counters in Plain too.
%
% \begin{macrocode}
-
-\expandafter\edef\csname ltxtra@AtEnd\endcsname{%
- \catcode64 \the\catcode64\relax
-}
-
-\catcode 64=11\relax
-
\expandafter\ifx\csname @tempcnta\endcsname\relax
\csname newcount\endcsname\@tempcnta
\fi
\expandafter\ifx\csname @tempcntb\endcsname\relax
\csname newcount\endcsname\@tempcntb
\fi
-
% \end{macrocode}
%
% A macro that sets the catcode of a range of characters. The first
@@ -196,7 +232,6 @@ and the derived files
% parameter is the catcode we want them to have.
%
% \begin{macrocode}
-
\def\luatexsetcatcoderange#1#2#3{%
\edef\luaSCR@temp{%
\noexpand\@tempcnta=\the\@tempcnta
@@ -211,9 +246,7 @@ and the derived files
\catcode\@tempcnta=\count@
\advance\@tempcnta by 1\relax
\repeat
- \luaSCR@temp
-}
-
+ \luaSCR@temp}
% \end{macrocode}
%
% Finally we create several catcodetables that may be used by the user.
@@ -232,7 +265,6 @@ and the derived files
% \end{itemize}
%
% \begin{macrocode}
-
\newluatexcatcodetable\CatcodeTableIniTeX
\newluatexcatcodetable\CatcodeTableString
\newluatexcatcodetable\CatcodeTableOther
@@ -299,11 +331,7 @@ and the derived files
\saveluatexcatcodetable\CatcodeTableOther
\endgroup
}
-
-\ltxtra@AtEnd
-
-\luadirect{luatextra.catcodetable_do_shortcuts()}
-
+\directlua{luatextra.catcodetable_do_shortcuts()}
% \end{macrocode}
%
% \begin{macrocode}
@@ -321,16 +349,12 @@ and the derived files
% \texttt{\string\newluacatcodetable}.
%
% \begin{macrocode}
-
luatextra.catcodetables = {}
-
tex.catcodetablenumber = luatextra.catcodetables
-
function luatextra.catcodetabledef_from_tex(name, number)
truename = name:gsub('[\\ ]', '')
luatextra.catcodetables[truename] = tonumber(number)
end
-
% \end{macrocode}
%
% With this function we create some shortcuts for a
@@ -339,7 +363,6 @@ end
% |tex.catcodetablenumber['CatcodeTableLaTeX']|.
%
% \begin{macrocode}
-
function luatextra.catcodetable_do_shortcuts()
local cat = tex.catcodetablenumber
local val = cat['CatcodeTableLaTeX']
@@ -369,7 +392,6 @@ function luatextra.catcodetable_do_shortcuts()
cat['other'] = val
end
end
-
% \end{macrocode}
%
% \begin{macrocode}