input:b0011v0002p0013e0006-e0,1,2,k110,111,r0,1,8,amlsfw 1ˆÌŽþDêÍË(„�+@þÑ 39ÖÁÓ'1#!/bin/sh mtxrun --script context "$@" 53ˆl–ßi~”T¾R( ÅýÀ·q–”Å£�þBg î¶ùK/óÒ ƒh¹×ÂÔ3input:b0011v0002p0013e0006-e0,1,3,k110,111,112,ra0,1,mlsfw 65ˆl–ßi~”ên-j}@à]¸)‹Fÿ�þC(†³N´26Ü�G�üÿÓ ƒu÷^ØÃÕ*5#!/usr/bin/env texlua local options = { pdfoutput=true, redoall=false, multipicfile=false, noborder=false, dotypesetting=true, nopostprocess=false, } local usagetext = 'Usage: cachepic [options] latexfile' local tryhelp = "Try `cachepic --help' for more information" local helptext = [[ Options start with '-' or '--' and can be any of: -pdf output in (e)pdf format (default) -eps output in eps format -all regenerate all graphics -multi all graphics in one file (implies -pdf) -tight no 0.5bp margin around the graphic -notex no typesetting, only graphic postprocessing -nopic generate no graphics, only .cachepic file -usage display usage message -help,-h,-? display help message]] local msg = { MultipleInputFiles = "cannot process multiple files:\t%s\t%s", NoInputFile = "no input file given\n" .. tryhelp, UnknownOption = "unknown option: %s\n" .. tryhelp, FileOpenFailed = "could not open file: %s", NoGhostScript = "could not locate ghostscript interpreter", WrongOutputMode = "expected %s output but got %s", NoPreviews = "no cachepic previews found", MultiPicOnlyInPDF = "option '-multi' for all graphics in one file supported only in pdf mode" } function die(msgfmt, ...) error(string.format(msgfmt, ...)) end function warn(msgfmt, ...) print('warning: ' .. string.format(msgfmt, ...)) end local function qfile(filename) filename = string.gsub(filename, '"', '') if string.find(filename, "[%s%&%(%)%[%]%{%}%^%=%;%!%'%+%,%`%~]") then filename = '"' .. filename .. '"' end return filename end local function syscall(command) print('system: ' .. command) local ret = os.execute(command) if ret > 0 then os.exit(ret) else return ret end end local function copyfile(src, dst) print('copy ' .. qfile(src) .. ' ' .. qfile(dst)) local buffer, bufsize = '', 1024 local fin = io.open(src, 'rb') if not fin then die(msg.FileOpenFailed, src) end local fout = io.open(dst, 'wb') if not fout then die(msg.FileOpenFailed, dst) end while buffer do fout:write(buffer) buffer = fin:read(bufsize) end fin:close() fout:close() end local isfile = lfs and lfs.isfile or function (fname) -- if we are not running under texlua, then do it the hard way local fh = io.open(fname) return (fh and (fh:close() or true) or false) end local function whichfile(fname, path) if isfile(fname) then return fname end -- make the best guess if it is Windows or Unix local dirsep, pathsep = '/', ':' if (os.type == 'windows') or string.find(path, '\\') or string.find(path, ';') then dirsep, pathsep = '\\', ';' -- Windows end -- iterate path for dir in string.gmatch(path, '[^' .. pathsep .. ']+') do local f = dir .. dirsep .. fname -- print(f) if isfile(f) then return f end end return nil end local function findgs() local path = os.getenv('PATH') for _, fname in ipairs{'gs', 'gswin32c.exe', 'mgs.exe'} do if whichfile(fname, path) then return fname end end die(msg.NoGhostScript) end -- Process options -- if #arg == 0 then print(usagetext) print(tryhelp) os.exit(0) end local filename = nil for _, argn in ipairs(arg) do local opt, num = string.gsub(argn, '^%-%-?', '') if num == 0 then -- not an option if filename then die(msg.MultipleInputFiles, filename, opt) else filename = opt end elseif opt == 'eps' then options.pdfoutput = false elseif opt == 'pdf' then options.pdfoutput = true elseif opt == 'all' then options.redoall = true elseif opt == 'multi' then options.multipicfile = true elseif opt == 'tight' then options.noborder = true elseif opt == 'notex' then options.dotypesetting = false els