diff options
-rw-r--r-- | Changes | 13 | ||||
-rw-r--r-- | Makefile | 26 | ||||
-rw-r--r-- | README | 10 | ||||
-rw-r--r-- | TODO | 34 | ||||
-rw-r--r-- | luamcallbacks.dtx | 39 | ||||
-rw-r--r-- | luatexbase-attr.dtx | 71 | ||||
-rw-r--r-- | luatexbase-cctb.dtx | 70 | ||||
-rw-r--r-- | luatexbase-loader.dtx | 64 | ||||
-rw-r--r-- | luatexbase-modutils.dtx | 561 | ||||
-rw-r--r-- | luatexbase-regs.dtx | 62 |
10 files changed, 812 insertions, 138 deletions
@@ -9,6 +9,19 @@ - don't create tex.catcodetablenumber - rename \luatexsetcatcoderange to \setcatcoderange +2010/03/28 + luatexbase-* + - add catcode defenses + +2010/03/27 + luatexbase-loader 0.1 + - add very minimal test files for luatex and lualatex + luatexbase-modutils 0.1 + - add minimal test files for luatex and lualatex + - use require() (with luatexbase-loader) for loading + luatexbase-attr, luatexbase-cctb, luamcallbacks (test file) + - use luatexbase-loader + 2010/03/26 luatexbase-cctb 0.1 - add minimal test files for luatex and lualatex @@ -4,6 +4,8 @@ NAME = luatexbase DTX = $(wildcard *.dtx) DOC = $(patsubst %.dtx, %.pdf, $(DTX)) DTXSTY = lltxb-dtxstyle.tex +LOADER_RUN = luatexbase-loader.sty luatexbase.loader.lua +MOD_RUN = luatexbase-modutils.sty luatexbase.modutils.lua # Files grouped by generation mode UNPACKED_MCB = test-luamcallbacks.tex luamcallbacks.lua @@ -13,10 +15,12 @@ UNPACKED_ATTR = luatexbase-attr.sty luatexbase.attr.lua \ test-attr-plain.tex test-attr-latex.tex UNPACKED_CCTB = luatexbase-cctb.sty luatexbase.cctb.lua \ test-cctb-plain.tex test-cctb-latex.tex -UNPACKED_LOADER = luatexbase-loader.sty luatexbase.loader.lua \ +UNPACKED_LOADER = $(LOADER_RUN) \ test-loader-plain.tex test-loader-latex.tex +UNPACKED_MODUTILS = $(MOD_RUN) \ + test-modutils-plain.tex test-modutils-latex.tex test-modutils.lua UNPACKED = $(UNPACKED_MCB) $(UNPACKED_REGS) $(UNPACKED_ATTR) $(UNPACKED_CCTB) \ - $(UNPACKED_LOADER) + $(UNPACKED_LOADER) $(UNPACKED_MODUTILS) COMPILED = $(DOC) GENERATED = $(COMPILED) $(UNPACKED) SOURCE = $(DTX) $(DTXSTY) README TODO Changes Makefile @@ -47,7 +51,7 @@ DO_MAKEINDEX = makeindex -s gind.ist $(subst .dtx,,$<) >/dev/null 2>&1 # Main targets definition all: $(GENERATED) -check: check-regs check-attr check-cctb check-load +check: check-regs check-attr check-cctb check-loader check-modutils check-mcb doc: $(COMPILED) unpack: $(UNPACKED) ctan: check $(CTAN_ZIP) @@ -75,15 +79,18 @@ $(UNPACKED_CCTB): luatexbase-cctb.dtx $(UNPACKED_LOADER): luatexbase-loader.dtx $(DO_TEX) +$(UNPACKED_MODUTILS): luatexbase-modutils.dtx + $(DO_TEX) + check-regs: $(UNPACKED_REGS) luatex --interaction=batchmode test-regs-plain.tex >/dev/null lualatex --interaction=batchmode test-regs-latex.tex >/dev/null -check-attr: $(UNPACKED_ATTR) +check-attr: $(UNPACKED_ATTR) $(LOADER_RUN) luatex --interaction=batchmode test-attr-plain.tex >/dev/null lualatex --interaction=batchmode test-attr-latex.tex >/dev/null -check-cctb: $(UNPACKED_CCTB) +check-cctb: $(UNPACKED_CCTB) $(LOADER_RUN) luatex --interaction=batchmode test-cctb-plain.tex >/dev/null lualatex --interaction=batchmode test-cctb-latex.tex >/dev/null @@ -91,6 +98,13 @@ check-loader: $(UNPACKED_LOADER) luatex --interaction=batchmode test-loader-plain.tex >/dev/null lualatex --interaction=batchmode test-loader-latex.tex >/dev/null +check-modutils: $(UNPACKED_MODUTILS) $(LOADER_RUN) + luatex --interaction=batchmode test-modutils-plain.tex >/dev/null + lualatex --interaction=batchmode test-modutils-latex.tex >/dev/null + +check-mcb: $(UNPACKED_MCB) $(LOADER_RUN) $(MOD_RUN) + luatex --interaction=batchmode test-luamcallbacks.tex >/dev/null + $(CTAN_ZIP): $(SOURCE) $(COMPILED) $(TDS_ZIP) @echo "Making $@ for CTAN upload." @$(RM) -- $@ @@ -124,7 +138,7 @@ manifest: @for f in $(GENERATED); do echo $$f; done clean: - @$(RM) -- *.log *.aux *.toc *.idx *.ind *.ilg *.out + @$(RM) -- *.log *.aux *.toc *.idx *.ind *.ilg *.out test-*.pdf mrproper: clean @$(RM) -- $(GENERATED) $(ZIPS) @@ -5,17 +5,19 @@ luatexbase provides basic resource management, similar to the way TeX resources are handled by Plain TeX and LaTeX, for new resources introduced by LuaTeX. -Each resource is handled in a separate package, and luatexbase.sty merely loads -all of them. +Each resource is handled in a separate package. The resources considered are: - registers (\count, \box, etc.) -> luatexbase-regs -- Lua modules -> luatexbase-loader -- Additional functions for modules -> luatexbase-modutils +- Lua module loading -> luatexbase-loader - \attribute's -> luatexbase-attr - \catcodetable's -> luatexbase-cctb - Lua callbacks -> luamcallbacks +Additional convenience packages: +- Lua module declaration -> luatexbase-modutils +- compatibility helpers -> luatexbase-compat + WARNING: these packages are subject to change or even be merged or disappear in the near future! @@ -1,27 +1,27 @@ general ------- -- write test files -- change prefix for internal TeX macros -- check for lua name conflicts ('module' used in mods) -- make TeX tests cleaner: \begingroup\expandafter\ETC. -- reload check, declaration, luatex test, catcodes for plain -- import/update doc -- date & changes entry - -- redo module loading in packages once mods is done. -- adjust preamble to avoid duplicated list of files (refer to DTX instead) +- check for user macros starting with \luatex +- change lua module name(s) (luatexbase or luatexbase.regs etc) +- check for macros starting with \luatex +- compat with LuaTeX 0.25.4? (Means problems with \directlua, primitive names, + kpse.find_file(..., 'lua'), etc.) Maybe do a compat package? loader ------ -- a.b.c -> a/b/c or a/b.c or a.b.c +- a.b.c -> a/b/c or a/b.c or a.b.c? What do to with files under texmf/scripts? +- adujst names of the modules afterwards +- write doc +- make a real test using a fake texmf tree as TEXMFHOME? -Later -===== +modutils +-------- -- change lua module name(s) (luatexbase or luatexbase.regs etc) -- check for macros starting with \luatex -- compat with LuaTeX 0.25.4? (Means problems with \directlua, primitive names, - kpse.find_file(..., 'lua'), etc.) +Review extensively. + +mcallbacks +---------- + +Review extensively. diff --git a/luamcallbacks.dtx b/luamcallbacks.dtx index 6b06b24..c2d94f9 100644 --- a/luamcallbacks.dtx +++ b/luamcallbacks.dtx @@ -14,11 +14,6 @@ % Documentation: % pdflatex luamcallbacks.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}% @@ -30,10 +25,6 @@ %</ignore> %<*install> \input docstrip.tex -\Msg{************************************************************************} -\Msg{* Installation} -\Msg{* Package: luamcallbacks 2009/09/18 v0.93 LuaTeX multiple callbacks.} -\Msg{************************************************************************} \keepsilent \askforoverwritefalse @@ -41,28 +32,21 @@ \let\MetaPrefix\relax \preamble -This is a generated file. Copyright (C) 2009 by Elie Roux <elie.roux@telecom-bretagne.eu> This work is under the CC0 license. - -This work consists of the main source file luamcallbacks.dtx -and the derived files - luamcallbacks.lua, test-luamcallbacks.tex, luamcallbacks.pdf. +See source file '\inFileName' for details. \endpreamble \let\MetaPrefix\DoubleperCent \generate{% - \usedir{doc/luatex/luatextra}% + \usedir{doc/luatex/luatexbase}% \file{test-luamcallbacks.tex}{\from{luamcallbacks.dtx}{test}}% } -% The following hacks are to generate a lua file with lua comments starting by -% -- instead of %% - \def\MetaPrefix{-- } \def\luapostamble{% @@ -73,7 +57,7 @@ and the derived files \def\currentpostamble{\luapostamble}% \generate{% - \usedir{tex/luatex/luatextra}% + \usedir{tex/luatex/luatexbase}% \file{luamcallbacks.lua}{\from{luamcallbacks.dtx}{lua}}% } @@ -95,19 +79,15 @@ and the derived files \fi %</ignore> %<*driver> -\NeedsTeXFormat{LaTeX2e} -\ProvidesFile{luamcallbacks.drv} - [2009/09/18 v0.93 LuaTeX multiple callbacks package] \documentclass{ltxdoc} -\EnableCrossrefs -\CodelineIndex +\input{lltxb-dtxstyle} \begin{document} \DocInput{luamcallbacks.dtx}% \end{document} %</driver> % \fi % -% \CheckSum{5} +% \CheckSum{0} % % \CharacterTable % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z @@ -139,6 +119,8 @@ and the derived files % \texttt{callback.register}. It also allows to create and call new callbacks. % For an introduction on this package (among others), please refer to the % document \texttt{luatextra-reference.pdf}. +% \par\textbf{Warning.} Currently assumes that \textsf{luatexbase-modutils} +% has been previously loaded. (This is a temporary limitation.) % \end{abstract} % % \section{Documentation} @@ -803,15 +785,16 @@ end % get a non-empty document. % % \begin{macrocode} -\input luatextra.sty - +\input luatexbase-loader.sty +\input luatexbase-modutils.sty +\directlua{require "luamcallbacks"} This is just a test file. % \end{macrocode} % % Then we declare three functions that we will use. % % \begin{macrocode} -\luadirect{ +\directlua{ local function one(head,...) texio.write_nl("I'm number 1") return head, true diff --git a/luatexbase-attr.dtx b/luatexbase-attr.dtx index 7b192c6..1580168 100644 --- a/luatexbase-attr.dtx +++ b/luatexbase-attr.dtx @@ -9,7 +9,7 @@ % This work consists of the main source file luatexbase-attr.dtx % and the derived files % luatexbase-attr.sty luatexbase.attr.lua -% test-regs-plain.tex test-regs-latex.tex +% test-regs-plain.tex test-regs-latex.tex % % Unpacking: % tex luatexbase-attr.dtx @@ -34,17 +34,11 @@ \let\MetaPrefix\relax \preamble -This is a generated file. -Written in 2009, 2010 by Manuel Pégourié-Gonnard and Élie Roux. - <mpg@elzevir.fr> - <elie.roux@telecom-bretagne.eu> +Written in 2009, 2010 by Manuel Pegourie-Gonnard and Elie Roux. This work is under the CC0 license. - -This work consists of the main source file luatexbase-attr.dtx -and the derived files - luatexbase-attr.sty luatexbase.attr.lua ... +See source file '\inFileName' for details. \endpreamble @@ -81,7 +75,7 @@ and the derived files \Msg{* To finish the installation you have to move the following} \Msg{* files into a directory searched by TeX:} \Msg{*} -\Msg{* luatexbase-attr.sty luatexbase.attr.lua ...} +\Msg{* luatexbase-attr.sty luatexbase.attr.lua} \Msg{*} \Msg{* Happy TeXing!} \Msg{*} @@ -180,6 +174,43 @@ and the derived files \expandafter\let\csname lltxb@attr@loaded\endcsname\endinput % \end{macrocode} % +% Catcode defenses. +% +% \begin{macrocode} +\begingroup + \catcode123 1 % { + \catcode125 2 % } + \catcode 35 6 % # + \toks0{}% + \def\x{}% + \def\y#1 #2 {% + \toks0\expandafter{\the\toks0 \catcode#1 \the\catcode#1}% + \edef\x{\x \catcode#1 #2}}% + \y 123 1 % { + \y 125 2 % } + \y 35 6 % # + \y 10 12 % ^^J + \y 34 12 % " + \y 36 3 % $ $ + \y 39 12 % ' + \y 40 12 % ( + \y 41 12 % ) + \y 42 12 % * + \y 43 12 % + + \y 44 12 % , + \y 45 12 % - + \y 46 12 % . + \y 47 12 % / + \y 60 12 % < + \y 61 12 % = + \y 64 11 % @ (letter) + \y 62 12 % > + \y 95 12 % _ (other) + \y 96 12 % ` + \edef\y#1{\endgroup\edef#1{\the\toks0\relax}\x}% +\expandafter\y\csname lltxb@attr@AtEnd\endcsname +% \end{macrocode} +% % Package declaration. % % \begin{macrocode} @@ -211,26 +242,24 @@ and the derived files \let\x\PackageWarningNoLine \fi \expandafter\endgroup - \x{luatexbase-attr}{LuaTeX is required for this package.^^J - Aborting package loading.} + \x{luatexbase-attr}{LuaTeX is required for this package. Aborting.} + \lltxb@attr@AtEnd \expandafter\endinput \fi % \end{macrocode} % -% Make sure the catcode of @ is correct, especially for \plaintex. -% -% \begin{macrocode} -\expandafter\edef\csname lltxb@attr@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.attr.lua', 'lua'))} +\begingroup\expandafter\expandafter\expandafter\endgroup +\expandafter\ifx\csname RequirePackage\endcsname\relax + \input luatexbase-loader.sty +\else + \RequirePackage{luatexbase-loader} +\fi +\directlua{require('luatexbase.attr.lua')} % \end{macrocode} % % The allocaton macro. diff --git a/luatexbase-cctb.dtx b/luatexbase-cctb.dtx index 3bfedac..3565fd0 100644 --- a/luatexbase-cctb.dtx +++ b/luatexbase-cctb.dtx @@ -34,18 +34,11 @@ \let\MetaPrefix\relax \preamble -This is a generated file. -Written in 2009, 2010 by Manuel Pégourié-Gonnard and Élie Roux. - <mpg@elzevir.fr> - <elie.roux@telecom-bretagne.eu> +Written in 2009, 2010 by Manuel Pegourie-Gonnard and Elie Roux. 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 luatexbase.cctb.lua - test-cctb-plain.tex test-cctb-latex.tex +See source file '\inFileName' for details. \endpreamble @@ -82,7 +75,7 @@ and the derived files \Msg{* To finish the installation you have to move the following} \Msg{* files into a directory searched by TeX:} \Msg{*} -\Msg{* luatexbase-cctb.sty cctb.lua ...} +\Msg{* luatexbase-cctb.sty luatexbase.cctb.lua} \Msg{*} \Msg{* Happy TeXing!} \Msg{*} @@ -204,6 +197,43 @@ and the derived files \expandafter\let\csname lltxb@cctb@loaded\endcsname\endinput % \end{macrocode} % +% Catcode defenses. +% +% \begin{macrocode} +\begingroup + \catcode123 1 % { + \catcode125 2 % } + \catcode 35 6 % # + \toks0{}% + \def\x{}% + \def\y#1 #2 {% + \toks0\expandafter{\the\toks0 \catcode#1 \the\catcode#1}% + \edef\x{\x \catcode#1 #2}}% + \y 123 1 % { + \y 125 2 % } + \y 35 6 % # + \y 10 12 % ^^J + \y 34 12 % " + \y 36 3 % $ $ + \y 39 12 % ' + \y 40 12 % ( + \y 41 12 % ) + \y 42 12 % * + \y 43 12 % + + \y 44 12 % , + \y 45 12 % - + \y 46 12 % . + \y 47 12 % / + \y 60 12 % < + \y 61 12 % = + \y 64 11 % @ (letter) + \y 62 12 % > + \y 95 12 % _ (other) + \y 96 12 % ` + \edef\y#1{\endgroup\edef#1{\the\toks0\relax}\x}% +\expandafter\y\csname lltxb@cctb@AtEnd\endcsname +% \end{macrocode} +% % Package declaration. % % \begin{macrocode} @@ -235,26 +265,24 @@ and the derived files \let\x\PackageWarningNoLine \fi \expandafter\endgroup - \x{luatexbase-cctb}{LuaTeX is required for this package.^^J - Aborting package loading.} + \x{luatexbase-cctb}{LuaTeX is required for this package. Aborting.} + \lltxb@cctb@AtEnd \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'))} +\begingroup\expandafter\expandafter\expandafter\endgroup +\expandafter\ifx\csname RequirePackage\endcsname\relax + \input luatexbase-loader.sty +\else + \RequirePackage{luatexbase-loader} +\fi +\directlua{require('luatexbase.cctb.lua')} % \end{macrocode} % % The allocation macro. Allocate tables starting with 1, since table 0 is diff --git a/luatexbase-loader.dtx b/luatexbase-loader.dtx index b413a46..695efe6 100644 --- a/luatexbase-loader.dtx +++ b/luatexbase-loader.dtx @@ -34,18 +34,11 @@ \let\MetaPrefix\relax \preamble -This is a generated file. -Written in 2009, 2010 by Manuel Pégourié-Gonnard and Élie Roux. - <mpg@elzevir.fr> - <elie.roux@telecom-bretagne.eu> +Written in 2009, 2010 by Manuel Pegourie-Gonnard and Elie Roux. This work is under the CC0 license. - -This work consists of the main source file luatexbase-loader.dtx -and the derived files - luatexbase-loader.sty luatexbase.loader.lua - test-loader-plain.tex test-loader-latex.tex +See source file '\inFileName' for details. \endpreamble @@ -82,7 +75,7 @@ and the derived files \Msg{* To finish the installation you have to move the following} \Msg{* files into a directory searched by TeX:} \Msg{*} -\Msg{* luatexbase-loader.sty loader.lua ...} +\Msg{* luatexbase-loader.sty luatex.loader.lua} \Msg{*} \Msg{* Happy TeXing!} \Msg{*} @@ -120,7 +113,7 @@ and the derived files % Grave accent \` Left brace \{ Vertical bar \| % Right brace \} Tilde \~} % -% \title{The \textsf{luatexbase-loader} package} +% \title{The \pk{luatexbase-loader} package} % \date{v0.1 2010-03-27} % \author{% % Manuel P\'egouri\'e-Gonnard \\ \texttt{mpg@elzevir.fr} \and @@ -150,6 +143,43 @@ and the derived files \expandafter\let\csname lltxb@loader@loaded\endcsname\endinput % \end{macrocode} % +% Catcode defenses. +% +% \begin{macrocode} +\begingroup + \catcode123 1 % { + \catcode125 2 % } + \catcode 35 6 % # + \toks0{}% + \def\x{}% + \def\y#1 #2 {% + \toks0\expandafter{\the\toks0 \catcode#1 \the\catcode#1}% + \edef\x{\x \catcode#1 #2}}% + \y 123 1 % { + \y 125 2 % } + \y 35 6 % # + \y 10 12 % ^^J + \y 34 12 % " + \y 36 3 % $ $ + \y 39 12 % ' + \y 40 12 % ( + \y 41 12 % ) + \y 42 12 % * + \y 43 12 % + + \y 44 12 % , + \y 45 12 % - + \y 46 12 % . + \y 47 12 % / + \y 60 12 % < + \y 61 12 % = + \y 64 11 % @ (letter) + \y 62 12 % > + \y 95 12 % _ (other) + \y 96 12 % ` + \edef\y#1{\endgroup\edef#1{\the\toks0\relax}\x}% +\expandafter\y\csname lltxb@loader@AtEnd\endcsname +% \end{macrocode} +% % Package declaration. % % \begin{macrocode} @@ -181,20 +211,12 @@ and the derived files \let\x\PackageWarningNoLine \fi \expandafter\endgroup - \x{luatexbase-loader}{LuaTeX is required for this package.^^J - Aborting package loading.} + \x{luatexbase-loader}{LuaTeX is required for this package. Aborting.} + \lltxb@loader@AtEnd \expandafter\endinput \fi % \end{macrocode} % -% Make sure the catcode of @ is correct, especially for \plaintex. -% -% \begin{macrocode} -\expandafter\edef\csname lltxb@loader@AtEnd\endcsname{% - \catcode64 \the\catcode64\relax} -\catcode64 11 -% \end{macrocode} -% % \subsubsection{Main content} % % Load the supporting Lua module. diff --git a/luatexbase-modutils.dtx b/luatexbase-modutils.dtx new file mode 100644 index 0000000..f623183 --- /dev/null +++ b/luatexbase-modutils.dtx @@ -0,0 +1,561 @@ +% \iffalse meta-comment +% +% Written in 2009, 2010 by Manuel Pégourié-Gonnard and Élie Roux. +% <mpg@elzevir.fr> +% <elie.roux@telecom-bretagne.eu> +% +% This work is under the CC0 license. +% +% This work consists of the main source file luatexbase-modutils.dtx +% and the derived files +% luatexbase-modutils.sty modutils.lua +% test-modutils-plain.tex test-modutils-latex.tex test-modutils.lua +% +% Unpacking: +% tex luatexbase-modutils.dtx +% Documentation: +% pdflatex luatexbase-modutils.dtx +% +%<*ignore> +\begingroup + \def\x{LaTeX2e}% +\expandafter\endgroup +\ifcase 0\ifx\install y1\fi\expandafter + \ifx\csname processbatchFile\endcsname\relax\else1\fi + \ifx\fmtname\x\else 1\fi\relax +\else\csname fi\endcsname +%</ignore> +%<*install> +\input docstrip.tex + +\keepsilent +\askforoverwritefalse + +\let\MetaPrefix\relax + +\preamble + +Written in 2009, 2010 by Manuel Pegourie-Gonnard and Elie Roux. + +This work is under the CC0 license. +See source file '\inFileName' for details. + +\endpreamble + +\let\MetaPrefix\DoubleperCent + +\generate{% + \usedir{tex/luatex/luatexbase}% + \file{luatexbase-modutils.sty}{\from{luatexbase-modutils.dtx}{texpackage}}% +} + +\generate{% + \usedir{doc/luatex/luatexbase}% + \file{test-modutils-plain.tex}{\from{luatexbase-modutils.dtx}{testplain}}% + \file{test-modutils-latex.tex}{\from{luatexbase-modutils.dtx}{testlatex}}% +} + +\def\MetaPrefix{-- } + +\def\luapostamble{% + \MetaPrefix^^J% + \MetaPrefix\space End of File `\outFileName'.% +} + +\def\currentpostamble{\luapostamble}% + +\generate{% + \usedir{tex/luatex/luatexbase}% + \file{luatexbase.modutils.lua}{\from{luatexbase-modutils.dtx}{luamodule}}% + \usedir{doc/luatex/luatexbase}% + \file{test-modutils.lua}{\from{luatexbase-modutils.dtx}{testdummy}}% +} + +\obeyspaces +\Msg{************************************************************************} +\Msg{*} +\Msg{* To finish the installation you have to move the following} +\Msg{* files into a directory searched by TeX:} +\Msg{*} +\Msg{* luatexbase-modutils.sty luatexbase.modutils.lua} +\Msg{*} +\Msg{* Happy TeXing!} +\Msg{*} +\Msg{************************************************************************} + +\endbatchfile +%</install> +%<*ignore> +\fi +%</ignore> +%<*driver> +\documentclass{ltxdoc} +\input{lltxb-dtxstyle} +\begin{document} + \DocInput{luatexbase-modutils.dtx}% +\end{document} +%</driver> +% \fi +% +% \CheckSum{0} +% +% \CharacterTable +% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z +% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z +% Digits \0\1\2\3\4\5\6\7\8\9 +% Exclamation \! Double quote \" Hash (number) \# +% Dollar \$ Percent \% Ampersand \& +% Acute accent \' Left paren \( Right paren \) +% Asterisk \* Plus \+ Comma \, +% Minus \- Point \. Solidus \/ +% Colon \: Semicolon \; Less than \< +% Equals \= Greater than \> Question mark \? +% Commercial at \@ Left bracket \[ Backslash \\ +% Right bracket \] Circumflex \^ Underscore \_ +% Grave accent \` Left brace \{ Vertical bar \| +% Right brace \} Tilde \~} +% +% \title{The \pk{luatexbase-modutils} package} +% \date{v0.1 2010-03-27} +% \author{% +% Manuel P\'egouri\'e-Gonnard \\ \texttt{mpg@elzevir.fr} \and +% \'Elie Roux \\ \texttt{elie.roux@telecom-bretagne.eu}} +% +% \maketitle +% +% \begin{abstract} +% \end{abstract} +% +% \section{Documentation} +% +% Lua has some embedded module management, with the functions \texttt{module} +% and \texttt{require}. With this package we try get more control on the +% module system, by implementing something close to the \LaTeX 's +% \texttt{\string\usepackage} and \texttt{\string\RequirePackage} macros: the +% \texttt{\string\luatexUseModule} and \texttt{\string\luatexRequireModule} +% that act like them, but for lua files. The functions \texttt{module} and +% \texttt{require} should not be used, in profit of the lua functions +% \texttt{luatextra.provides\_module} and \texttt{luatextra.use\_module} or +% \texttt{luatextra.require\_module}. +% +% \section{Implementation} +% +% \subsection{\tex package} +% +% \begin{macrocode} +%<*texpackage> +% \end{macrocode} +% +% \subsubsection{Preliminaries} +% +% Reload protection, especially for \plaintex. +% +% \begin{macrocode} + \csname lltxb@modutils@loaded\endcsname +\expandafter\let\csname lltxb@modutils@loaded\endcsname\endinput +% \end{macrocode} +% +% Catcode defenses. +% +% \begin{macrocode} +\begingroup + \catcode123 1 % { + \catcode125 2 % } + \catcode 35 6 % # + \toks0{}% + \def\x{}% + \def\y#1 #2 {% + \toks0\expandafter{\the\toks0 \catcode#1 \the\catcode#1}% + \edef\x{\x \catcode#1 #2}}% + \y 123 1 % { + \y 125 2 % } + \y 35 6 % # + \y 10 12 % ^^J + \y 34 12 % " + \y 36 3 % $ $ + \y 39 12 % ' + \y 40 12 % ( + \y 41 12 % ) + \y 42 12 % * + \y 43 12 % + + \y 44 12 % , + \y 45 12 % - + \y 46 12 % . + \y 47 12 % / + \y 60 12 % < + \y 61 12 % = + \y 64 11 % @ (letter) + \y 62 12 % > + \y 95 12 % _ (other) + \y 96 12 % ` + \edef\y#1{\endgroup\edef#1{\the\toks0\relax}\x}% +\expandafter\y\csname lltxb@modutils@AtEnd\endcsname +% \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-modutils}[2010/03/26 v0.1 Module utilities 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-modutils}{LuaTeX is required for this package. Aborting.} + \lltxb@modutils@AtEnd + \expandafter\endinput +\fi +% \end{macrocode} +% +% Load the package loader. +% +% \begin{macrocode} +\begingroup\expandafter\expandafter\expandafter\endgroup +\expandafter\ifx\csname RequirePackage\endcsname\relax + \input luatexbase-loader.sty +\else + \RequirePackage{luatexbase-loader} +\fi +% \end{macrocode} +% +% \subsubsection{Main code} +% +% The \texttt{\string\luatexModuleError} macro is called by the lua function +% \texttt{luatextra.module\_error}. It is necessary because we can't call +% directly \texttt{\string\errmessage} in lua. +% +% \begin{macrocode} + +\def\luatexModuleError#1#2{% + \errorcontextlines=0\relax + \immediate\write16{}% + \errmessage{Module #1 error: #2^^J^^J% +See the module #1 documentation for explanation.^^J ...^^J}% +} + +% \end{macrocode} +% +% Then we define +% \texttt{\string\luatexUseModule} that simply calls +% \texttt{luatextra.use\_module}. +% If the package is loaded with Plain, we define +% \texttt{\string\luaRequireModule} with two mandatory arguments. +% +% \begin{macrocode} +\def\luatexUseModule#1{\directlua{luatextra.use_module([[#1]])}} + +\expandafter\ifx\csname ProvidesPackage\endcsname\relax + \def\luatexRequireModule#1#2{\directlua{% + luatextra.require_module([[#1]], [[#2]])}} +\else +% \end{macrocode} +% +% If the package is loaded with \LaTeX , we define +% \texttt{\string\luaRequireModule} with one mandatory +% argument (the name of the package) and one optional (the version or the +% date). +% +% \begin{macrocode} + \newcommand\luatexRequireModule[2][0]{\directlua{luatextra.require_module([[#2]], [[#1]])}} +\fi +% \end{macrocode} +% +% \begin{macrocode} +\directlua{dofile(assert(kpse.find_file('luatexbase.modutils.lua', 'tex')))} +% \end{macrocode} +% +% \begin{macrocode} +\lltxb@modutils@AtEnd +%</texpackage> +% \end{macrocode} +% +% \subsection{Lua module} +% +% \begin{macrocode} +%<*luamodule> +% \end{macrocode} +% +% Initialisation borrowed from luatextra +% +% \begin{macrocode} +module("luatextra", package.seeall) + +local format = string.format + +luatextra.modules = luatextra.modules or {} +% \end{macrocode} +% +% Here we define the warning and error functions specific to +% \texttt{luatextra}. +% +% \begin{macrocode} + +luatextra.internal_warning_spaces = " " + +function luatextra.internal_warning(msg) + if not msg then return end + texio.write_nl(format("\nLuaTeXtra Warning: %s\n\n", msg)) +end + +luatextra.internal_error_spaces = " " + +function luatextra.internal_error(msg) + if not msg then return end + tex.sprint(format("\\immediate\\write16{}\\errmessage{LuaTeXtra error: %s^^J^^J}", msg)) +end + +% \end{macrocode} +% +% \subsubsection{Error, warning and info function for modules} +% +% Some module printing functions are provided, they have the same +% philosophy as the \LaTeX 's \texttt{\string\PackageError} and +% \texttt{\string\PackageWarning} macros: their first argument is the name +% of the module, and the second is the message. These functions are meant +% to be used by lua module writers. +% +% \begin{macrocode} + +function luatextra.module_error(package, msg, helpmsg) + if not package or not msg then + return + end + if helpmsg then + tex.sprint(format("\\errhelp{%s}", helpmsg)) + end + tex.sprint(format("\\luatexModuleError{%s}{%s}", package, msg)) +end + +function luatextra.module_warning(modulename, msg) + if not modulename or not msg then + return + end + texio.write_nl(format("\nModule %s Warning: %s\n\n", modulename, msg)) +end + +function luatextra.module_log(modulename, msg) + if not modulename or not msg then + return + end + texio.write_nl('log', format("%s: %s", modulename, msg)) +end + +function luatextra.module_term(modulename, msg) + if not modulename or not msg then + return + end + texio.write_nl('term', format("%s: %s", modulename, msg)) +end + +function luatextra.module_info(modulename, msg) + if not modulename or not msg then + return + end + texio.write_nl(format("%s: %s\n", modulename, msg)) +end + +% \end{macrocode} +% +% \subsubsection{module loading and providing functions} +% +% A small patch, for the \texttt{module} function to work in this file. I +% can't understand why it doens't otherwise. +% +% \begin{macrocode} + +luatextra.module = module + +% \end{macrocode} +% +% \begin{macro}{luatextra.use module} +% +% This macro is the one used to simply load a lua module file. It does not +% reload it if it's already loaded, and prints the filename in the terminal +% and the log. A lua module must call the macro +% \texttt{luatextra.provides\_module}. +% +% \begin{macrocode} +function luatextra.use_module(name) + if not name or luatextra.modules[name] then + return + end + require(name) + if not luatextra.modules[name] then + luatextra.internal_warning(format("You have requested module `%s',\n%s but the file %s does not provide it.", name, luatextra.internal_warning_spaces, filename)) + end + if not package.loaded[name] then + luatextra.module(name, package.seeall) + end +end +% \end{macrocode} +% +% \end{macro} +% +% Some internal functions to convert a date into a number, and to determine +% if a string is a date. It is useful for +% \texttt{luatextra.require\_package} to understand if a user asks a +% version with a date or a version number. +% +% \begin{macrocode} + +function luatextra.datetonumber(date) + numbers = string.gsub(date, "(%d+)/(%d+)/(%d+)", "%1%2%3") + return tonumber(numbers) +end + +function luatextra.isdate(date) + for _, _ in string.gmatch(date, "%d+/%d+/%d+") do + return true + end + return false +end + +local date, number = 1, 2 + +function luatextra.versiontonumber(version) + if luatextra.isdate(version) then + return {type = date, version = luatextra.datetonumber(version), orig = version} + else + return {type = number, version = tonumber(version), orig = version} + end +end + +luatextra.requiredversions = {} + +% \end{macrocode} +% +% \begin{macro}{luatextra.require module} +% +% This function is like the \texttt{luatextra.use\_module} function, but +% can accept a second argument that checks for the version of the module. +% The version can be a number or a date (format yyyy/mm/dd). +% +% \begin{macrocode} + +function luatextra.require_module(name, version) + if not name then + return + end + if not version then + return luatextra.use_module(name) + end + luaversion = luatextra.versiontonumber(version) + if luatextra.modules[name] then + if luaversion.type == date then + if luatextra.datetonumber(luatextra.modules[name].date) < luaversion.version then + luatextra.internal_error(format("found module `%s' loaded in version %s, but version %s was required", name, luatextra.modules[name].date, version)) + end + else + if luatextra.modules[name].version < luaversion.version then + luatextra.internal_error(format("found module `%s' loaded in version %.02f, but version %s was required", name, luatextra.modules[name].version, version)) + end + end + else + luatextra.requiredversions[name] = luaversion + luatextra.use_module(name) + end +end + +% \end{macrocode} +% +% \end{macro} +% +% \begin{macro}{luatextra.provides module} +% +% This macro is the one that must be called in the module files. It takes a +% table as argument. You can put any information you want in this table, +% but the mandatory ones are \texttt{name} (a string), \texttt{version} (a +% number), \texttt{date} (a string) and \texttt{description} (a string). +% Other fields are usually \texttt{copyright}, \texttt{author} and +% \texttt{license}. +% +% This function logs informations about the module the same way \LaTeX\ +% does for informations about packages. +% +% \begin{macrocode} + +function luatextra.provides_module(mod) + if not mod then + luatextra.internal_error('cannot provide nil module') + return + end + if not mod.version or not mod.name or not mod.date or not mod.description then + luatextra.internal_error('invalid module registered, fields name, version, date and description are mandatory') + return + end + requiredversion = luatextra.requiredversions[mod.name] + if requiredversion then + if requiredversion.type == date and requiredversion.version > luatextra.datetonumber(mod.date) then + luatextra.internal_error(format("loading module %s in version %s, but version %s was required", mod.name, mod.date, requiredversion.orig)) + elseif requiredversion.type == number and requiredversion.version > mod.version then + luatextra.internal_error(format("loading module %s in version %.02f, but version %s was required", mod.name, mod.version, requiredversion.orig)) + end + end + luatextra.modules[mod.name] = module + texio.write_nl('log', format("Lua module: %s %s v%.02f %s\n", mod.name, mod.date, mod.version, mod.description)) +end + +% \end{macrocode} +% +% \end{macro} +% +% \begin{macrocode} +%</luamodule> +% \end{macrocode} +% +% \section{Test files} +% +% A dummy lua file for tests. +% +% \begin{macrocode} +%<*testdummy> +luatextra.provides_module { + name = 'test-modutils', + date = '2000/01/01', + version = 1, + description = 'dummy test package', +} +%</testdummy> +% \end{macrocode} +% +% We just check that the package loads properly, under both LaTeX and Plain +% TeX. Anyway, the test files of other modules using this one already are a +% test\dots +% +% \begin{macrocode} +%<testplain>\input luatexbase-modutils.sty +%<testlatex>\RequirePackage{luatexbase-modutils} +%<*testplain,testlatex> +\luatexRequireModule +%<testlatex>[1970/01/01] +{test-modutils} +%<testplain>{1970/01/01} +%</testplain,testlatex> +%<testplain>\bye +%<testlatex>\stop +% \end{macrocode} +% +% \Finale +\endinput diff --git a/luatexbase-regs.dtx b/luatexbase-regs.dtx index 30e477d..89c2313 100644 --- a/luatexbase-regs.dtx +++ b/luatexbase-regs.dtx @@ -37,18 +37,11 @@ \askforoverwritefalse \preamble -This is a generated file. -Written in 2009, 2010 by Manuel P'egouri'e-Gonnard and 'Elie Roux. - <mpg@elzevir.fr> - <elie.roux@telecom-bretagne.eu> +Written in 2009, 2010 by Manuel Pegourie-Gonnard and Elie Roux. This work is under the CC0 license. - -This work consists of the main source file luatexbase-regs.dtx -and the derived files - luatexbase-regs.pdf luatexbase-regs.sty - test-regs-plain.tex test-regs-latex.tex +See source file '\inFileName' for details. \endpreamble @@ -69,7 +62,7 @@ and the derived files \Msg{* To finish the installation you have to move the following} \Msg{* files into a directory searched by TeX:} \Msg{*} -\Msg{* luatexbase-regs.sty luatexbase-regs-latex.tex ...} +\Msg{* luatexbase-regs.sty} \Msg{*} \Msg{* Happy TeXing!} \Msg{*} @@ -171,6 +164,43 @@ and the derived files \expandafter\let\csname lltxb@regs@loaded\endcsname\endinput % \end{macrocode} % +% Catcode defenses. +% +% \begin{macrocode} +\begingroup + \catcode123 1 % { + \catcode125 2 % } + \catcode 35 6 % # + \toks0{}% + \def\x{}% + \def\y#1 #2 {% + \toks0\expandafter{\the\toks0 \catcode#1 \the\catcode#1}% + \edef\x{\x \catcode#1 #2}}% + \y 123 1 % { + \y 125 2 % } + \y 35 6 % # + \y 10 12 % ^^J + \y 34 12 % " + \y 36 3 % $ $ + \y 39 12 % ' + \y 40 12 % ( + \y 41 12 % ) + \y 42 12 % * + \y 43 12 % + + \y 44 12 % , + \y 45 12 % - + \y 46 12 % . + \y 47 12 % / + \y 60 12 % < + \y 61 12 % = + \y 64 11 % @ (letter) + \y 62 12 % > + \y 95 12 % _ (other) + \y 96 12 % ` + \edef\y#1{\endgroup\edef#1{\the\toks0\relax}\x}% +\expandafter\y\csname lltxb@regs@AtEnd\endcsname +% \end{macrocode} +% % Package declaration. % % \begin{macrocode} @@ -202,20 +232,12 @@ and the derived files \let\x\PackageWarningNoLine \fi \expandafter\endgroup - \x{luatexbase-regs}{LuaTeX is required for this package.^^J - Aborting package loading.} + \x{luatexbase-regs}{LuaTeX is required for this package. Aborting.} + \lltxb@regs@AtEnd \expandafter\endinput \fi % \end{macrocode} % -% Make sure the catcode of @ is correct, especially for \plaintex. -% -% \begin{macrocode} -\expandafter\edef\csname lltxb@regs@AtEnd\endcsname{% - \catcode64 \the\catcode64\relax} -\catcode64 11 -% \end{macrocode} -% % \subsection{Main content} % % If running \latex, load \file{etex.sty}. If not, either |