summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source
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/source
parent2b5c60ccb1ed42479efd6b30e140b111770e7114 (diff)
luamplib (20jan14)
git-svn-id: svn://tug.org/texlive/trunk@32739 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source')
-rw-r--r--Master/texmf-dist/source/luatex/luamplib/luamplib.dtx166
1 files changed, 113 insertions, 53 deletions
diff --git a/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx b/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx
index 2f673d7f773..f6c95a77d21 100644
--- a/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx
+++ b/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx
@@ -1,6 +1,6 @@
% \iffalse meta-comment -- by the way, this file contains UTF-8
%
-% Copyright (C) 2008-2010 by Hans Hagen, Taco Hoekwater, Elie Roux,
+% Copyright (C) 2008-2014 by Hans Hagen, Taco Hoekwater, Elie Roux,
% Manuel Pégourié-Gonnard, Philipp Gesang and Kim Dohyun.
% Currently maintained by the LuaLaTeX development team.
% Support: <lualatex-dev@tug.org>
@@ -85,7 +85,7 @@ See source file '\inFileName' for licencing and contact information.
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{luamplib.drv}%
- [2013/12/29 v2.2 Interface for using the mplib library]%
+ [2014/01/20 v2.3 Interface for using the mplib library]%
\documentclass{ltxdoc}
\usepackage{metalogo,multicol,mdwlist,fancyvrb,xspace}
\usepackage[x11names]{xcolor}
@@ -154,7 +154,7 @@ See source file '\inFileName' for licencing and contact information.
% \author{Hans Hagen, Taco Hoekwater, Elie Roux, Philipp Gesang and Kim Dohyun\\
% Maintainer: LuaLaTeX Maintainers ---
% Support: \email{lualatex-dev@tug.org}}
-% \date{2013/12/29 v2.2}
+% \date{2014/01/20 v2.3}
%
% \maketitle
%
@@ -176,6 +176,10 @@ See source file '\inFileName' for licencing and contact information.
% The metapost figures are put in a \TeX\ \texttt{hbox} with dimensions
% adjusted to the metapost code.
%
+% Using this package is easy: in Plain, type your metapost code between the
+% macros \cs{mplibcode} and \cs{endmplibcode}, and in \LaTeX\ in the
+% \texttt{mplibcode} environment.
+%
% The code is from the \texttt{luatex-mplib.lua} and \texttt{luatex-mplib.tex} files
% from \ConTeXt, they have been adapted to \LaTeX\ and Plain by Elie Roux and
% Philipp Gesang, new functionalities have been added by Kim Dohyun.
@@ -189,12 +193,12 @@ See source file '\inFileName' for licencing and contact information.
% |textext()| is a more versatile macro equivalent to |TEX()| from TEX.mp.
% |TEX()| is also allowed unless TEX.mp is loaded, which should be always
% avoided.
-% \item \verb|verbatimtex ... etex| that comes just before \verb|beginfig()|
+% \item |verbatimtex ... etex| that comes just before |beginfig()|
% is not ignored, but the \TeX\ code inbetween will be inserted before the
% following mplib hbox. Using this command,
% each mplib box can be freely moved horizontally and/or vertically.
-% All other \verb|verbatimtex ... etex|'s are ignored.
-% \textsc{e.g.}:
+% All other |verbatimtex ... etex|'s are ignored.
+% \textsc{e.g.}
% \begin{verbatim}
% \mplibcode
% verbatimtex \moveright 3cm etex; beignfig(0); ... endfig;
@@ -204,15 +208,37 @@ See source file '\inFileName' for licencing and contact information.
% \endmplibcode
% \end{verbatim}
% \textsc{n.b.} \cs{endgraf} should be used instead of \cs{par} inside
-% \verb|verbatimtex ... etex|.
+% |verbatimtex ... etex|.
% \item Notice that, after each figure is processed, macro \cs{MPwidth} stores
% the width value of latest figure; \cs{MPheight}, the height value.
+% \item Since v2.3, new macros \cs{everymplib} and \cs{everyendmplib} redefine
+% token lists \cs{everymplibtoks} and \cs{everyendmplibtoks} respectively,
+% which will
+% be automatically inserted at the beginning and ending of each mplib code.
+% \textsc{e.g.}
+% \begin{verbatim}
+% \everymplib{ verbatimtex \leavevmode etex; beginfig(0); }
+% \everyendmplib{ endfig; }
+% \mplibcode % befinfig/endfig not needed; always in horizontal mode
+% draw fullcircle scaled 1cm;
+% \endmplibcode
+% \end{verbatim}
+% \item Since v2.3, \cs{mpdim} and other raw \TeX\ commands are allowed
+% inside mplib code. This feature is inpired by gmp.sty authored by
+% Enrico Gregorio. Please refer the manual of gmp package for details.
+% \textsc{e.g.}
+% \begin{verbatim}
+% \begin{mplibcode}
+% draw origin--(\mpdim{\linewidth},0) withpen pencircle scaled 4
+% dashed evenly scaled 4 withcolor \myrulecolor;
+% \end{mplibcode}
+% \end{verbatim}
+% \textsc{n.b.} Users should not use the protected variant of
+% |btex ... etex| as provided by gmp package. As \textsf{luamplib}
+% automatically protects \TeX\ code inbetween, \cs{btex} is not supported
+% here.
% \end{itemize}
%
-% Using this package is easy: in Plain, type your metapost code between the
-% macros \cs{mplibcode} and \cs{endmplibcode}, and in \LaTeX\ in the
-% \texttt{mplibcode} environment.
-%
% There are (basically) two formats for metapost: \emph{plain} and
% \emph{metafun}. By default, the \emph{plain} format is used, but you can set
% the format to be used by future figures at any time using
@@ -243,8 +269,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.",
})
@@ -588,6 +614,9 @@ end
% \verb|TEX()| is synonym of \verb|textext()| unless TEX.mp is loaded.
%
% v2.2: Transparency and Shading
+%
+% v2.2: \cs{everymplib}, \cs{everyendmplib},
+% and allows naked \TeX\ commands.
% \begin{macrocode}
local further_split_keys = {
["MPlibTEXboxID"] = true,
@@ -662,6 +691,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)
@@ -716,22 +777,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)
@@ -1109,7 +1154,7 @@ luamplib.colorconverter = colorconverter
\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
@@ -1146,7 +1191,8 @@ luamplib.colorconverter = colorconverter
\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’t in Plain!
\catcode`\&=12 \catcode`\$=12
@@ -1172,12 +1218,10 @@ luamplib.colorconverter = colorconverter
}
\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
@@ -1188,32 +1232,48 @@ luamplib.colorconverter = colorconverter
% \begin{macrocode}
\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
% \end{macrocode}
%
+% \cs{everymplib} \& \cs{everyendmplib}: macros redefining
+% \cs{everymplibtoks} \& \cs{everyendmplibtoks} respectively
+%
+% \begin{macrocode}
+\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
+% \end{macrocode}
+%
% We use a dedicated scratchbox.
%
% \begin{macrocode}