summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-10-03 23:10:11 +0000
committerKarl Berry <karl@freefriends.org>2015-10-03 23:10:11 +0000
commit502742d47c3d0cf25164c9121fcb2592cd272109 (patch)
tree86765fd8f379b191be5a30e10ade41a7b80286cf /Master/texmf-dist/tex/luatex
parentff37512bde5f73a7c823f417675c27545da3dea0 (diff)
luamplib (3oct15)
git-svn-id: svn://tug.org/texlive/trunk@38538 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r--Master/texmf-dist/tex/luatex/luamplib/luamplib.lua247
-rw-r--r--Master/texmf-dist/tex/luatex/luamplib/luamplib.sty8
2 files changed, 134 insertions, 121 deletions
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
index 2b7db37bbd0..9cae3851d65 100644
--- a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
+++ b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
@@ -16,16 +16,20 @@ local luamplib = luamplib
luamplib.showlog = luamplib.showlog or false
luamplib.lastlog = ""
-local err, warn, info, log = luatexbase.provides_module({
+luatexbase.provides_module {
name = "luamplib",
- version = "2.11.0",
- date = "2015/08/01",
+ version = "2.11.1",
+ date = "2015/10/02",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
-})
+}
local format, abs = string.format, math.abs
+local err = function(...) return luatexbase.module_error ("luamplib", format(...)) end
+local warn = function(...) return luatexbase.module_warning("luamplib", format(...)) end
+local info = function(...) return luatexbase.module_info ("luamplib", format(...)) end
+
local stringgsub = string.gsub
local stringfind = string.find
local stringmatch = string.match
@@ -38,7 +42,6 @@ local textprint = tex.tprint
local texget = tex.get
local texset = tex.set
local texgettoks = tex.gettoks
-local texsettoks = tex.settoks
local texgetbox = tex.getbox
local mplib = require ('mplib')
@@ -51,17 +54,12 @@ local lfsmkdir = lfs.mkdir
local lfstouch = lfs.touch
local ioopen = io.open
-local file = file
-if not file then
- file = { }
-
- function file.replacesuffix(filename, suffix)
- return (stringgsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
- end
-
- function file.stripsuffix(filename)
- return (stringgsub(filename,"%.[%a%d]+$",""))
- end
+local file = file or { }
+local replacesuffix = file.replacesuffix or function(filename, suffix)
+ return (stringgsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+end
+local stripsuffix = file.stripsuffix or function(filename)
+ return (stringgsub(filename,"%.[%a%d]+$",""))
end
local is_writable = file.is_writable or function(name)
@@ -116,8 +114,8 @@ if not outputdir then
end
function luamplib.getcachedir(dir)
- dir = stringgsub(dir,"##","#")
- dir = stringgsub(dir,"^~",
+ dir = dir:gsub("##","#")
+ dir = dir:gsub("^~",
os.type == "windows" and os.getenv("UserProfile") or os.getenv("HOME"))
if lfstouch and dir then
if lfsisdir(dir) then
@@ -191,29 +189,31 @@ local function replaceformatmp(file,newfile,ofmodify)
return newfile
end
-local esctex = "!!!T!!!E!!!X!!!"
-local esclbr = "!!!!!LEFTBRCE!!!!!"
-local escrbr = "!!!!!RGHTBRCE!!!!!"
-local escshar = "!!!!!SHARPE!!!!!"
+local esctex = "!!!T!!!E!!!X!!!"
+local esclbr = "!!!!!LEFTBRCE!!!!!"
+local escrbr = "!!!!!RGHTBRCE!!!!!"
local escpcnt = "!!!!!PERCENT!!!!!"
local eschash = "!!!!!HASH!!!!!"
local begname = "%f[A-Z_a-z]"
local endname = "%f[^A-Z_a-z]"
+local btex_etex = begname.."btex"..endname.."%s*(.-)%s*"..begname.."etex"..endname
+local verbatimtex_etex = begname.."verbatimtex"..endname.."%s*(.-)%s*"..begname.."etex"..endname
+
local function protecttexcontents(str)
- str = stringgsub(str,"\\%%","\\"..escpcnt)
- str = stringgsub(str,"%%.-\n", "")
- str = stringgsub(str,"%%.-$", "")
- str = stringgsub(str,'"','"&ditto&"')
- str = stringgsub(str,"\n%s*"," ")
- return str
+ return str:gsub("\\%%", "\\"..escpcnt)
+ :gsub("%%.-\n", "")
+ :gsub("%%.-$", "")
+ :gsub('"', '"&ditto&"')
+ :gsub("\n%s*", " ")
+ :gsub(escpcnt, "%%")
end
local function replaceinputmpfile (name,file)
local ofmodify = lfsattributes(file,"modification")
if not ofmodify then return file end
local cachedir = luamplib.cachedir or outputdir
- local newfile = stringgsub(name,"%W","_")
+ local newfile = name:gsub("%W","_")
newfile = cachedir .."/luamplib_input_"..newfile
if newfile and luamplibtime then
local nf = lfsattributes(newfile)
@@ -226,24 +226,24 @@ local function replaceinputmpfile (name,file)
local fh = ioopen(file,"r")
if not fh then return file end
local data = fh:read("*all"); fh:close()
- data = stringgsub(data, "\"[^\n]-\"",
- function(str)
- str = stringgsub(str,"([bem])tex"..endname,"%1"..esctex)
- return str
- end)
+
local count,cnt = 0,0
- data,cnt = stringgsub(data,
- begname.."btex"..endname.."%s*(.-)%s*"..begname.."etex"..endname,
- function(str)
- str = protecttexcontents(str)
- str = stringgsub(str,"\\"..escpcnt,"\\%%")
- return format("rawtextext(\"%s\")",str)
- end)
+
+ data = data:gsub("\"[^\n]-\"", function(str)
+ return str:gsub("([bem])tex"..endname,"%1"..esctex)
+ end)
+
+ data, cnt = data:gsub(btex_etex, function(str)
+ return format("rawtextext(\"%s\")",protecttexcontents(str))
+ end)
count = count + cnt
- data,cnt = stringgsub(data,
- begname.."verbatimtex"..endname.."%s*.-%s*"..begname.."etex"..endname,
- "")
+ data, cnt = data:gsub(verbatimtex_etex, "")
count = count + cnt
+
+ data = data:gsub("\"[^\n]-\"", function(str) -- restore string btex .. etex
+ return str:gsub("([bem])"..esctex, "%1tex")
+ end)
+
if count == 0 then
noneedtoreplace[name] = true
fh = ioopen(newfile,"w");
@@ -253,7 +253,6 @@ local function replaceinputmpfile (name,file)
end
return file
end
- data = stringgsub(data,"([bem])"..esctex,"%1tex")
fh = ioopen(newfile,"w")
if not fh then return file end
fh:write(data); fh:close()
@@ -301,7 +300,7 @@ if mplibone then
local mpx = mplib.new {
ini_version = true,
find_file = luamplib.finder,
- job_name = file.stripsuffix(name)
+ job_name = stripsuffix(name)
}
mpx:execute(format("input %s ;",name))
if dump then
@@ -314,7 +313,7 @@ if mplibone then
end
function luamplib.load(name)
- local mem_name = file.replacesuffix(name,"mem")
+ local mem_name = replacesuffix(name,"mem")
local mpx = mplib.new {
ini_version = false,
mem_name = mem_name,
@@ -344,22 +343,22 @@ else
luamplib.make = luamplib.make or function()
end
- function luamplib.load(name)
+ function luamplib.load(name,verbatim)
local mpx = mplib.new {
ini_version = true,
find_file = luamplib.finder,
math_mode = luamplib.numbersystem,
random_seed = randomseed,
}
- local preamble = preamble .. luamplib.mplibcodepreamble
+ local preamble = preamble .. (verbatim and "" or luamplib.mplibcodepreamble)
if luamplib.textextlabel then
- preamble = preamble .. luamplib.textextlabelpreamble
+ preamble = preamble .. (verbatim and "" or luamplib.textextlabelpreamble)
end
local result
if not mpx then
result = { status = 99, error = "out of memory"}
else
- result = mpx:execute(format(preamble, file.replacesuffix(name,"mp")))
+ result = mpx:execute(format(preamble, replacesuffix(name,"mp")))
end
luamplib.reporterror(result)
return mpx, result
@@ -416,14 +415,14 @@ end
luamplib.codeinherit = false
local mplibinstances = {}
-local process = function (data,indeed)
+local process = function (data,indeed,verbatim)
local standalone, firstpass = not luamplib.codeinherit, not indeed
local currfmt = currentformat .. (luamplib.numbersystem or "scaled")
currfmt = firstpass and currfmt or (currfmt.."2")
local mpx = mplibinstances[currfmt]
if standalone or not mpx then
randomseed = firstpass and math.random(65535) or randomseed
- mpx = luamplib.load(currentformat)
+ mpx = luamplib.load(currentformat,verbatim)
mplibinstances[currfmt] = mpx
end
return process_indeed(mpx, data, indeed)
@@ -642,55 +641,6 @@ enddef;
]]
luamplib.textextlabelpreamble = textextlabelpreamble
-local function protecttextext(data)
- local everymplib = texgettoks('everymplibtoks') or ''
- local everyendmplib = texgettoks('everyendmplibtoks') or ''
- data = "\n" .. everymplib .."\n".. data .."\n".. everyendmplib
- data = stringgsub(data,"\r","\n")
- data = stringgsub(data, "\"[^\n]-\"",
- function(str)
- str = stringgsub(str,"%%",escpcnt)
- str = stringgsub(str,"([bem])tex"..endname,"%1"..esctex)
- return str
- end)
- data = stringgsub(data,
- begname.."btex"..endname.."%s*(.-)%s*"..begname.."etex"..endname,
- function(str)
- str = protecttexcontents(str)
- return format("rawtextext(\"%s\")",str)
- end)
- data = stringgsub(data,
- begname.."verbatimtex"..endname.."%s*(.-)%s*"..begname.."etex"..endname,
- function(str)
- str = protecttexcontents(str)
- return format("VerbatimTeX(\"%s\")",str)
- end)
- data = stringgsub(data, "\"[^\n]-\"",
- function(str)
- str = stringgsub(str,"([bem])"..esctex,"%1tex")
- str = stringgsub(str,"{", esclbr)
- str = stringgsub(str,"}", escrbr)
- str = stringgsub(str,"#", escshar)
- return format("\\detokenize{%s}",str)
- end)
- data = stringgsub(data,"%%.-\n", "")
- luamplib.mpxcolors = {}
- data = stringgsub(data, "\\mpcolor"..endname.."(.-){(.-)}",
- function(opt,str)
- local cnt = #luamplib.mpxcolors + 1
- luamplib.mpxcolors[cnt] = format(
- "\\expandafter\\mplibcolor\\csname mpxcolor%i\\endcsname%s{%s}",
- cnt,opt,str)
- return format("\\csname mpxcolor%i\\endcsname",cnt)
- end)
- data = stringgsub(data, "([`\\])#", "%1"..eschash)
- data = stringgsub(data, "#", "##")
- data = stringgsub(data, eschash, "#")
- texsprint(data)
-end
-
-luamplib.protecttextext = protecttextext
-
local TeX_code_t = {}
local function domakeTEXboxes (data)
@@ -721,12 +671,76 @@ local function domakeTEXboxes (data)
end
end
+local function protect_tex_text_common (data)
+ local everymplib = texgettoks('everymplibtoks') or ''
+ local everyendmplib = texgettoks('everyendmplibtoks') or ''
+ data = format("\n%s\n%s\n%s",everymplib, data, everyendmplib)
+ data = data:gsub("\r","\n")
+
+ data = data:gsub("\"[^\n]-\"", function(str)
+ return str:gsub("([bem])tex"..endname,"%1"..esctex)
+ end)
+
+ data = data:gsub(btex_etex, function(str)
+ return format("rawtextext(\"%s\")",protecttexcontents(str))
+ end)
+ data = data:gsub(verbatimtex_etex, function(str)
+ return format("VerbatimTeX(\"%s\")",protecttexcontents(str))
+ end)
+
+ return data
+end
+
+local function protecttextextVerbatim(data)
+ data = protect_tex_text_common(data)
+
+ data = data:gsub("\"[^\n]-\"", function(str) -- restore string btex .. etex
+ return str:gsub("([bem])"..esctex, "%1tex")
+ end)
+
+ local _,result = process(data, false)
+ domakeTEXboxes(result)
+ return data
+end
+
+luamplib.protecttextextVerbatim = protecttextextVerbatim
+
+local function protecttextext(data)
+ data = protect_tex_text_common(data)
+
+ data = data:gsub("\"[^\n]-\"", function(str)
+ str = str:gsub("([bem])"..esctex, "%1tex")
+ :gsub("%%", escpcnt)
+ :gsub("{", esclbr)
+ :gsub("}", escrbr)
+ :gsub("#", eschash)
+ return format("\\detokenize{%s}",str)
+ end)
+
+ data = data:gsub("%%.-\n", "")
+
+ luamplib.mpxcolors = {}
+ data = data:gsub("\\mpcolor"..endname.."(.-){(.-)}", function(opt,str)
+ local cnt = #luamplib.mpxcolors + 1
+ luamplib.mpxcolors[cnt] = format(
+ "\\expandafter\\mplibcolor\\csname mpxcolor%i\\endcsname%s{%s}",
+ cnt,opt,str)
+ return format("\\csname mpxcolor%i\\endcsname",cnt)
+ end)
+
+ data = data:gsub("([^`\\])#","%1##")
+
+ texsprint(data)
+end
+
+luamplib.protecttextext = protecttextext
+
local function makeTEXboxes (data)
- data = stringgsub(data, "##", "#") -- restore # doubled in input string
- data = stringgsub(data, escpcnt, "%%")
- data = stringgsub(data, esclbr,"{")
- data = stringgsub(data, escrbr,"}")
- data = stringgsub(data, escshar, "#" )
+ data = data:gsub("##","#")
+ :gsub(escpcnt,"%%")
+ :gsub(esclbr,"{")
+ :gsub(escrbr,"}")
+ :gsub(eschash,"#")
local _,result = process(data, false)
domakeTEXboxes(result)
return data
@@ -863,7 +877,7 @@ local function tr_pdf_pageresources(mode,opaq)
if no_extgs then
tpr = tpr.."/ExtGState<<>>"
end
- tpr = stringgsub(tpr,"/ExtGState<<","%1"..res)
+ tpr = tpr:gsub("/ExtGState<<","%1"..res)
texset("global","pdfpageresources",tpr)
end
end
@@ -881,16 +895,13 @@ local setpageres = pdf.setpageresources or function(s) pdf.pageresources = s end
local function shading_initialize ()
shading_res = {}
- if pdfmode then
- require('luatexbase.mcb')
- if luatexbase.is_active_callback then -- luatexbase 0.7+
- local shading_obj = pdf.reserveobj()
- setpageres(format("%s/Shading %i 0 R",getpageres() or "",shading_obj))
- luatexbase.add_to_callback("finish_pdffile", function()
- pdf.immediateobj(shading_obj,format("<<%s>>",tableconcat(shading_res)))
+ if pdfmode and luatexbase.callbacktypes and luatexbase.callbacktypes.finish_pdffile then -- ltluatex
+ local shading_obj = pdf.reserveobj()
+ setpageres(format("%s/Shading %i 0 R",getpageres() or "",shading_obj))
+ luatexbase.add_to_callback("finish_pdffile", function()
+ pdf.immediateobj(shading_obj,format("<<%s>>",tableconcat(shading_res)))
end, "luamplib.finish_pdffile")
- pdf_objs.finishpdf = true
- end
+ pdf_objs.finishpdf = true
end
end
@@ -912,7 +923,7 @@ local function sh_pdfpageresources(shtype,domain,colorspace,colora,colorb,coordi
if not stringfind(pageres,"/Shading<<.*>>") then
pageres = pageres.."/Shading<<>>"
end
- pageres = stringgsub(pageres,"/Shading<<","%1"..res)
+ pageres = pageres:gsub("/Shading<<","%1"..res)
setpageres(pageres)
end
end
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
index 55508dcfeaa..be09b7aa3a1 100644
--- a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
+++ b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
@@ -14,7 +14,7 @@
\else
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luamplib}
- [2015/08/01 v2.11.0 mplib package for LuaTeX]
+ [2015/10/02 v2.11.1 mplib package for LuaTeX]
\RequirePackage{luatexbase-modutils}
\fi
\RequireLuaModule{luamplib}
@@ -61,7 +61,8 @@
\long\def\mplibdocode#1\endmplibcode{%
\endgroup
\ifdefined\mplibverbatimYes
- \directlua{luamplib.process([===[\the\everymplibtoks\detokenize{#1}\the\everyendmplibtoks]===],true)}%
+ \directlua{luamplib.tempdata = luamplib.protecttextextVerbatim([===[\detokenize{#1}]===])}%
+ \directlua{luamplib.processwithTEXboxes(luamplib.tempdata)}%
\else
\edef\mplibtemp{\directlua{luamplib.protecttextext([===[\unexpanded{#1}]===])}}%
\directlua{ tex.sprint(luamplib.mpxcolors) }%
@@ -87,7 +88,8 @@
\toks@\expandafter{\the\toks@#1}%
\def\mplibtemp@a{#2}\ifx\mplib@mplibcode\mplibtemp@a
\ifdefined\mplibverbatimYes
- \directlua{luamplib.process([===[\the\everymplibtoks\the\toks@\the\everyendmplibtoks]===],true)}%
+ \directlua{luamplib.tempdata = luamplib.protecttextextVerbatim([===[\the\toks@]===])}%
+ \directlua{luamplib.processwithTEXboxes(luamplib.tempdata)}%
\else
\edef\mplibtemp{\directlua{luamplib.protecttextext([===[\the\toks@]===])}}%
\directlua{ tex.sprint(luamplib.mpxcolors) }%