diff options
author | Karl Berry <karl@freefriends.org> | 2014-03-09 21:30:34 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2014-03-09 21:30:34 +0000 |
commit | 630961707af41c344d014c8589d4b793069a98fc (patch) | |
tree | 418a08b198a3cf6e6f55acd6bb36066c3bf8f8db /Master/texmf-dist/tex/luatex/luamplib | |
parent | 287d865990e5823a75263a98624f9f4bd89192a4 (diff) |
luamplib (9mar14)
git-svn-id: svn://tug.org/texlive/trunk@33135 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luamplib')
-rw-r--r-- | Master/texmf-dist/tex/luatex/luamplib/luamplib.lua | 182 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/luamplib/luamplib.sty | 12 |
2 files changed, 115 insertions, 79 deletions
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua index 575e030539b..a247ac12958 100644 --- a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua +++ b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua @@ -18,8 +18,8 @@ luamplib.lastlog = "" local err, warn, info, log = luatexbase.provides_module({ name = "luamplib", - version = "2.5.3", - date = "2014/03/01", + version = "2.6.0", + date = "2014/03/08", description = "Lua package to typeset Metapost with LuaTeX's MPLib.", }) @@ -30,6 +30,7 @@ local stringgsub = string.gsub local stringfind = string.find local stringmatch = string.match local stringgmatch = string.gmatch +local stringexplode = string.explode local tableconcat = table.concat local texsprint = tex.sprint @@ -168,8 +169,8 @@ local function replaceinputmpfile (name,file) local data = fh:read("*all"); fh:close() data = stringgsub(data, "\"[^\n]-\"", function(str) - str = stringgsub(str,"%%","*****PERCENT*****") - str = stringgsub(str,"([bem])tex%f[^A-Z_a-z]","%1***T***E***X***") + str = stringgsub(str,"%%","!!!!!PERCENT!!!!!") + str = stringgsub(str,"([bem])tex%f[^A-Z_a-z]","%1!!!T!!!E!!!X!!!") return str end) data = stringgsub(data,"%%.-\n","") @@ -195,8 +196,8 @@ local function replaceinputmpfile (name,file) end return file end - data = stringgsub(data,"([bem])***T***E***X***","%1tex") - data = stringgsub(data,"*****PERCENT*****","%%") + data = stringgsub(data,"([bem])!!!T!!!E!!!X!!!","%1tex") + data = stringgsub(data,"!!!!!PERCENT!!!!!","%%") fh = ioopen(newfile,"w") if not fh then return file end fh:write(data); fh:close() @@ -204,6 +205,8 @@ local function replaceinputmpfile (name,file) return newfile end +local randomseed = nil + local mpkpse = kpse.new("luatex", "mpost") local function finder(name, mode, ftype) @@ -285,6 +288,7 @@ else ini_version = true, find_file = luamplib.finder, math_mode = luamplib.numbersystem, + random_seed = randomseed, } local result if not mpx then @@ -481,72 +485,68 @@ local further_split_keys = { } local function script2table(s) - local t = {} - for i in stringgmatch(s,"[^\13]+") do - local k,v = stringmatch(i,"(.-)=(.+)") -- v may contain =. - if k and v then - local vv = {} - if further_split_keys[k] then - for j in stringgmatch(v,"[^:]+") do - vv[#vv+1] = j - end - end - if #vv > 0 then - t[k] = vv - else - t[k] = v - end - end + local t = {} + for _,i in ipairs(stringexplode(s,"\13+")) do + local k,v = stringmatch(i,"(.-)=(.*)") -- v may contain = or empty. + if k and v and k ~= "" then + if further_split_keys[k] then + t[k] = stringexplode(v,":") + else + t[k] = v + end end - return t + end + return t end local mplibcodepreamble = [[ vardef rawtextext (expr t) = - if unknown TEXBOX_: - image( special "MPlibmkTEXbox="&t; ) + if unknown TEXBOX_: + image( special "MPlibmkTEXbox="&t; ) + else: + TEXBOX_ := TEXBOX_ + 1; + if known TEXBOX_wd_[TEXBOX_]: + image ( addto currentpicture doublepath unitsquare + xscaled TEXBOX_wd_[TEXBOX_] + yscaled (TEXBOX_ht_[TEXBOX_] + TEXBOX_dp_[TEXBOX_]) + shifted (0, -TEXBOX_dp_[TEXBOX_]) + withprescript "MPlibTEXboxID=" & + decimal TEXBOX_ & ":" & + decimal TEXBOX_wd_[TEXBOX_] & ":" & + decimal(TEXBOX_ht_[TEXBOX_]+TEXBOX_dp_[TEXBOX_]); ) else: - TEXBOX_ := TEXBOX_ + 1; - image ( - addto currentpicture doublepath unitsquare - xscaled TEXBOX_wd[TEXBOX_] - yscaled (TEXBOX_ht[TEXBOX_] + TEXBOX_dp[TEXBOX_]) - shifted (0, -TEXBOX_dp[TEXBOX_]) - withprescript "MPlibTEXboxID=" & - decimal TEXBOX_ & ":" & - decimal TEXBOX_wd[TEXBOX_] & ":" & - decimal(TEXBOX_ht[TEXBOX_]+TEXBOX_dp[TEXBOX_]); - ) + image( special "MPlibTEXError=1"; ) fi + fi enddef; if known context_mlib: - defaultfont := "cmtt10"; - let infont = normalinfont; - let fontsize = normalfontsize; - vardef thelabel@#(expr p,z) = - if string p : - thelabel@#(p infont defaultfont scaled defaultscale,z) - else : - p shifted (z + labeloffset*mfun_laboff@# - - (mfun_labxf@#*lrcorner p + mfun_labyf@#*ulcorner p + - (1-mfun_labxf@#-mfun_labyf@#)*llcorner p)) - fi - enddef; - def graphictext primary filename = - if (readfrom filename = EOF): - errmessage "Please prepare '"&filename&"' in advance with command"& - " 'pstoedit -ssp -dt -f mpost yourfile.ps "&filename&"'"; - fi - closefrom filename; - def data_mpy_file = filename enddef; - mfun_do_graphic_text (filename) - enddef; - if unknown TEXBOX_: def mfun_do_graphic_text text t = enddef; fi + defaultfont := "cmtt10"; + let infont = normalinfont; + let fontsize = normalfontsize; + vardef thelabel@#(expr p,z) = + if string p : + thelabel@#(p infont defaultfont scaled defaultscale,z) + else : + p shifted (z + labeloffset*mfun_laboff@# - + (mfun_labxf@#*lrcorner p + mfun_labyf@#*ulcorner p + + (1-mfun_labxf@#-mfun_labyf@#)*llcorner p)) + fi + enddef; + def graphictext primary filename = + if (readfrom filename = EOF): + errmessage "Please prepare '"&filename&"' in advance with"& + " 'pstoedit -ssp -dt -f mpost yourfile.ps "&filename&"'"; + fi + closefrom filename; + def data_mpy_file = filename enddef; + mfun_do_graphic_text (filename) + enddef; + if unknown TEXBOX_: def mfun_do_graphic_text text t = enddef; fi else: - vardef textext@# (text t) = rawtextext (t) enddef; + vardef textext@# (text t) = rawtextext (t) enddef; fi def externalfigure primary filename = - draw rawtextext("\includegraphics{"& filename &"}") + draw rawtextext("\includegraphics{"& filename &"}") enddef; def TEX = textext enddef; def fontmapfile primary filename = enddef; @@ -557,6 +557,20 @@ extra_beginfig := extra_beginfig & " let VerbatimTeX = ignoreVerbatimTeX;" ; extra_endfig := extra_endfig & " let VerbatimTeX = specialVerbatimTeX;" ; ]] +local textextlabelpreamble = [[ +primarydef s infont f = rawtextext(s) enddef; +let normalinfont = infont; +def fontsize expr f = + begingroup + save size,pic; numeric size; picture pic; + pic := rawtextext("\hskip\pdffontsize\font"); + size := xpart urcorner pic - xpart llcorner pic; + if size = 0: 10pt else: size fi + endgroup +enddef; +let normalfontsize = fontsize; +]] + local function protecttextext(data) local everymplib = tex.toks['everymplibtoks'] or '' local everyendmplib = tex.toks['everyendmplibtoks'] or '' @@ -564,8 +578,8 @@ local function protecttextext(data) data = stringgsub(data,"\r","\n") data = stringgsub(data, "\"[^\n]-\"", function(str) - str = stringgsub(str,"%%","****PERCENT****") - str = stringgsub(str,"([bem])tex%f[^A-Z_a-z]","%1***T***E***X***") + str = stringgsub(str,"%%","!!!!!PERCENT!!!!!") + str = stringgsub(str,"([bem])tex%f[^A-Z_a-z]","%1!!!T!!!E!!!X!!!") return str end) data = stringgsub(data,"%%.-\n","") @@ -585,11 +599,11 @@ local function protecttextext(data) end) data = stringgsub(data, "\"[^\n]-\"", function(str) - str = stringgsub(str,"([bem])***T***E***X***","%1tex") - str = stringgsub(str,"{", "****LEFTBRCE****") - str = stringgsub(str,"}", "****RGHTBRCE****") - str = stringgsub(str,"#", "****SHARPE****") - return format("\\unexpanded{%s}",str) + str = stringgsub(str,"([bem])!!!T!!!E!!!X!!!","%1tex") + str = stringgsub(str,"{", "!!!!!LEFTBRCE!!!!!") + str = stringgsub(str,"}", "!!!!!RGHTBRCE!!!!!") + str = stringgsub(str,"#", "!!!!!SHARPE!!!!!") + return format("\\detokenize{%s}",str) end) texsprint(data) end @@ -599,7 +613,7 @@ luamplib.protecttextext = protecttextext local TeX_code_t = {} local function domakeTEXboxes (data) - local num = tex.count[14] -- newbox register + local num = 255 -- output box if data and data.fig then local figures = data.fig for f=1, #figures do @@ -628,13 +642,18 @@ end local function makeTEXboxes (data) data = stringgsub(data, "##", "#") -- restore # doubled in input string - data = stringgsub(data, "****PERCENT****", "%%") - data = stringgsub(data, "****LEFTBRCE****","{") - data = stringgsub(data, "****RGHTBRCE****","}") - data = stringgsub(data, "****SHARPE****", "#" ) + data = stringgsub(data, "!!!!!PERCENT!!!!!", "%%") + data = stringgsub(data, "!!!!!LEFTBRCE!!!!!","{") + data = stringgsub(data, "!!!!!RGHTBRCE!!!!!","}") + data = stringgsub(data, "!!!!!SHARPE!!!!!", "#" ) + local preamble = mplibcodepreamble + if luamplib.textextlabel then + preamble = textextlabelpreamble .. preamble + end + randomseed = math.random(65535) local mpx = luamplib.load(currentformat) if mpx and data then - local result = mpx:execute(mplibcodepreamble .. data) + local result = mpx:execute(preamble .. data) domakeTEXboxes(result) end return data @@ -645,18 +664,22 @@ luamplib.makeTEXboxes = makeTEXboxes local factor = 65536*(7227/7200) local function processwithTEXboxes (data) - local num = tex.count[14] -- the same newbox register + local num = 255 -- output box local prepreamble = "TEXBOX_ := "..num..";\n" while true do num = num + 1 local box = tex.box[num] if not box then break end prepreamble = prepreamble .. - "TEXBOX_wd["..num.."] := "..box.width /factor..";\n".. - "TEXBOX_ht["..num.."] := "..box.height/factor..";\n".. - "TEXBOX_dp["..num.."] := "..box.depth /factor..";\n" + "TEXBOX_wd_["..num.."] := "..box.width /factor..";\n".. + "TEXBOX_ht_["..num.."] := "..box.height/factor..";\n".. + "TEXBOX_dp_["..num.."] := "..box.depth /factor..";\n" end - process(prepreamble .. mplibcodepreamble .. data) + local preamble = prepreamble .. mplibcodepreamble + if luamplib.textextlabel then + preamble = textextlabelpreamble .. preamble + end + process(preamble .. data) end luamplib.processwithTEXboxes = processwithTEXboxes @@ -859,6 +882,9 @@ local function flush(result,flusher) miterlimit, linecap, linejoin, dashed = -1, -1, -1, false elseif objecttype == "special" then -- not supported + if prescript and prescript.MPlibTEXError then + warn("textext() anomaly. Try disabling \\mplibtextextlabel.") + end elseif objecttype == "text" then local ot = object.transform -- 3,4,5,6,1,2 pdf_literalcode("q %f %f %f %f %f %f cm",ot[3],ot[4],ot[5],ot[6],ot[1],ot[2]) diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty index be85a430f32..7d09685e809 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} - [2014/03/01 v2.5.3 mplib package for LuaTeX] + [2014/03/08 v2.6.0 mplib package for LuaTeX] \RequirePackage{luatexbase-modutils} \RequirePackage{pdftexcmds} \fi @@ -145,6 +145,16 @@ \fi } \def\mplibcachedir#1{\directlua{luamplib.getcachedir("\unexpanded{#1}")}} +\def\mplibtextextlabel#1{% + \begingroup + \def\tempa{enable}\def\tempb{#1}% + \ifx\tempa\tempb + \directlua{luamplib.textextlabel = true}% + \else + \directlua{luamplib.textextlabel = false}% + \fi + \endgroup +} \ifx\mplibscratchbox\undefined \newbox\mplibscratchbox \fi \def\mplibstarttoPDF#1#2#3#4{% \hbox\bgroup |