diff options
Diffstat (limited to 'luatexbase-attr.dtx')
-rw-r--r-- | luatexbase-attr.dtx | 98 |
1 files changed, 35 insertions, 63 deletions
diff --git a/luatexbase-attr.dtx b/luatexbase-attr.dtx index 99b853a..c6a7040 100644 --- a/luatexbase-attr.dtx +++ b/luatexbase-attr.dtx @@ -2,6 +2,7 @@ % % Copyright 2009, 2010 by Élie Roux <elie.roux@telecom-bretagne.eu> % Copyright 2010, 2011 by Manuel Pégourié-Gonnard <mpg@elzevir.fr> +% Copyright 2013 by Philipp Gesang <philipp.gesang@alumni.uni-heidelberg.de> % % This work is under the CC0 license. % @@ -109,7 +110,7 @@ See the aforementioned source file(s) for copyright and licensing information. % Grave accent \` Left brace \{ Vertical bar \| % Right brace \} Tilde \~} % -% \pkdate{luatexbase-attr}{v0.4 2011-05-24} +% \pkdate{luatexbase-attr}{v0.6 2013-05-11} % % \maketitle % @@ -230,7 +231,7 @@ See the aforementioned source file(s) for copyright and licensing information. \let\x\ProvidesPackage \fi \expandafter\endgroup -\x{luatexbase-attr}[2011/05/24 v0.4 Attributes allocation for LuaTeX] +\x{luatexbase-attr}[2013/05/11 v0.6 Attributes allocation for LuaTeX] % \end{macrocode} % % Make sure \luatex is used. @@ -261,14 +262,17 @@ See the aforementioned source file(s) for copyright and licensing information. % % \subsubsection{Primitives needed} % -% Load \pk{luatexbase-compat}. +% First load \pk{luatexbase-modutils} (hence \pk{luatexbase-loader} +% and \pk{luatexbase-compat}), and make sure \pk{luatex.sty} is loaded too. % % \begin{macrocode} \begingroup\expandafter\expandafter\expandafter\endgroup \expandafter\ifx\csname RequirePackage\endcsname\relax - \input luatexbase-compat.sty + \input luatexbase-modutils.sty + \input luatex.sty \else - \RequirePackage{luatexbase-compat} + \RequirePackage{luatexbase-modutils} + \RequirePackage{luatex} \fi % \end{macrocode} % @@ -282,18 +286,7 @@ See the aforementioned source file(s) for copyright and licensing information. % % \subsubsection{Load supporting Lua module} % -% First load \pk{luatexbase-loader} (hence \pk{luatexbase-compat}), then -% the supporting Lua module. We make sure \verb|luatex.sty| is loaded. -% % \begin{macrocode} -\begingroup\expandafter\expandafter\expandafter\endgroup -\expandafter\ifx\csname RequirePackage\endcsname\relax - \input luatexbase-loader.sty - \input luatex.sty -\else - \RequirePackage{luatexbase-loader} - \RequirePackage{luatex} -\fi \luatexbase@directlua{require('luatexbase.attr')} % \end{macrocode} % @@ -360,23 +353,15 @@ local user_defined_t = nodesubtype"user_defined" local unassociated = "__unassociated" luatexbase = luatexbase or { } local luatexbase = luatexbase -% \end{macrocode} -% -% We improvise a basic logging facility. -% -% \begin{macrocode} -local reporter = function (log, category, ...) - if log == true then - texiowrite_nl("log", "("..category..") ") - texiowrite("log", stringformat(...)) - else - texiowrite_nl("("..category..") ") - texiowrite(stringformat(...)) - end -end -local warning = function (...) reporter (false, "warning", ...) end ------ info = function (...) reporter (false, "info", ...) end -local log = function (...) reporter (true, "log", ...) end +local err, warning, info, log = luatexbase.provides_module({ + name = "luatexbase-attr", + version = 0.6, + date = "2013/05/11", + description = "Attributes allocation for LuaTeX", + author = "Elie Roux, Manuel Pegourie-Gonnard and Philipp Gesang", + copyright = "Elie Roux, Manuel Pegourie-Gonnard and Philipp Gesang", + license = "CC0", +}) % \end{macrocode} % % This table holds the values of the allocated attributes, indexed by name. @@ -458,7 +443,11 @@ end luatexbase.unset_attribute = unset_attribute % \end{macrocode} % -% User whatsit allocation (experimental). +% Allocation of user-defined whatsit nodes (experimental). +% User-defined whatsit nodes (or user whatsits) are ignored by the +% \luatex engine. They can thus be used to store information in +% node lists without doing any harm. User whatsits can be +% distinguished by an id that is stored in node field |user_id|. % % \begin{macrocode} --- cf. luatexref-t.pdf, sect. 8.1.4.25 @@ -472,18 +461,18 @@ local anonymous_whatsits = 0 local anonymous_prefix = "anon" % \end{macrocode} % -% The whatsit allocation is split into two functions: +% User whatsit allocation is split into two functions: % \verb|new_user_whatsit_id| registers a new id (an integer) % and returns it. It is up to the user what he actually does % with the return value. % -% Registering whatsits without a name, though supported, is +% Registering user whatsits without a name, though supported, is % not exactly good style. In these cases we generate a name % from a counter. % -% In addition to the whatsit name, it is possible and even +% In addition to the user whatsit name, it is possible and even % encouraged to specify the name of the package that will be -% using the whatsit as the second argument. +% using the user whatsit as the second argument. % % \begin{macrocode} --- string -> string -> int @@ -527,7 +516,7 @@ luatexbase.new_user_whatsit_id = new_user_whatsit_id % \end{macrocode} % % \verb|new_user_whatsit| first registers a new id and then also -% creates the corresponding whatsit of subtype “user defined”. +% creates the corresponding whatsit node of subtype “user-defined”. % We return a nullary function that delivers copies of the whatsit. % % \begin{macrocode} @@ -537,30 +526,13 @@ local new_user_whatsit = function (name, package) local whatsit = newnode(whatsit_t, user_defined_t) whatsit.user_id = id --- unit -> node_t - local generator = function (proto) - local res - if proto - and proto.id == whatsit_t - and proto.subtype == user_defined_t - then - local proto_id = proto.user_id - if proto_id ~= id then --- mismatch - warning("overriding user_id %d of whatsit prototype (now: %d)", - proto.user_id, id) - end - res = copynode(proto) - res.user_id = id - else - res = copynode(whatsit) - end - return res - end - return generator, id + return function ( ) return copynode(whatsit) end, id end luatexbase.new_user_whatsit = new_user_whatsit +luatexbase.new_user_whatsit_factory = new_user_whatsit --- for Stephan % \end{macrocode} % -% If one knows the name of a whatsit, its corresponding id +% If one knows the name of a user whatsit, its corresponding id % can be retrieved by means of \verb|get_user_whatsit_id|. % % \begin{macrocode} @@ -577,11 +549,11 @@ luatexbase.get_user_whatsit_id = get_user_whatsit_id % The inverse lookup is also possible via \verb|get_user_whatsit_name|. % Here it finally becomes obvious why it is beneficial to supply a package % name -- it adds information about who created and might be relying on the -% whatsit in question. First return value is the whatsit name, the second -% the package identifier it was registered with. +% user whatsit in question. First return value is the user whatsit name, the +% second the package identifier it was registered with. % -% We issue a warning and return empty strings in case the asked whatsit is -% unregistered. +% We issue a warning and return empty strings in case the argument +% doesn't correspond to a registered user whatsit id. % % \begin{macrocode} --- int | fun | node -> (string, string) |