summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-01-20 23:18:15 +0000
committerKarl Berry <karl@freefriends.org>2014-01-20 23:18:15 +0000
commit70a9a637489e651f4aee19179e792b79d7ab79f6 (patch)
tree7a576526987016eb599cf323acfb83e252cfac16 /Master/texmf-dist/tex/luatex
parent2b5c60ccb1ed42479efd6b30e140b111770e7114 (diff)
luamplib (20jan14)
git-svn-id: svn://tug.org/texlive/trunk@32739 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r--Master/texmf-dist/tex/luatex/luamplib/luamplib.lua52
-rw-r--r--Master/texmf-dist/tex/luatex/luamplib/luamplib.sty56
2 files changed, 67 insertions, 41 deletions
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
index 8fb71d6fe64..e0db6e0c767 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.2,
- date = "2013/12/29",
+ version = 2.3,
+ date = "2014/01/20",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
})
@@ -386,6 +386,38 @@ extra_beginfig := extra_beginfig & " let VerbatimTeX = ignoreVerbatimTeX;" ;
extra_endfig := extra_endfig & " let VerbatimTeX = specialVerbatimTeX;" ;
]]
+local function protecttextext(data)
+ local everymplib = tex.toks['everymplibtoks'] or ''
+ local everyendmplib = tex.toks['everyendmplibtoks'] or ''
+ data = " " .. everymplib .. data .. everyendmplib
+ data = stringgsub(data,
+ "%f[A-Za-z]btex%f[^A-Za-z]%s*(.-)%s*%f[A-Za-z]etex%f[^A-Za-z]",
+ function(str)
+ str = stringgsub(str,'"','"&ditto&"')
+ return format("rawtextext(\\unexpanded{\"%s\"})",str)
+ end)
+ data = stringgsub(data,
+ "%f[A-Za-z]verbatimtex%f[^A-Za-z]%s*(.-)%s*%f[A-Za-z]etex%f[^A-Za-z]",
+ function(str)
+ str = stringgsub(str,'"','"&ditto&"')
+ return format("VerbatimTeX(\\unexpanded{\"%s\"})",str)
+ end)
+ data = stringgsub(data, "\".-\"", -- hack for parentheses inside quotes
+ function(str)
+ str = stringgsub(str,"%(","%%%%LEFTPAREN%%%%")
+ str = stringgsub(str,"%)","%%%%RGHTPAREN%%%%")
+ return str
+ end)
+ data = stringgsub(data, "%f[A-Za-z]TEX%s*%b()", "\\unexpanded{%1}")
+ data = stringgsub(data, "%f[A-Za-z]textext%s*%b()", "\\unexpanded{%1}")
+ data = stringgsub(data, "%f[A-Za-z]textext%.[_a-z]+%s*%b()", "\\unexpanded{%1}")
+ data = stringgsub(data, "%%%%LEFTPAREN%%%%", "(") -- restore
+ data = stringgsub(data, "%%%%RGHTPAREN%%%%", ")") -- restore
+ texsprint(data)
+end
+
+luamplib.protecttextext = protecttextext
+
local factor = 65536*(7227/7200)
local function putTEXboxes (object,prescript)
@@ -436,22 +468,6 @@ local function domakeTEXboxes (data)
end
local function makeTEXboxes (data)
- data = "relax " .. data
- data = stringgsub(data, "([^A-Z_a-z])btex([^A-Z_a-z])",
- function(pre,post)
- post = stringgsub(post,"%s","")
- return pre .. 'rawtextext("' .. post
- end)
- data = stringgsub(data, "([^A-Z_a-z])verbatimtex([^A-Z_a-z])",
- function(pre,post)
- post = stringgsub(post,"%s","")
- return pre .. 'VerbatimTeX("' .. post
- end)
- data = stringgsub(data, "([^A-Z_a-z])etex([^A-Z_a-z])",
- function(pre,post)
- pre = stringgsub(pre,"%s","")
- return pre .. '")' .. post
- end)
local mpx = luamplib.load(currentformat)
if mpx and data then
local result = mpx:execute(mplibcodepreamble .. data)
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
index 89d55e9a8e1..548bf58dda4 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}
- [2013/12/29 v2.2 mplib package for LuaTeX]
+ [2014/01/20 v2.3 mplib package for LuaTeX]
\RequirePackage{luatexbase-modutils}
\RequirePackage{pdftexcmds}
\fi
@@ -35,7 +35,8 @@
\fi
\fi
\def\mplibsetupcatcodes{%
- \catcode`\{=12 \catcode`\}=12 \catcode`\#=12
+ %catcode`\{=12 %catcode`\}=12
+ \catcode`\#=12
\catcode`\^=12 \catcode`\~=12 \catcode`\_=12
%catcode`\%=12 %% don^^e2^^80^^99t in Plain!
\catcode`\&=12 \catcode`\$=12
@@ -51,39 +52,48 @@
}
\long\def\mplibdocode#1\endmplibcode{%
\egroup
- \directlua{
- luamplib.tempdata = luamplib.makeTEXboxes([===[\unexpanded{#1}]===])
- }%
- \directlua{
- luamplib.processwithTEXboxes(luamplib.tempdata)
- }%
+ \expandafter\def\expandafter\mplibtmp\expandafter
+ {\directlua{luamplib.protecttextext([===[\unexpanded{#1}]===])}}%
+ \directlua{luamplib.tempdata = luamplib.makeTEXboxes([===[\mplibtmp]===])}%
+ \directlua{luamplib.processwithTEXboxes(luamplib.tempdata)}%
\endgroup
}
\else
\newenvironment{mplibcode}{\toks@{}\ltxdomplibcode}{}
\def\ltxdomplibcode{%
- \bgroup
+ \begingroup
\mplibsetupcatcodes
\ltxdomplibcodeindeed %
}
-\long\def\ltxdomplibcodeindeed#1\end{%
- \egroup
- \toks@\expandafter{\the\toks@#1}\ltxdomplibcodefinally%
-}%
-\def\ltxdomplibcodefinally#1{%
- \ifnum\pdf@strcmp{#1}{mplibcode}=\z@
- \directlua{
- luamplib.tempdata = luamplib.makeTEXboxes([===[\the\toks@]===])
- }%
- \directlua{
- luamplib.processwithTEXboxes(luamplib.tempdata)
- }%
+\long\def\ltxdomplibcodeindeed#1\end#2{%
+ \endgroup
+ \toks@\expandafter{\the\toks@#1}%
+ \ifnum\pdf@strcmp{#2}{mplibcode}=\z@
+ \expandafter\def\expandafter\reserved@a\expandafter
+ {\directlua{luamplib.protecttextext([===[\the\toks@]===])}}%
+ \directlua{luamplib.tempdata=luamplib.makeTEXboxes([===[\reserved@a]===])}%
+ \directlua{luamplib.processwithTEXboxes(luamplib.tempdata)}%
\end{mplibcode}%
\else
- \toks@\expandafter{\the\toks@\end{#1}}\expandafter\ltxdomplibcode
- \fi%
+ \toks@\expandafter{\the\toks@\end{#2}}\expandafter\ltxdomplibcode
+ \fi
}
\fi
+\newtoks\everymplibtoks
+\newtoks\everyendmplibtoks
+\protected\def\everymplib{%
+ \begingroup
+ \mplibsetupcatcodes
+ \expandafter\endgroup
+ \everymplibtoks
+}
+\protected\def\everyendmplib{%
+ \begingroup
+ \mplibsetupcatcodes
+ \expandafter\endgroup
+ \everyendmplibtoks
+}
+\def\mpdim#1{ begingroup \the\dimexpr #1\relax\space endgroup } % gmp.sty
\ifx\mplibscratchbox\undefined \newbox\mplibscratchbox \fi
\def\mplibstarttoPDF#1#2#3#4{%
\hbox\bgroup