diff options
author | Karl Berry <karl@freefriends.org> | 2009-06-23 00:16:18 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-06-23 00:16:18 +0000 |
commit | a6f953f4816835c3e6460c8623361f6cc7978ee5 (patch) | |
tree | bebd23f3118698497ca50f1ac3b6f7fcbc49ac4e /Master/texmf-dist/tex/luatex | |
parent | b3e52d29b04fed8c4f0a8695fbca2b113a36d4ad (diff) |
new luatex package luatextra
git-svn-id: svn://tug.org/texlive/trunk@13902 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r-- | Master/texmf-dist/tex/luatex/luatextra/luaextra.lua | 600 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/luatextra/luamcallbacks.lua | 407 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/luatextra/luatextra-latex.tex | 36 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/luatextra/luatextra.lua | 401 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/luatextra/luatextra.sty | 237 |
5 files changed, 1681 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/luatex/luatextra/luaextra.lua b/Master/texmf-dist/tex/luatex/luatextra/luaextra.lua new file mode 100644 index 00000000000..4c21f24b157 --- /dev/null +++ b/Master/texmf-dist/tex/luatex/luatextra/luaextra.lua @@ -0,0 +1,600 @@ +-- +-- This is file `luaextra.lua', +-- generated with the docstrip utility. +-- +-- The original source files were: +-- +-- luaextra.dtx (with options: `lua') +-- This is a generated file. +-- +-- Copyright (C) 2009 by PRAGMA ADE / ConTeXt Development Team +-- +-- See ConTeXt's mreadme.pdf for the license. +-- +-- This work consists of the main source file luaextra.dtx +-- and the derived file luaextra.lua. +-- +do + local luatextra_module = { + name = "luaextra", + version = 0.91, + date = "2009/04/15", + description = "Lua additional functions.", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "See ConTeXt's mreadme.pdf for the license", + } + + luatextra.provides_module(luatextra_module) +end + +function string:stripspaces() + return (self:gsub("^%s*(.-)%s*$", "%1")) +end + + +function string.is_boolean(str) + if type(str) == "string" then + if str == "true" or str == "yes" or str == "on" or str == "t" then + return true + elseif str == "false" or str == "no" or str == "off" or str == "f" then + return false + end + end + return nil +end + + +function string.is_number(str) + return str:find("^[%-%+]?[%d]-%.?[%d+]$") == 1 +end + + +lpeg.space = lpeg.S(" \t\f\v") +lpeg.newline = lpeg.P("\r\n") + lpeg.P("\r") +lpeg.P("\n") + + +if not table.fastcopy then do + + local type, pairs, getmetatable, setmetatable = type, pairs, getmetatable, setmetatable + + local function fastcopy(old) -- fast one + if old then + local new = { } + for k,v in pairs(old) do + if type(v) == "table" then + new[k] = fastcopy(v) -- was just table.copy + else + new[k] = v + end + end + local mt = getmetatable(old) + if mt then + setmetatable(new,mt) + end + return new + else + return { } + end + end + + table.fastcopy = fastcopy + +end end + + +if not table.copy then do + + local type, pairs, getmetatable, setmetatable = type, pairs, getmetatable, setmetatable + + local function copy(t, tables) -- taken from lua wiki, slightly adapted + tables = tables or { } + local tcopy = {} + if not tables[t] then + tables[t] = tcopy + end + for i,v in pairs(t) do -- brrr, what happens with sparse indexed + if type(i) == "table" then + if tables[i] then + i = tables[i] + else + i = copy(i, tables) + end + end + if type(v) ~= "table" then + tcopy[i] = v + elseif tables[v] then + tcopy[i] = tables[v] + else + tcopy[i] = copy(v, tables) + end + end + local mt = getmetatable(t) + if mt then + setmetatable(tcopy,mt) + end + return tcopy + end + + table.copy = copy + +end end + + +function table.sortedkeys(tab) + local srt, kind = { }, 0 -- 0=unknown 1=string, 2=number 3=mixed + for key,_ in pairs(tab) do + srt[#srt+1] = key + if kind == 3 then + -- no further check + else + local tkey = type(key) + if tkey == "string" then + -- if kind == 2 then kind = 3 else kind = 1 end + kind = (kind == 2 and 3) or 1 + elseif tkey == "number" then + -- if kind == 1 then kind = 3 else kind = 2 end + kind = (kind == 1 and 3) or 2 + else + kind = 3 + end + end + end + if kind == 0 or kind == 3 then + table.sort(srt,function(a,b) return (tostring(a) < tostring(b)) end) + else + table.sort(srt) + end + return srt +end + +do + table.serialize_functions = true + table.serialize_compact = true + table.serialize_inline = true + + local function key(k) + if type(k) == "number" then -- or k:find("^%d+$") then + return "["..k.."]" + elseif noquotes and k:find("^%a[%a%d%_]*$") then + return k + else + return '["'..k..'"]' + end + end + + local function simple_table(t) + if #t > 0 then + local n = 0 + for _,v in pairs(t) do + n = n + 1 + end + if n == #t then + local tt = { } + for i=1,#t do + local v = t[i] + local tv = type(v) + if tv == "number" or tv == "boolean" then + tt[#tt+1] = tostring(v) + elseif tv == "string" then + tt[#tt+1] = ("%q"):format(v) + else + tt = nil + break + end + end + return tt + end + end + return nil + end + + local function serialize(root,name,handle,depth,level,reduce,noquotes,indexed) + handle = handle or print + reduce = reduce or false + if depth then + depth = depth .. " " + if indexed then + handle(("%s{"):format(depth)) + else + handle(("%s%s={"):format(depth,key(name))) + end + else + depth = "" + local tname = type(name) + if tname == "string" then + if name == "return" then + handle("return {") + else + handle(name .. "={") + end + elseif tname == "number" then + handle("[" .. name .. "]={") + elseif tname == "boolean" then + if name then + handle("return {") + else + handle("{") + end + else + handle("t={") + end + end + if root and next(root) then + local compact = table.serialize_compact + local inline = compact and table.serialize_inline + local first, last = nil, 0 -- #root cannot be trusted here + if compact then + for k,v in ipairs(root) do -- NOT: for k=1,#root do (why) + if not first then first = k end + last = last + 1 + end + end + for _,k in pairs(table.sortedkeys(root)) do + local v = root[k] + local t = type(v) + if compact and first and type(k) == "number" and k >= first and k <= last then + if t == "number" then + handle(("%s %s,"):format(depth,v)) + elseif t == "string" then + if reduce and (v:find("^[%-%+]?[%d]-%.?[%d+]$") == 1) then + handle(("%s %s,"):format(depth,v)) + else + handle(("%s %q,"):format(depth,v)) + end + elseif t == "table" then + if not next(v) then + handle(("%s {},"):format(depth)) + elseif inline then + local st = simple_table(v) + if st then + handle(("%s { %s },"):format(depth,table.concat(st,", "))) + else + serialize(v,k,handle,depth,level+1,reduce,noquotes,true) + end + else + serialize(v,k,handle,depth,level+1,reduce,noquotes,true) + end + elseif t == "boolean" then + handle(("%s %s,"):format(depth,tostring(v))) + elseif t == "function" then + if table.serialize_functions then + handle(('%s loadstring(%q),'):format(depth,string.dump(v))) + else + handle(('%s "function",'):format(depth)) + end + else + handle(("%s %q,"):format(depth,tostring(v))) + end + elseif k == "__p__" then -- parent + if false then + handle(("%s __p__=nil,"):format(depth)) + end + elseif t == "number" then + handle(("%s %s=%s,"):format(depth,key(k),v)) + elseif t == "string" then + if reduce and (v:find("^[%-%+]?[%d]-%.?[%d+]$") == 1) then + handle(("%s %s=%s,"):format(depth,key(k),v)) + else + handle(("%s %s=%q,"):format(depth,key(k),v)) + end + elseif t == "table" then + if not next(v) then + handle(("%s %s={},"):format(depth,key(k))) + elseif inline then + local st = simple_table(v) + if st then + handle(("%s %s={ %s },"):format(depth,key(k),table.concat(st,", "))) + else + serialize(v,k,handle,depth,level+1,reduce,noquotes) + end + else + serialize(v,k,handle,depth,level+1,reduce,noquotes) + end + elseif t == "boolean" then + handle(("%s %s=%s,"):format(depth,key(k),tostring(v))) + elseif t == "function" then + if table.serialize_functions then + handle(('%s %s=loadstring(%q),'):format(depth,key(k),string.dump(v))) + else + handle(('%s %s="function",'):format(depth,key(k))) + end + else + handle(("%s %s=%q,"):format(depth,key(k),tostring(v))) + -- handle(('%s %s=loadstring(%q),'):format(depth,key(k),string.dump(function() return v end))) + end + end + if level > 0 then + handle(("%s},"):format(depth)) + else + handle(("%s}"):format(depth)) + end + else + handle(("%s}"):format(depth)) + end + end + + function table.serialize(root,name,reduce,noquotes) + local t = { } + local function flush(s) + t[#t+1] = s + end + serialize(root, name, flush, nil, 0, reduce, noquotes) + return table.concat(t,"\n") + end + + function table.tostring(t, name) + return table.serialize(t, name) + end + + function table.tohandle(handle,root,name,reduce,noquotes) + serialize(root, name, handle, nil, 0, reduce, noquotes) + end + + -- sometimes tables are real use (zapfino extra pro is some 85M) in which + -- case a stepwise serialization is nice; actually, we could consider: + -- + -- for line in table.serializer(root,name,reduce,noquotes) do + -- ...(line) + -- end + -- + -- so this is on the todo list + + table.tofile_maxtab = 2*1024 + + function table.tofile(filename,root,name,reduce,noquotes) + local f = io.open(filename,'w') + if f then + local concat = table.concat + local maxtab = table.tofile_maxtab + if maxtab > 1 then + local t = { } + local function flush(s) + t[#t+1] = s + if #t > maxtab then + f:write(concat(t,"\n"),"\n") -- hm, write(sometable) should be nice + t = { } + end + end + serialize(root, name, flush, nil, 0, reduce, noquotes) + f:write(concat(t,"\n"),"\n") + else + local function flush(s) + f:write(s,"\n") + end + serialize(root, name, flush, nil, 0, reduce, noquotes) + end + f:close() + end + end + +end + + +function table.tohash(t) + local h = { } + for _, v in pairs(t) do -- no ipairs here + h[v] = true + end + return h +end + + +function table.fromhash(t) + local h = { } + for k, v in pairs(t) do -- no ipairs here + if v then h[#h+1] = k end + end + return h +end + + +function table.contains_value(t, val) + if t then + for k, v in pairs(t) do + if v==val then + return true + end + end + end + return false +end + + +function table.contains_key(t, key) + if t then + for k, v in pairs(t) do + if k==key then + return true + end + end + end + return false +end + + +function table.value_position(t, val) + if t then + local i=1 + for k, v in pairs(t) do + if v==val then + return i + end + i=i+1 + end + end + return 0 +end + + +function table.key_position(t, key) + if t then + local i=1 + for k,v in pairs(t) do + if k==key then + return i + end + i = i+1 + end + end + return -1 +end + + +function table.remove_value(t, v) + local p = table.value_position(t,v) + if p ~= -1 then + table.remove(t, table.value_position(t,v)) + end +end + + +function table.remove_key(t, k) + local p = table.key_position(t,k) + if p ~= -1 then + table.remove(t, table.key_position(t,k)) + end +end + + +function table.is_empty(t) + return not t or not next(t) +end + + +fpath = { } + + +function fpath.removesuffix(filename) + return filename:gsub("%.[%a%d]+$", "") +end + + +function fpath.addsuffix(filename, suffix) + if not filename:find("%.[%a%d]+$") then + return filename .. "." .. suffix + else + return filename + end +end + + +function fpath.replacesuffix(filename, suffix) + if not filename:find("%.[%a%d]+$") then + return filename .. "." .. suffix + else + return (filename:gsub("%.[%a%d]+$","."..suffix)) + end +end + + +function fpath.dirname(name) + return name:match("^(.+)[/\\].-$") or "" +end + + +function fpath.basename(fname) + if not fname then + return nil + end + return fname:match("^.+[/\\](.-)$") or fname +end + + +function fpath.nameonly(name) + return ((name:match("^.+[/\\](.-)$") or name):gsub("%..*$","")) +end + + +function fpath.suffix(name) + return name:match("^.+%.([^/\\]-)$") or "" +end + + +function fpath.join(...) + local pth = table.concat({...},"/") + pth = pth:gsub("\\","/") + local a, b = pth:match("^(.*://)(.*)$") + if a and b then + return a .. b:gsub("//+","/") + end + a, b = pth:match("^(//)(.*)$") + if a and b then + return a .. b:gsub("//+","/") + end + return (pth:gsub("//+","/")) +end + + +function fpath.split(str) + local t = { } + str = str:gsub("\\", "/") + str = str:gsub("(%a):([;/])", "%1\001%2") + for name in str:gmatch("([^;:]+)") do + if name ~= "" then + name = name:gsub("\001",":") + t[#t+1] = name + end + end + return t +end + + +function fpath.normalize_sep(str) + return str:gsub("\\", "/") +end + + +function fpath.localize_sep(str) + if os.type == 'windows' or type == 'msdos' then + return str:gsub("/", "\\") + else + return str:gsub("\\", "/") + end +end + + +function lfs.is_writable(name) + local f = io.open(name, 'w') + if f then + f:close() + return true + else + return false + end +end + + +function lfs.is_readable(name) + local f = io.open(name,'r') + if f then + f:close() + return true + else + return false + end +end + + +if not math.round then + function math.round(x) + return math.floor(x + 0.5) + end +end + + +if not math.div then + function math.div(n,m) + return floor(n/m) + end +end + + +if not math.mod then + function math.mod(n,m) + return n % m + end +end + +-- +-- End of File `luaextra.lua'. diff --git a/Master/texmf-dist/tex/luatex/luatextra/luamcallbacks.lua b/Master/texmf-dist/tex/luatex/luatextra/luamcallbacks.lua new file mode 100644 index 00000000000..03bebe0b7e9 --- /dev/null +++ b/Master/texmf-dist/tex/luatex/luatextra/luamcallbacks.lua @@ -0,0 +1,407 @@ +-- +-- This is file `luamcallbacks.lua', +-- generated with the docstrip utility. +-- +-- The original source files were: +-- +-- luamcallbacks.dtx (with options: `lua') +-- 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, luamcallbacks-test.tex, luamcallbacks.pdf. +-- + +luamcallbacks = { } + +luamcallbacks.module = { + name = "luamcallbacks", + version = 0.92, + date = "2009/03/19", + description = "Module to register several functions in a callback.", + author = "Hans Hagen & Elie Roux", + copyright = "Hans Hagen & Elie Roux", + license = "CC0", +} + +luatextra.provides_module(luamcallbacks.module) + + +luamcallbacks.callbacklist = luamcallbacks.callbacklist or { } + + +luamcallbacks.lua_callbacks_defaults = { } + +local format = string.format + + +local list = 1 +local data = 2 +local first = 3 +local simple = 4 + + +luamcallbacks.callbacktypes = luamcallbacks.callbacktypes or { +buildpage_filter = simple, +token_filter = first, +pre_output_filter = list, +hpack_filter = list, +process_input_buffer = data, +mlist_to_hlist = list, +vpack_filter = list, +define_font = first, +open_read_file = first, +linebreak_filter = list, +post_linebreak_filter = list, +pre_linebreak_filter = list, +start_page_number = simple, +stop_page_number = simple, +start_run = simple, +show_error_hook = simple, +stop_run = simple, +hyphenate = simple, +ligaturing = simple, +kerning = data, +find_write_file = first, +find_read_file = first, +find_vf_file = data, +find_map_file = data, +find_format_file = data, +find_opentype_file = data, +find_output_file = data, +find_truetype_file = data, +find_type1_file = data, +find_data_file = data, +find_pk_file = data, +find_font_file = data, +find_image_file = data, +find_ocp_file = data, +find_sfd_file = data, +find_enc_file = data, +read_sfd_file = first, +read_map_file = first, +read_pk_file = first, +read_enc_file = first, +read_vf_file = first, +read_ocp_file = first, +read_opentype_file = first, +read_truetype_file = first, +read_font_file = first, +read_type1_file = first, +read_data_file = first, +} + + +luamcallbacks.internalregister = luamcallbacks.internalregister or callback.register + +local callbacktypes = luamcallbacks.callbacktypes + +luamcallbacks.log = luamcallbacks.log or function(...) + luatextra.module_log('luamcallbacks', format(...)) +end + +luamcallbacks.info = luamcallbacks.info or function(...) + luatextra.module_info('luamcallbacks', format(...)) +end + +luamcallbacks.warning = luamcallbacks.warning or function(...) + luatextra.module_warning('luamcallbacks', format(...)) +end + +luamcallbacks.error = luamcallbacks.error or function(...) + luatextra.module_error('luamcallbacks', format(...)) +end + + +function luamcallbacks.str_to_type(str) + if str == 'list' then + return list + elseif str == 'data' then + return data + elseif str == 'first' then + return first + elseif str == 'simple' then + return simple + else + return nil + end +end + + +function luamcallbacks.create(name, ctype, default) + if not name then + luamcallbacks.error(format("unable to call callback, no proper name passed", name)) + return nil + end + if not ctype or not default then + luamcallbacks.error(format("unable to create callback '%s', callbacktype or default function not specified", name)) + return nil + end + if callbacktypes[name] then + luamcallbacks.error(format("unable to create callback '%s', callback already exists", name)) + return nil + end + local temp = luamcallbacks.str_to_type(ctype) + if not temp then + luamcallbacks.error(format("unable to create callback '%s', type '%s' undefined", name, ctype)) + return nil + end + ctype = temp + luamcallbacks.lua_callbacks_defaults[name] = default + callbacktypes[name] = ctype +end + + +function luamcallbacks.call(name, ...) + if not name then + luamcallbacks.error(format("unable to call callback, no proper name passed", name)) + return nil + end + if not luamcallbacks.lua_callbacks_defaults[name] then + luamcallbacks.error(format("unable to call lua callback '%s', unknown callback", name)) + return nil + end + local l = luamcallbacks.callbacklist[name] + local f + if not l then + f = luamcallbacks.lua_callbacks_defaults[name] + else + if callbacktypes[name] == list then + f = luamcallbacks.listhandler(name) + elseif callbacktypes[name] == data then + f = luamcallbacks.datahandler(name) + elseif callbacktypes[name] == simple then + f = luamcallbacks.simplehandler(name) + elseif callbacktypes[name] == first then + f = luamcallbacks.firsthandler(name) + else + luamcallbacks.error("unknown callback type") + end + end + return f(...) +end + + +function luamcallbacks.add (name,func,description,priority) + if type(func) ~= "function" then + luamcallbacks.error("unable to add function, no proper function passed") + return + end + if not name or name == "" then + luamcallbacks.error("unable to add function, no proper callback name passed") + return + elseif not callbacktypes[name] then + luamcallbacks.error( + format("unable to add function, '%s' is not a valid callback", + name)) + return + end + if not description or description == "" then + luamcallbacks.error( + format("unable to add function to '%s', no proper description passed", + name)) + return + end + if luamcallbacks.get_priority(name, description) ~= 0 then + luamcallbacks.warning( + format("function '%s' already registered in callback '%s'", + description, name)) + end + local l = luamcallbacks.callbacklist[name] + if not l then + l = {} + luamcallbacks.callbacklist[name] = l + if not luamcallbacks.lua_callbacks_defaults[name] then + if callbacktypes[name] == list then + luamcallbacks.internalregister(name, luamcallbacks.listhandler(name)) + elseif callbacktypes[name] == data then + luamcallbacks.internalregister(name, luamcallbacks.datahandler(name)) + elseif callbacktypes[name] == simple then + luamcallbacks.internalregister(name, luamcallbacks.simplehandler(name)) + elseif callbacktypes[name] == first then + luamcallbacks.internalregister(name, luamcallbacks.firsthandler(name)) + else + luamcallbacks.error("unknown callback type") + end + end + end + local f = { + func = func, + description = description, + } + priority = tonumber(priority) + if not priority or priority > #l then + priority = #l+1 + elseif priority < 1 then + priority = 1 + end + if callbacktypes[name] == first and (priority ~= 1 or #l ~= 0) then + luamcallbacks.warning(format("several callbacks registered in callback '%s', only the first function will be active.", name)) + end + table.insert(l,priority,f) + luamcallbacks.log( + format("inserting function '%s' at position %s in callback list for '%s'", + description,priority,name)) +end + + +function luamcallbacks.get_priority (name, description) + if not name or name == "" or not callbacktypes[name] or not description then + return 0 + end + local l = luamcallbacks.callbacklist[name] + if not l then return 0 end + for p, f in pairs(l) do + if f.description == description then + return p + end + end + return 0 +end + + +function luamcallbacks.remove (name, description) + if not name or name == "" then + luamcallbacks.error("unable to remove function, no proper callback name passed") + return + elseif not callbacktypes[name] then + luamcallbacks.error( + format("unable to remove function, '%s' is not a valid callback", + name)) + return + end + if not description or description == "" then + luamcallbacks.error( + format("unable to remove function from '%s', no proper description passed", + name)) + return + end + local l = luamcallbacks.callbacklist[name] + if not l then + luamcallbacks.error(format("no callback list for '%s'",name)) + return + end + for k,v in ipairs(l) do + if v.description == description then + table.remove(l,k) + luamcallbacks.log( + format("removing function '%s' from '%s'",description,name)) + if l == {} and not luamcallbacks.lua_callbacks_defaults[name] then + luamcallbacks.internalregister(name, nil) + end + return + end + end + luamcallbacks.warning( + format("unable to remove function '%s' from '%s'",description,name)) +end + + +function luamcallbacks.reset (name) + if not name or name == "" then + luamcallbacks.error("unable to reset, no proper callback name passed") + return + elseif not callbacktypes[name] then + luamcallbacks.error( + format("reset error, '%s' is not a valid callback", + name)) + return + end + if not luamcallbacks.lua_callbacks_defaults[name] then + luamcallbacks.internalregister(name, nil) + end + local l = luamcallbacks.callbacklist[name] + if l then + luamcallbacks.log(format("resetting callback list '%s'",name)) + luamcallbacks.callbacklist[name] = nil + end +end + + +function luamcallbacks.listhandler (name) + return function(head,...) + local l = luamcallbacks.callbacklist[name] + if l then + local done = true + for _, f in ipairs(l) do + -- the returned value can be either true or a new head plus true + rtv1, rtv2 = f.func(head,...) + if type(rtv1) == 'boolean' then + done = rtv1 + elseif type (rtv1) == 'userdata' then + head = rtv1 + end + if type(rtv2) == 'boolean' then + done = rtv2 + elseif type(rtv2) == 'userdata' then + head = rtv2 + end + if done == false then + luamcallbacks.error(format( + "function \"%s\" returned false in callback '%s'", + f.description, name)) + end + end + return head, done + else + return head, false + end + end +end + + +function luamcallbacks.datahandler (name) + return function(data,...) + local l = luamcallbacks.callbacklist[name] + if l then + for _, f in ipairs(l) do + data = f.func(data,...) + end + end + return data + end +end + + +function luamcallbacks.firsthandler (name) + return function(...) + local l = luamcallbacks.callbacklist[name] + if l then + local f = l[1].func + return f(...) + else + return nil, false + end + end +end + + +function luamcallbacks.simplehandler (name) + return function(...) + local l = luamcallbacks.callbacklist[name] + if l then + for _, f in ipairs(l) do + f.func(...) + end + end + end +end + + +callback.add = luamcallbacks.add +callback.remove = luamcallbacks.remove +callback.reset = luamcallbacks.reset +callback.create = luamcallbacks.create +callback.call = luamcallbacks.call +callback.get_priority = luamcallbacks.get_priority + +callback.register = function (...) +luamcallbacks.error("function callback.register has been deleted by luamcallbacks, please use callback.add instead.") +end + +-- +-- End of File `luamcallbacks.lua'. diff --git a/Master/texmf-dist/tex/luatex/luatextra/luatextra-latex.tex b/Master/texmf-dist/tex/luatex/luatextra/luatextra-latex.tex new file mode 100644 index 00000000000..024b1888307 --- /dev/null +++ b/Master/texmf-dist/tex/luatex/luatextra/luatextra-latex.tex @@ -0,0 +1,36 @@ +%% +%% This is file `luatextra-latex.tex', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% luatextra.dtx (with options: `latex') +%% 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 luainputenc.dtx +%% and the derived files +%% luatextra.sty, luatextra.lua, luatextra-latex.tex, luatextra.pdf +%% +\def\ltxtra@temp#1{% +\ifnum\count27#1=32768 % + \count27#1=65536 % +\fi +}% +\ltxtra@temp0% +\ltxtra@temp1% +\ltxtra@temp2% +\ltxtra@temp3% +\ltxtra@temp4% +\ltxtra@temp5% +\ltxtra@temp6% +\let\newcount\globcount +\let\newdimen\globdimen +\let\newskip\globskip +\let\newbox\globbox +\endinput +%% +%% End of file `luatextra-latex.tex'. diff --git a/Master/texmf-dist/tex/luatex/luatextra/luatextra.lua b/Master/texmf-dist/tex/luatex/luatextra/luatextra.lua new file mode 100644 index 00000000000..5c4a0f947af --- /dev/null +++ b/Master/texmf-dist/tex/luatex/luatextra/luatextra.lua @@ -0,0 +1,401 @@ +-- +-- This is file `luatextra.lua', +-- generated with the docstrip utility. +-- +-- The original source files were: +-- +-- luatextra.dtx (with options: `lua') +-- 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 luainputenc.dtx +-- and the derived files +-- luatextra.sty, luatextra.lua, luatextra-latex.tex, luatextra.pdf +-- +do + local luatextrapath = kpse.find_file("luatextra.lua") + if luatextrapath then + if luatextrapath:sub(1,2) == "./" then + luatextrapath = luatextrapath:sub(3) + end + texio.write(' ('..luatextrapath) + end +end + + +luatextra = {} + +module("luatextra", package.seeall) + + +luatextra.modules = {} + +luatextra.modules['luatextra'] = { + version = 0.93, + name = "luatextra", + date = "2009/04/15", + description = "Additional low level functions for LuaTeX", + author = "Elie Roux", + copyright = "Elie Roux, 2009", + license = "CC0", +} + +local format = string.format + + +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 + + +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("\\luaModuleError{%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 + + +function luatextra.find_module_file(name) + if string.sub(name, -4) ~= '.lua' then + name = name..'.lua' + end + path = kpse.find_file(name, 'tex') + if not path then + path = kpse.find_file(name, 'texmfscripts') + end + return path, name +end + + +luatextra.module = module + + +function luatextra.use_module(name) + if not name or luatextra.modules[name] then + return + end + local path, filename = luatextra.find_module_file(name) + if not path then + luatextra.internal_error(format("unable to find lua module %s", name)) + else + if path:sub(1,2) == "./" then + path = path:sub(3) + end + texio.write(' ('..path) + dofile(path) + 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 + texio.write(')') + end +end + + +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 = {} + + +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 + + +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 + + +luatextra.use_module('luaextra') + + +function luatextra.kpse_module_loader(mod) + local file = luatextra.find_module_file(mod) + if file then + local loader, error = loadfile(file) + if loader then + texio.write_nl("(" .. file .. ")") + return loader + end + return "\n\t[luatextra.kpse_module_loader] Loading error:\n\t" + .. error + end + return "\n\t[luatextra.kpse_module_loader] Search failed" +end + +table.insert(package.loaders, luatextra.kpse_module_loader) + + +luatextra.attributes = {} + +tex.attributenumber = luatextra.attributes + +function luatextra.attributedef_from_tex(name, number) + truename = name:gsub('[\\ ]', '') + luatextra.attributes[truename] = tonumber(number) +end + + +luatextra.catcodetables = {} + +tex.catcodetablenumber = luatextra.catcodetables + +function luatextra.catcodetabledef_from_tex(name, number) + truename = name:gsub('[\\ ]', '') + luatextra.catcodetables[truename] = tonumber(number) +end + + +function luatextra.open_read_file(filename) + local path = kpse.find_file(filename) + local env = { + ['filename'] = filename, + ['path'] = path, + } + luamcallbacks.call('pre_read_file', env) + path = env.path + if not path then + return + end + local f = env.file + if not f then + f = io.open(path) + env.file = f + end + if not f then + return + end + env.reader = luatextra.reader + env.close = luatextra.close + return env +end + + +function luatextra.reader(env) + local line = (env.file):read() + line = luamcallbacks.call('file_reader', env, line) + return line +end + +function luatextra.close(env) + (env.file):close() + luamcallbacks.call('file_close', env) +end + + +function luatextra.default_reader(env, line) + return line +end + +function luatextra.default_close(env) + return +end + +function luatextra.default_pre_read(env) + return env +end + + +do + if tex.luatexversion < 36 then + fontloader = fontforge + end +end + +function luatextra.find_font(name) + local types = {'ofm', 'ovf', 'opentype fonts', 'truetype fonts'} + local path = kpse.find_file(name) + if path then return path end + for _,t in pairs(types) do + path = kpse.find_file(name, t) + if path then return path end + end + return nil +end + +function luatextra.font_load_error(error) + luatextra.module_warning('luatextra', string.format('%s\nloading lmr10 instead...', error)) +end + +function luatextra.load_default_font(size) + return font.read_tfm("lmr10", size) +end + +function luatextra.define_font(name, size) + if (size < 0) then size = (- 655.36) * size end + local fontinfos = { + asked_name = name, + name = name, + size = size + } + callback.call('font_syntax', fontinfos) + name = fontinfos.name + local path = fontinfos.path + if not path then + path = luatextra.find_font(name) + fontinfos.path = luatextra.find_font(name) + end + if not path then + luatextra.font_load_error("unable to find font "..name) + return luatextra.load_default_font(size) + end + if not fontinfos.filename then + fontinfos.filename = fpath.basename(path) + end + local ext = fpath.suffix(path) + local f + if ext == 'tfm' or ext == 'ofm' then + f = font.read_tfm(name, size) + elseif ext == 'vf' or ext == 'ovf' then + f = font.read_vf(name, size) + elseif ext == 'ttf' or ext == 'otf' or ext == 'ttc' then + f = callback.call('open_otf_font', fontinfos) + else + luatextra.font_load_error("unable to determine the type of font "..name) + f = luatextra.load_default_font(size) + end + if not f then + luatextra.font_load_error("unable to load font "..name) + f = luatextra.load_default_font(size) + end + callback.call('post_font_opening', f, fontinfos) + return f +end + +function luatextra.default_font_syntax(fontinfos) + return +end + +function luatextra.default_open_otf(fontinfos) + return nil +end + +function luatextra.default_post_font(f, fontinfos) + return true +end + +function luatextra.register_font_callback() + callback.add('define_font', luatextra.define_font, 'luatextra.define_font') +end + +do + luatextra.use_module('luamcallbacks') + callback.create('pre_read_file', 'simple', luatextra.default_pre_read) + callback.create('file_reader', 'data', luatextra.default_reader) + callback.create('file_close', 'simple', luatextra.default_close) + callback.add('open_read_file', luatextra.open_read_file, 'luatextra.open_read_file') + callback.create('font_syntax', 'simple', luatextra.default_font_syntax) + callback.create('open_otf_font', 'first', luatextra.default_open_otf) + callback.create('post_font_opening', 'simple', luatextra.default_post_font) + + if luatextrapath then + texio.write(')') + end +end +-- +-- End of File `luatextra.lua'. diff --git a/Master/texmf-dist/tex/luatex/luatextra/luatextra.sty b/Master/texmf-dist/tex/luatex/luatextra/luatextra.sty new file mode 100644 index 00000000000..3b86be22d90 --- /dev/null +++ b/Master/texmf-dist/tex/luatex/luatextra/luatextra.sty @@ -0,0 +1,237 @@ +%% +%% This is file `luatextra.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% luatextra.dtx (with options: `package') +%% 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 luainputenc.dtx +%% and the derived files +%% luatextra.sty, luatextra.lua, luatextra-latex.tex, luatextra.pdf +%% +\csname ifluatextraloaded\endcsname +\let\ifluatextraloaded\endinput + + +\expandafter\ifx\csname ProvidesPackage\endcsname\relax + \expandafter\ifx\csname ifluatex\endcsname\relax + \input ifluatex.sty + \fi +\else + \RequirePackage{ifluatex} +\fi + +\expandafter\ifx\csname ProvidesPackage\endcsname\relax + \ifluatex\else + \immediate\write16{} + \errmessage{Package luatextra Error: This package must be used with LuaTeX} + \fi + \def\luaRequireModule#1#2{\luadirect{luatextra.require_module([[#1]], [[#2]])}} +\else + \ifluatex\else + \PackageError{luatextra}{This package must be used with LuaTeX.} + \fi + \NeedsTeXFormat{LaTeX2e} + \ProvidesPackage{luatextra} + [2009/04/15 v0.93 LuaTeX extra low-level macros] + \RequirePackage{environ} + \NewEnviron{luacode}{\luadirect{\BODY}} + \newcommand\luaRequireModule[2][0]{\luadirect{luatextra.require_module([[#2]], [[#1]])}} + \RequirePackage{etex}[1998/03/26]% + \input luatextra-latex.tex +\fi + + +\def\LuaTeX{Lua\TeX } +\def\LuaLaTeX{Lua\LaTeX } + + +\ifnum\luatexversion<36 + \def\directlua{\pdfprimitive\directlua0} + \def\latelua{\pdfprimitive\latelua0} + \def\luadirect{\pdfprimitive\directlua0} + \def\lualate{\pdfprimitive\latelua0} + \def\luaattribute{\attribute} + \def\luaattributedef{\attributedef} + \def\luaclearmarks{\pdfprimitive\luaclearmarks} + \def\luaformatname{\pdfprimitive\formatname} + \def\luascantexttokens{\pdfprimitive\scantexttokens} + \def\luacatcodetable{\catcodetable} +\else + \directlua{tex.enableprimitives('lua', {'attribute'})} + \directlua{tex.enableprimitives('lua', {'attributedef'})} + \directlua{tex.enableprimitives('lua', {'clearmarks'})} + \directlua{tex.enableprimitives('lua', {'formatname'})} + \directlua{tex.enableprimitives('lua', {'scantexttokens'})} + \directlua{tex.enableprimitives('lua', {'catcodetable'})} + \def\luadirect{\pdfprimitive\directlua} + \def\lualate{\pdfprimitive\latelua} +\fi + +\def\initluacatcodetable{\pdfprimitive\initcatcodetable} +\def\saveluacatcodetable{\pdfprimitive\savecatcodetable} +\def\luaclose{\pdfprimitive\closelua} + + +\luadirect{dofile(kpse.find_file("luatextra.lua"))} + + +\def\ltxtra@RegisterFontCallback{ + \luadirect{luatextra.register_font_callback()} +} + + + +\def\luaModuleError#1#2{% + \errorcontextlines=0\relax + \immediate\write16{}% + \errmessage{Module #1 error: #2^^J^^J% +See the module #1 documentation for explanation.^^J ...^^J}% +} + +\def\luaUseModule#1{\luadirect{luatextra.use_module([[#1]])}} + + +\newcount\luaattdefcounter +\luaattdefcounter = 1 + +\def\newluaattribute#1{% + \ifnum\luaattdefcounter<65535\relax % + \global\advance\luaattdefcounter by 1\relax % + \allocationnumber\luaattdefcounter % + \ifluatex % + \global\luaattributedef#1=\allocationnumber % + \fi % + \wlog{\string#1=\string\attribute\the\allocationnumber}% + \luadirect{% + luatextra.attributedef_from_tex([[\noexpand#1]], '\number\allocationnumber')}% + \else % + \errmessage{No room for a new \string\attribute}% + \fi % +} + + +\def\setluaattribute#1#2{% + #1=\numexpr#2\relax % +} + +\def\unsetluaattribute#1{% + \ifnum\luatexversion<37\relax % + #1=-1\relax % + \else % + #1=-"7FFFFFFF\relax % + \fi % +} + + +\newcount\luacatcodetabledefcounter + +\luacatcodetabledefcounter = 1 + +\def\newluacatcodetable#1{% + \ifnum\luacatcodetabledefcounter<1114110\relax % 0x10FFFF is maximal \chardef + \global\advance\luacatcodetabledefcounter by 1\relax % + \allocationnumber=\luacatcodetabledefcounter % + \global\chardef#1=\allocationnumber % + \luadirect{% + luatextra.catcodetabledef_from_tex([[\noexpand#1]], '\number\allocationnumber')}% + \wlog{\string#1=\string\catcodetable\the\allocationnumber}% + \else % + \errmessage{No room for a new \string\catcodetable}% + \fi % +} + + +\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 + + +\def\luasetcatcoderange#1#2#3{% + \edef\luaSCR@temp{% + \noexpand\@tempcnta=\the\@tempcnta + \noexpand\@tempcntb=\the\@tempcntb + \noexpand\count@=\the\count@ + \relax + }% + \@tempcnta=#1\relax + \@tempcntb=#2\relax + \count@=#3\relax + \loop\unless\ifnum\@tempcnta>\@tempcntb + \catcode\@tempcnta=\count@ + \advance\@tempcnta by 1\relax + \repeat + \luaSCR@temp +} + + +\newluacatcodetable\CatcodeTableIniTeX +\newluacatcodetable\CatcodeTableString +\newluacatcodetable\CatcodeTableOther +\newluacatcodetable\CatcodeTableLaTeX +\initluacatcodetable\CatcodeTableIniTeX + +\expandafter\ifx\csname @firstofone\endcsname\relax + \long\def\@firstofone#1{#1}% +\fi + +\begingroup + \def\@makeother#1{\catcode#1=12\relax}% + \@firstofone{% + \luacatcodetable\CatcodeTableIniTeX + \begingroup + \luasetcatcoderange{0}{8}{15}% + \catcode9=10 % tab + \catcode11=15 % + \catcode12=13 % form feed + \luasetcatcoderange{14}{31}{15}% + \catcode35=6 % hash + \catcode36=3 % dollar + \catcode38=4 % ampersand + \catcode94=7 % circumflex + \catcode95=8 % underscore + \catcode123=1 % brace left + \catcode125=2 % brace right + \catcode126=13 % tilde + \catcode127=15 % + \saveluacatcodetable\CatcodeTableLaTeX + \endgroup + \@makeother{0}% nul + \@makeother{13}% carriage return + \@makeother{37}% percent + \@makeother{92}% backslash + \@makeother{127}% + \luasetcatcoderange{65}{90}{12}% A-Z + \luasetcatcoderange{97}{122}{12}% a-z + \saveluacatcodetable\CatcodeTableString + \@makeother{32}% space + \saveluacatcodetable\CatcodeTableOther + \endgroup +} + + +\expandafter\ifx\csname ProvidesPackage\endcsname\relax + \input luaotfload.sty +\else + \RequirePackage{luaotfload} +\fi + +\ltxtra@AtEnd +\endinput +%% +%% End of file `luatextra.sty'. |