-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from dohyunkim/master
v2.5.3
- Loading branch information
Showing
2 changed files
with
99 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ See source file '\inFileName' for licencing and contact information. | |
%<*driver> | ||
\NeedsTeXFormat{LaTeX2e} | ||
\ProvidesFile{luamplib.drv}% | ||
[2014/02/24 v2.5.2 Interface for using the mplib library]% | ||
[2014/03/01 v2.5.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{[email protected]}} | ||
% \date{2014/02/24 v2.5.2} | ||
% \date{2014/03/01 v2.5.3} | ||
% | ||
% \maketitle | ||
% | ||
|
@@ -261,9 +261,20 @@ See source file '\inFileName' for licencing and contact information. | |
% \item |\mplibmakenocache{<filename>[,<filename>,...]}| | ||
% \item |\mplibcancelnocache{<filename>[,<filename>,...]}| | ||
% \end{itemize} | ||
% where |<filename>| is a filename excluding |.mp| extension. | ||
% where |<filename>| is a file name excluding |.mp| extension. | ||
% Note that |.mp| files under |[TEXMFMAIN]/metapost/base| and | ||
% |[TEXMFMAIN]/metapost/context/base| are already registered by default. | ||
% \item By default, cache files will be stored in the same directory as | ||
% pdf output file. This however can be changed by the command | ||
% |\mplibcachedir{<directory path>}|, where tilde (|~|) is interpreted | ||
% as the user's home directory (on windows machines as well). | ||
% As backslashes (|\|) should be escaped by users, it is easier to use | ||
% slashes (|/|) instead. | ||
% \item At the end of package loading, \textsf{luamplib} searches | ||
% |luamplib.cfg| and, if found, reads the file in automatically. | ||
% Frequently used settings such as |\everymplib| or |\mplibcachedir| | ||
% are suitable for going into this file. | ||
% | ||
% \end{itemize} | ||
% | ||
% There are (basically) two formats for metapost: \emph{plain} and | ||
|
@@ -296,8 +307,8 @@ luamplib.lastlog = "" | |
|
||
local err, warn, info, log = luatexbase.provides_module({ | ||
name = "luamplib", | ||
version = "2.5.2", | ||
date = "2014/02/24", | ||
version = "2.5.3", | ||
date = "2014/03/01", | ||
description = "Lua package to typeset Metapost with LuaTeX's MPLib.", | ||
}) | ||
|
||
|
@@ -321,6 +332,11 @@ local mplib = require ('mplib') | |
local kpse = require ('kpse') | ||
local lfs = require ('lfs') | ||
|
||
local lfsattributes = lfs.attributes | ||
local lfsisdir = lfs.isdir | ||
local lfstouch = lfs.touch | ||
local ioopen = io.open | ||
|
||
local file = file | ||
if not file then | ||
|
||
|
@@ -347,8 +363,40 @@ end | |
% \end{macrocode} | ||
% |btex ... etex| in input .mp files will be replaced in finder. | ||
% \begin{macrocode} | ||
local luamplibchange = kpse.find_file("luamplib.lua") | ||
luamplibchange = luamplibchange and lfs.attributes(luamplibchange,"modification") | ||
local luamplibtime = kpse.find_file("luamplib.lua") | ||
luamplibtime = luamplibtime and lfsattributes(luamplibtime,"modification") | ||
|
||
local currenttime = os.time() | ||
|
||
local outputdir = "." | ||
for _,v in ipairs(arg) do | ||
local t = stringmatch(v,"%-output%-directory=(.+)") | ||
if t then | ||
outputdir = t | ||
break | ||
end | ||
end | ||
|
||
function luamplib.getcachedir(dir) | ||
dir = stringgsub(dir,"##","#") | ||
dir = stringgsub(dir,"^~", | ||
os.type == "windows" and os.getenv("UserProfile") or os.getenv("HOME")) | ||
if lfstouch and dir then | ||
if lfsisdir(dir) then | ||
local tmp = dir.."/_luam_plib_temp_file_" | ||
local fh = ioopen(tmp,"w") | ||
if fh then | ||
fh:close(fh) | ||
os.remove(tmp) | ||
luamplib.cachedir = dir | ||
else | ||
warn("Directory '"..dir.."' is not writable!") | ||
end | ||
else | ||
warn("Directory '"..dir.."' does not exist!") | ||
end | ||
end | ||
end | ||
|
||
local noneedtoreplace = { | ||
["boxes.mp"] = true, | ||
|
@@ -389,11 +437,11 @@ local noneedtoreplace = { | |
} | ||
luamplib.noneedtoreplace = noneedtoreplace | ||
|
||
local function replaceformatmp(file,newfile) | ||
local fh = io.open(file,"r") | ||
local function replaceformatmp(file,newfile,ofmodify) | ||
local fh = ioopen(file,"r") | ||
if not fh then return file end | ||
local data = fh:read("*all"); fh:close() | ||
fh = io.open(newfile,"w") | ||
fh = ioopen(newfile,"w") | ||
if not fh then return file end | ||
fh:write( | ||
"let normalinfont = infont;\n", | ||
|
@@ -403,26 +451,25 @@ local function replaceformatmp(file,newfile) | |
"vardef Fexp_(expr x) = rawtextext(\"$^{\"&decimal x&\"}$\") enddef;\n", | ||
"let infont = normalinfont;\n" | ||
); fh:close() | ||
lfstouch(newfile,currenttime,ofmodify) | ||
return newfile | ||
end | ||
|
||
local function replaceinputmpfile (name,file) | ||
local newfile = stringgsub(name,"%.mp$","") | ||
newfile = stringgsub(newfile,"%W","_") | ||
newfile = "luamplib_input_"..newfile..".mp" | ||
if newfile and luamplibchange then | ||
local ofchange = lfs.attributes(file,"modification") | ||
local nf = lfs.attributes(newfile) | ||
local nfchange = nf and nf.modification | ||
if ofchange and nfchange and nf.mode == "file" | ||
and ofchange < nfchange and luamplibchange < nfchange | ||
then | ||
return newfile | ||
local ofmodify = lfsattributes(file,"modification") | ||
if not ofmodify then return file end | ||
local cachedir = luamplib.cachedir or outputdir | ||
local newfile = stringgsub(name,"%W","_") | ||
newfile = cachedir .."/luamplib_input_"..newfile | ||
if newfile and luamplibtime then | ||
local nf = lfsattributes(newfile) | ||
if nf and nf.mode == "file" and ofmodify == nf.modification and luamplibtime < nf.access then | ||
return nf.size == 0 and file or newfile | ||
end | ||
end | ||
if name == "format.mp" then return replaceformatmp(file,newfile) end | ||
if name == "format.mp" then return replaceformatmp(file,newfile,ofmodify) end | ||
|
||
local fh = io.open(file,"r") | ||
local fh = ioopen(file,"r") | ||
if not fh then return file end | ||
local data = fh:read("*all"); fh:close() | ||
data = stringgsub(data, "\"[^\n]-\"", | ||
|
@@ -447,13 +494,19 @@ local function replaceinputmpfile (name,file) | |
count = count + cnt | ||
if count == 0 then | ||
noneedtoreplace[name] = true | ||
fh = ioopen(newfile,"w"); | ||
if fh then | ||
fh:close() | ||
lfstouch(newfile,currenttime,ofmodify) | ||
end | ||
return file | ||
end | ||
data = stringgsub(data,"([bem])***T***E***X***","%1tex") | ||
data = stringgsub(data,"*****PERCENT*****","%%") | ||
fh = io.open(newfile,"w") | ||
fh = ioopen(newfile,"w") | ||
if not fh then return file end | ||
fh:write(data); fh:close() | ||
lfstouch(newfile,currenttime,ofmodify) | ||
return newfile | ||
end | ||
% \end{macrocode} | ||
|
@@ -471,7 +524,9 @@ local function finder(name, mode, ftype) | |
else | ||
local file = mpkpse:find_file(name,ftype) | ||
if file then | ||
if ftype ~= "mp" or noneedtoreplace[name] then return file end | ||
if not lfstouch or ftype ~= "mp" or noneedtoreplace[name] then | ||
return file | ||
end | ||
return replaceinputmpfile(name,file) | ||
end | ||
return mpkpse:find_file(name,stringmatch(name,"[a-zA-Z]+$")) | ||
|
@@ -1328,7 +1383,7 @@ luamplib.colorconverter = colorconverter | |
\else | ||
\NeedsTeXFormat{LaTeX2e} | ||
\ProvidesPackage{luamplib} | ||
[2014/02/24 v2.5.2 mplib package for LuaTeX] | ||
[2014/03/01 v2.5.3 mplib package for LuaTeX] | ||
\RequirePackage{luatexbase-modutils} | ||
\RequirePackage{pdftexcmds} | ||
\fi | ||
|
@@ -1495,6 +1550,7 @@ luamplib.colorconverter = colorconverter | |
\fi | ||
\fi | ||
} | ||
\def\mplibcachedir#1{\directlua{luamplib.getcachedir("\unexpanded{#1}")}} | ||
% \end{macrocode} | ||
% | ||
% We use a dedicated scratchbox. | ||
|
@@ -1563,6 +1619,16 @@ luamplib.colorconverter = colorconverter | |
} | ||
% \end{macrocode} | ||
% | ||
% input luamplib.cfg when it exists | ||
% | ||
% \begin{macrocode} | ||
\openin0=luamplib.cfg | ||
\ifeof0 \else | ||
\closein0 | ||
\input luamplib.cfg | ||
\fi | ||
% \end{macrocode} | ||
% | ||
% That's all folks! | ||
% | ||
% \begin{macrocode} | ||
|