summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/context/ruby/base/tex.rb
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts/context/ruby/base/tex.rb')
-rw-r--r--Master/texmf-dist/scripts/context/ruby/base/tex.rb316
1 files changed, 189 insertions, 127 deletions
diff --git a/Master/texmf-dist/scripts/context/ruby/base/tex.rb b/Master/texmf-dist/scripts/context/ruby/base/tex.rb
index 582ff640c6e..23db7f1e872 100644
--- a/Master/texmf-dist/scripts/context/ruby/base/tex.rb
+++ b/Master/texmf-dist/scripts/context/ruby/base/tex.rb
@@ -16,6 +16,8 @@
# report ?
+require 'fileutils'
+
require 'base/variables'
require 'base/kpse'
require 'base/system'
@@ -67,28 +69,26 @@ class TEX
include Variables
- @@texengines = Hash.new
- @@mpsengines = Hash.new
- @@backends = Hash.new
- @@mappaths = Hash.new
- @@runoptions = Hash.new
- @@tcxflag = Hash.new
- @@draftoptions = Hash.new
- @@texformats = Hash.new
- @@mpsformats = Hash.new
- @@prognames = Hash.new
- @@texmakestr = Hash.new
- @@texprocstr = Hash.new
- @@mpsmakestr = Hash.new
- @@mpsprocstr = Hash.new
-
- @@texmethods = Hash.new
- @@mpsmethods = Hash.new
-
- @@pdftex = 'pdftex' # new default, pdfetex is gone
-
- @@luafiles = "luafiles.tmp"
- @@luatarget = "lua/context"
+ @@texengines = Hash.new
+ @@mpsengines = Hash.new
+ @@backends = Hash.new
+ @@mappaths = Hash.new
+ @@runoptions = Hash.new
+ @@tcxflag = Hash.new
+ @@draftoptions = Hash.new
+ @@synctexcoptions = Hash.new
+ @@texformats = Hash.new
+ @@mpsformats = Hash.new
+ @@prognames = Hash.new
+ @@texmakestr = Hash.new
+ @@texprocstr = Hash.new
+ @@mpsmakestr = Hash.new
+ @@mpsprocstr = Hash.new
+ @@texmethods = Hash.new
+ @@mpsmethods = Hash.new
+ @@pdftex = 'pdftex' # new default, pdfetex is gone
+ @@luafiles = "luafiles.tmp"
+ @@luatarget = "lua/context"
@@platformslash = if System.unix? then "\\\\" else "\\" end
@@ -112,8 +112,8 @@ class TEX
['tex','standard'] .each do |b| @@mappaths[b] = 'dvips' end
['pdftex','pdfetex'] .each do |b| @@mappaths[b] = 'pdftex' end
- ['aleph','omega','xetex','petex'] .each do |b| @@mappaths[b] = 'dvipdfm' end
- ['dvipdfm', 'dvipdfmx', 'xdvipdfmx'] .each do |b| @@mappaths[b] = 'dvipdfm' end
+ ['aleph','omega','xetex','petex'] .each do |b| @@mappaths[b] = 'dvipdfmx' end
+ ['dvipdfm', 'dvipdfmx', 'xdvipdfmx'] .each do |b| @@mappaths[b] = 'dvipdfmx' end
['xdv','xdv2pdf'] .each do |b| @@mappaths[b] = 'dvips' end
# todo norwegian (no)
@@ -124,14 +124,16 @@ class TEX
['cont-de','de','german'] .each do |f| @@texformats[f] = 'cont-de' end
['cont-it','it','italian'] .each do |f| @@texformats[f] = 'cont-it' end
['cont-fr','fr','french'] .each do |f| @@texformats[f] = 'cont-fr' end
- ['cont-cz','cz','czech'] .each do |f| @@texformats[f] = 'cont-cz' end
+ ['cont-cs','cs','cont-cz','cz','czech'] .each do |f| @@texformats[f] = 'cont-cs' end
['cont-ro','ro','romanian'] .each do |f| @@texformats[f] = 'cont-ro' end
- ['cont-uk','uk','british'] .each do |f| @@texformats[f] = 'cont-uk' end
+ ['cont-gb','gb','cont-uk','uk','british'] .each do |f| @@texformats[f] = 'cont-gb' end
+ ['cont-pe','pe','persian'] .each do |f| @@texformats[f] = 'cont-pe' end
+ ['cont-xp','xp','experimental'] .each do |f| @@texformats[f] = 'cont-xp' end
['mptopdf'] .each do |f| @@texformats[f] = 'mptopdf' end
['latex'] .each do |f| @@texformats[f] = 'latex.ltx' end
- ['plain','mpost'] .each do |f| @@mpsformats[f] = 'plain' end
+ ['plain','mpost'] .each do |f| @@mpsformats[f] = 'mpost' end
['metafun','context','standard'] .each do |f| @@mpsformats[f] = 'metafun' end
['pdftex','pdfetex','aleph','omega','petex',
@@ -141,7 +143,8 @@ class TEX
['plain','default','standard','mptopdf'] .each do |f| @@texmethods[f] = 'plain' end
['cont-en','cont-nl','cont-de','cont-it',
- 'cont-fr','cont-cz','cont-ro','cont-uk'] .each do |f| @@texmethods[f] = 'context' end
+ 'cont-fr','cont-cs','cont-ro','cont-gb',
+ 'cont-pe','cont-xp'] .each do |f| @@texmethods[f] = 'context' end
['latex','pdflatex'] .each do |f| @@texmethods[f] = 'latex' end
['plain','default','standard'] .each do |f| @@mpsmethods[f] = 'plain' end
@@ -151,28 +154,31 @@ class TEX
@@mpsmakestr['plain'] = @@platformslash + "dump"
['cont-en','cont-nl','cont-de','cont-it',
- 'cont-fr','cont-cz','cont-ro','cont-uk'] .each do |f| @@texprocstr[f] = @@platformslash + "emergencyend" end
-
- @@runoptions['aleph'] = ['--8bit']
- @@runoptions['luatex'] = ['--file-line-error']
- @@runoptions['mpost'] = ['--8bit']
- @@runoptions['pdfetex'] = ['--8bit'] # obsolete
- @@runoptions['pdftex'] = ['--8bit'] # pdftex is now pdfetex
- # @@runoptions['petex'] = []
- @@runoptions['xetex'] = ['--8bit','-output-driver="xdvipdfmx -E -d 4 -V 5"']
+ 'cont-fr','cont-cs','cont-ro','cont-gb',
+ 'cont-pe','cont-xp'] .each do |f| @@texprocstr[f] = @@platformslash + "emergencyend" end
+
+ @@runoptions['aleph'] = ['--8bit']
+ @@runoptions['luatex'] = ['--file-line-error']
+ @@runoptions['mpost'] = ['--8bit']
+ @@runoptions['pdfetex'] = ['--8bit'] # obsolete
+ @@runoptions['pdftex'] = ['--8bit'] # pdftex is now pdfetex
+ # @@runoptions['petex'] = []
+ @@runoptions['xetex'] = ['--8bit','-output-driver="xdvipdfmx -E -d 4 -V 5"']
+ @@draftoptions['pdftex'] = ['--draftmode']
+ @@synctexcoptions['pdftex'] = ['--synctex=1']
+ @@synctexcoptions['luatex'] = ['--synctex=1']
+ @@synctexcoptions['xetex'] = ['--synctex=1']
@@tcxflag['aleph'] = true
@@tcxflag['luatex'] = false
- @@tcxflag['mpost'] = true
+ @@tcxflag['mpost'] = false
@@tcxflag['pdfetex'] = true
@@tcxflag['pdftex'] = true
@@tcxflag['petex'] = false
@@tcxflag['xetex'] = false
- @@draftoptions['pdftex'] = ['--draftmode']
-
- @@booleanvars = [
- 'batchmode', 'nonstopmode', 'fast', 'fastdisabled', 'silentmode', 'final',
+ @@mainbooleanvars = [
+ 'batchmode', 'nonstopmode', 'fast', 'final',
'paranoid', 'notparanoid', 'nobanner', 'once', 'allpatterns', 'draft',
'nompmode', 'nomprun', 'automprun', 'combine',
'nomapfiles', 'local',
@@ -184,19 +190,20 @@ class TEX
'globalfile', 'autopath',
'purge', 'purgeall', 'keep', 'autopdf', 'xpdf', 'simplerun', 'verbose',
'nooptionfile', 'nobackend', 'noctx', 'utfbom',
- 'mkii',
+ 'mkii','mkiv',
+ 'synctex',
]
- @@stringvars = [
+ @@mainstringvars = [
'modefile', 'result', 'suffix', 'response', 'path',
'filters', 'usemodules', 'environments', 'separation', 'setuppath',
'arguments', 'input', 'output', 'randomseed', 'modes', 'mode', 'filename',
'ctxfile', 'printformat', 'paperformat', 'paperoffset',
'timeout', 'passon'
]
- @@standardvars = [
+ @@mainstandardvars = [
'mainlanguage', 'bodyfont', 'language'
]
- @@knownvars = [
+ @@mainknownvars = [
'engine', 'distribution', 'texformats', 'mpsformats', 'progname', 'interface',
'runs', 'backend'
]
@@ -205,29 +212,31 @@ class TEX
@@extrastringvars = []
def booleanvars
- [@@booleanvars,@@extrabooleanvars].flatten.uniq
+ [@@mainbooleanvars,@@extrabooleanvars].flatten.uniq
end
def stringvars
- [@@stringvars,@@extrastringvars].flatten.uniq
+ [@@mainstringvars,@@extrastringvars].flatten.uniq
end
def standardvars
- [@@standardvars].flatten.uniq
+ [@@mainstandardvars].flatten.uniq
end
def knownvars
- [@@knownvars].flatten.uniq
+ [@@mainknownvars].flatten.uniq
end
def allbooleanvars
- [@@booleanvars,@@extrabooleanvars].flatten.uniq
+ [@@mainbooleanvars,@@extrabooleanvars].flatten.uniq
end
def allstringvars
- [@@stringvars,@@extrastringvars,@@standardvars,@@knownvars].flatten.uniq
+ [@@mainstringvars,@@extrastringvars,@@mainstandardvars,@@mainknownvars].flatten.uniq
end
def setextrastringvars(vars)
- @@extrastringvars << vars
+ # @@extrastringvars << vars -- problems in 1.9
+ @@extrastringvars = [@@extrastringvars,vars].flatten
end
def setextrabooleanvars(vars)
- @@extrabooleanvars << vars
+ # @@extrabooleanvars << vars -- problems in 1.9
+ @@extrabooleanvars = [@@extrabooleanvars,vars].flatten
end
# def jobvariables(names=nil)
@@ -378,6 +387,7 @@ class TEX
def runoptions(engine)
options = if getvariable('draft') then @@draftoptions[engine] else [] end
+ options = if getvariable('synctex') then @@synctexcoptions[engine] else [] end
begin
if str = getvariable('passon') then
options = [options,str.split(' ')].flatten
@@ -577,7 +587,7 @@ class TEX
if data = (IO.readlines(@@luafiles) rescue nil) then
report("compiling lua files (using #{File.expand_path(@@luafiles)})")
begin
- File.makedirs(@@luatarget) rescue false
+ FileUtils.makedirs(@@luatarget) rescue false
data.each do |line|
luafile = line.chomp
lucfile = File.basename(luafile).gsub(/\..*?$/,'') + ".luc"
@@ -640,10 +650,14 @@ class TEX
report("using tex format path #{texformatpath}")
Dir.chdir(texformatpath) rescue false
if FileTest.writable?(texformatpath) then
- if texformats.length > 0 then
- makeuserfile
- makeresponsefile
- end
+ # from now on we no longer support this; we load
+ # all patterns and if someone wants another
+ # interface language ... cook up a fmt or usr file
+ #
+ # if texformats.length > 0 then
+ # makeuserfile
+ # makeresponsefile
+ # end
if texengine == 'luatex' then
cleanupluafiles
texformats.each do |texformat|
@@ -679,7 +693,8 @@ class TEX
mpsformats.each do |mpsformat|
report("generating mps format #{mpsformat}")
progname = validprogname([getvariable('progname'),mpsformat,mpsengine])
- if not runcommand([quoted(mpsengine),prognameflag(progname),iniflag,tcxflag(mpsengine),runoptions(mpsengine),mpsformat,mpsmakeextras(mpsformat)]) then
+ # if not runcommand([quoted(mpsengine),prognameflag(progname),iniflag,tcxflag(mpsengine),runoptions(mpsengine),mpsformat,mpsmakeextras(mpsformat)]) then
+ if not runcommand([quoted(mpsengine),prognameflag(progname),iniflag,runoptions(mpsengine),mpsformat,mpsmakeextras(mpsformat)]) then
setvariable('error','no format made')
end
end
@@ -879,7 +894,7 @@ class TEX
def scantexpreamble(filename)
begin
- if FileTest.file?(filename) and tex = File.open(filename) then
+ if FileTest.file?(filename) and tex = File.open(filename,'rb') then
bomdone = false
while str = tex.gets and str.chomp! do
unless bomdone then
@@ -925,7 +940,7 @@ end
end
def scantexcontent(filename)
- if FileTest.file?(filename) and tex = File.open(filename) then
+ if FileTest.file?(filename) and tex = File.open(filename,'rb') then
while str = tex.gets do
case str.chomp
when /^\%/o then
@@ -1002,7 +1017,11 @@ end
tmp << "\\starttext\n"
if forcexml then
# tmp << checkxmlfile(rawname)
- tmp << "\\processXMLfilegrouped{#{rawname}}\n"
+ if getvariable('mkiv') then
+ tmp << "\\xmlprocess{\\xmldocument}{#{rawname}}{}\n"
+ else
+ tmp << "\\processXMLfilegrouped{#{rawname}}\n"
+ end
else
tmp << "\\processfile{#{rawname}}\n"
end
@@ -1056,7 +1075,7 @@ end
end
def checkxmlfile(rawname)
- if FileTest.file?(rawname) && (xml = File.open(rawname)) then
+ if FileTest.file?(rawname) && (xml = File.open(rawname,'rb')) then
xml.each do |line|
case line
when /<\?context\-directive\s+(\S+)\s+(\S+)\s+(\S+)\s*(.*?)\s*\?>/o then
@@ -1322,12 +1341,9 @@ class TEX
# local handies
opt << "\% #{topname}\n"
opt << "\\unprotect\n"
- if getvariable('utfbom') then
- opt << "\\enableregime[utf]"
- end
- opt << "\\setupsystem[\\c!n=#{kindofrun},\\c!m=#{currentrun}]\n"
- progname = validprogname(['metafun']) # [getvariable('progname'),mpsformat,mpsengine]
- opt << "\\def\\MPOSTformatswitch\{#{prognameflag(progname)} #{formatflag('mpost')}=\}\n"
+ #
+ # feedback and basic control
+ #
if getvariable('batchmode') then
opt << "\\batchmode\n"
end
@@ -1337,6 +1353,21 @@ class TEX
if getvariable('paranoid') then
opt << "\\def\\maxreadlevel{1}\n"
end
+ if getvariable('nomapfiles') then
+ opt << "\\disablemapfiles\n"
+ end
+ if getvariable('nompmode') || getvariable('nomprun') || getvariable('automprun') then
+ opt << "\\runMPgraphicsfalse\n"
+ end
+ if getvariable('utfbom') then
+ opt << "\\enableregime[utf]"
+ end
+ progname = validprogname(['metafun']) # [getvariable('progname'),mpsformat,mpsengine]
+ opt << "\\def\\MPOSTformatswitch\{#{prognameflag(progname)} #{formatflag('mpost')}=\}\n"
+ #
+ # process info
+ #
+ opt << "\\setupsystem[\\c!n=#{kindofrun},\\c!m=#{currentrun}]\n"
if (str = File.unixfied(getvariable('modefile'))) && ! str.empty? then
opt << "\\readlocfile{#{str}}{}{}\n"
end
@@ -1353,6 +1384,35 @@ class TEX
if (str = getvariable('mainlanguage').downcase) && ! str.empty? && ! str.standard? then
opt << "\\setuplanguage[#{str}]\n"
end
+ if (str = getvariable('arguments')) && ! str.empty? then
+ opt << "\\setupenv[#{str}]\n"
+ end
+ if (str = getvariable('setuppath')) && ! str.empty? then
+ opt << "\\setupsystem[\\c!directory=\{#{str}\}]\n"
+ end
+ if (str = getvariable('randomseed')) && ! str.empty? then
+ report("using randomseed #{str}")
+ opt << "\\setupsystem[\\c!random=#{str}]\n"
+ end
+ if (str = getvariable('input')) && ! str.empty? then
+ opt << "\\setupsystem[inputfile=#{str}]\n"
+ else
+ opt << "\\setupsystem[inputfile=#{rawname}]\n"
+ end
+ #
+ # modes
+ #
+ # we handle both "--mode" and "--modes", else "--mode" is mapped onto "--modefile"
+ if (str = getvariable('modes')) && ! str.empty? then
+ opt << "\\enablemode[#{str}]\n"
+ end
+ if (str = getvariable('mode')) && ! str.empty? then
+ opt << "\\enablemode[#{str}]\n"
+ end
+ #
+ # options
+ #
+ opt << "\\startsetups *runtime:options\n"
if str = validbackend(getvariable('backend')) then
opt << "\\setupoutput[#{str}]\n"
elsif str = validbackend(getvariable('output')) then
@@ -1361,21 +1421,9 @@ class TEX
if getvariable('color') then
opt << "\\setupcolors[\\c!state=\\v!start]\n"
end
- if getvariable('nompmode') || getvariable('nomprun') || getvariable('automprun') then
- opt << "\\runMPgraphicsfalse\n"
- end
- if getvariable('fast') && ! getvariable('fastdisabled') then
- opt << "\\fastmode\n"
- end
- if getvariable('silentmode') then
- opt << "\\silentmode\n"
- end
if (str = getvariable('separation')) && ! str.empty? then
opt << "\\setupcolors[\\c!split=#{str}]\n"
end
- if (str = getvariable('setuppath')) && ! str.empty? then
- opt << "\\setupsystem[\\c!directory=\{#{str}\}]\n"
- end
if (str = getvariable('paperformat')) && ! str.empty? && ! str.standard? then
if str =~ /^([a-z]+\d+)([a-z]+\d+)$/io then # A5A4 A4A3 A2A1 ...
opt << "\\setuppapersize[#{$1.upcase}][#{$2.upcase}]\n"
@@ -1392,9 +1440,6 @@ class TEX
if getvariable('centerpage') then
opt << "\\setuplayout[\\c!location=\\v!middle,\\c!marking=\\v!on]\n"
end
- if getvariable('nomapfiles') then
- opt << "\\disablemapfiles\n"
- end
if getvariable('noarrange') then
opt << "\\setuparranging[\\v!disable]\n"
elsif getvariable('arrange') then
@@ -1412,26 +1457,6 @@ class TEX
end
opt << "\\setuparranging[#{arrangement.flatten.join(',')}]\n" if arrangement.size > 0
end
- # we handle both "--mode" and "--modes", else "--mode" is
- # mapped onto "--modefile"
- if (str = getvariable('modes')) && ! str.empty? then
- opt << "\\enablemode[#{str}]\n"
- end
- if (str = getvariable('mode')) && ! str.empty? then
- opt << "\\enablemode[#{str}]\n"
- end
- if (str = getvariable('arguments')) && ! str.empty? then
- opt << "\\setupenv[#{str}]\n"
- end
- if (str = getvariable('randomseed')) && ! str.empty? then
- report("using randomseed #{str}")
- opt << "\\setupsystem[\\c!random=#{str}]\n"
- end
- if (str = getvariable('input')) && ! str.empty? then
- opt << "\\setupsystem[inputfile=#{str}]\n"
- else
- opt << "\\setupsystem[inputfile=#{rawname}]\n"
- end
if (str = getvariable('pages')) && ! str.empty? then
if str.downcase == 'odd' then
opt << "\\chardef\\whichpagetoshipout=1\n"
@@ -1452,14 +1477,18 @@ class TEX
opt << "\\def\\pagestoshipout\{#{pagelist.join(',')}\}\n";
end
end
- opt << "\\protect\n";
- # begin getvariable('modes' ).split(',').uniq.each do |e| opt << "\\enablemode [#{e}]\n" end ; rescue ; end
+ opt << "\\stopsetups\n"
+ #
+ # styles and modules
+ #
+ opt << "\\startsetups *runtime:modules\n"
begin getvariable('filters' ).split(',').uniq.each do |f| opt << "\\useXMLfilter[#{f}]\n" end ; rescue ; end
begin getvariable('usemodules' ).split(',').uniq.each do |m| opt << "\\usemodule [#{m}]\n" end ; rescue ; end
begin getvariable('environments').split(',').uniq.each do |e| opt << "\\environment #{e} \n" end ; rescue ; end
- # this will become:
- # begin getvariable('environments').split(',').uniq.each do |e| opt << "\\useenvironment[#{e}]\n" end ; rescue ; end
- opt << "\\endinput\n"
+ opt << "\\stopsetups\n"
+ #
+ opt << "\\protect \\endinput\n"
+ #
opt.close
else
report("unable to write option file #{topname}")
@@ -1572,7 +1601,9 @@ end
if mpsengine && mpsformat then
ENV["MPXCOMMAND"] = "0" unless mpx
progname = validprogname([getvariable('progname'),mpsformat,mpsengine])
- runcommand([quoted(mpsengine),prognameflag(progname),formatflag(mpsengine,mpsformat),tcxflag(mpsengine),runoptions(mpsengine),mpname,mpsprocextras(mpsformat)])
+ mpname.gsub!(/\.mp$/,"") # temp bug in mp
+ # runcommand([quoted(mpsengine),prognameflag(progname),formatflag(mpsengine,mpsformat),tcxflag(mpsengine),runoptions(mpsengine),mpname,mpsprocextras(mpsformat)])
+ runcommand([quoted(mpsengine),prognameflag(progname),formatflag(mpsengine,mpsformat),runoptions(mpsengine),mpname,mpsprocextras(mpsformat)])
true
else
false
@@ -1582,7 +1613,7 @@ end
def runtexmp(filename,filetype='',purge=true)
checktestversion
mpname = File.suffixed(filename,filetype,'mp')
- if File.atleast?(mpname,25) then
+ if File.atleast?(mpname,10) then
# first run needed
File.silentdelete(File.suffixed(mpname,'mpt'))
doruntexmp(mpname,nil,true,purge)
@@ -1620,7 +1651,7 @@ end
end
def runtexutil(filename=[], options=['--ref','--ij','--high'], old=false)
- filename.each do |fname|
+ [filename].flatten.each do |fname|
if old then
Kpse.runscript('texutil',fname,options)
else
@@ -1980,7 +2011,7 @@ end
end
if true then # autopurge
begin
- File.open(File.suffixed(rawbase, 'tuo')) do |f|
+ File.open(File.suffixed(rawbase, 'tuo'),'rb') do |f|
ok = 0
f.each do |line|
case ok
@@ -2058,7 +2089,7 @@ end
setvariable('mp.line','')
setvariable('mp.error','')
if mpdata = File.silentread(mpname) then
- mpdata.gsub!(/^\%.*\n/o,'')
+ # mpdata.gsub!(/^\%.*\n/o,'')
File.silentrename(mpname,mpcopy)
texfound = mergebe || (mpdata =~ /btex .*? etex/mo)
if mp = openedfile(mpname) then
@@ -2075,10 +2106,11 @@ end
mp << mergebe['0'] if mergebe.key?('0')
end
end
- mp << MPTools::splitmplines(mpdata)
- mp << "\n"
- mp << "end"
+ # mp << MPTools::splitmplines(mpdata)
+ mp << mpdata
mp << "\n"
+ # mp << "end"
+ # mp << "\n"
mp.close
end
processmpx(mpname,true,true,purge) if texfound
@@ -2090,7 +2122,10 @@ end
options = ''
end
# todo plain|mpost|metafun
- ok = runmp(mpname)
+ begin
+ ok = runmp(mpname)
+ rescue
+ end
if f = File.silentopen(File.suffixed(mpname,'log')) then
while str = f.gets do
if str =~ /^l\.(\d+)\s(.*?)\n/o then
@@ -2174,30 +2209,57 @@ end
end
def checkmpgraphics(mpname)
+ # in practice the checksums will differ because of multiple instances
+ # ok, we could save the mpy/mpo files by number, but not now
mpoptions = ''
if getvariable('makempy') then
mpoptions += " --makempy "
end
+ mponame = File.suffixed(mpname,'mpo')
+ mpyname = File.suffixed(mpname,'mpy')
+ pdfname = File.suffixed(mpname,'pdf')
+ tmpname = File.suffixed(mpname,'tmp')
if getvariable('mpyforce') || getvariable('forcempy') then
mpoptions += " --force "
else
- mponame = File.suffixed(mpname,'mpo')
- mpyname = File.suffixed(mpname,'mpy')
return false unless File.atleast?(mponame,32)
mpochecksum = FileState.new.checksum(mponame)
return false if mpochecksum.empty?
# where does the checksum get into the file?
# maybe let texexec do it?
# solution: add one if not present or update when different
- if f = File.silentopen(mpyname) then
- str = f.gets.chomp
- f.close
- if str =~ /^\%\s*mpochecksum\s*\:\s*(\d+)/o then
- return false if mpochecksum == $1
+ begin
+ mpydata = IO.read(mpyname)
+ if mpydata then
+ if mpydata =~ /^\%\s*mpochecksum\s*\:\s*([A-Z0-9]+)$/mo then
+ checksum = $1
+ if mpochecksum == checksum then
+ return false
+ end
+ end
+ end
+ rescue
+ # no file
+ end
+ end
+ # return Kpse.runscript('makempy',mpname)
+ # only pdftex
+ flags = ['--noctx','--process','--batch','--once']
+ result = runtexexec([mponame], flags, 1)
+ runcommand(["pstoedit","-ssp -dt -f mpost", pdfname,tmpname])
+ tmpdata = IO.read(tmpname)
+ if tmpdata then
+ if mpy = openedfile(mpyname) then
+ mpy << "% mpochecksum: #{mpochecksum}\n"
+ tmpdata.scan(/beginfig(.*?)endfig/mo) do |s|
+ mpy << "begingraphictextfig#{s}endgraphictextfig\n"
end
+ mpy.close()
end
end
- return Kpse.runscript('makempy',mpname)
+ File.silentdelete(tmpname)
+ File.silentdelete(pdfname)
+ return true
end
def checkmplabels(mpname)