summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/context/ruby/base/tex.rb
diff options
context:
space:
mode:
authorTaco Hoekwater <taco@elvenkind.com>2008-06-12 10:42:53 +0000
committerTaco Hoekwater <taco@elvenkind.com>2008-06-12 10:42:53 +0000
commit0d01365d53c456d246da0ca1f0b3cd9868f02b35 (patch)
tree01a655c8028e17cfb371456b299c1848fe08c05b /Master/texmf-dist/scripts/context/ruby/base/tex.rb
parent44f3714442da07fdfc36a7f2a8dcd5d4294c5d26 (diff)
ConTeXt release 2008.05.21
git-svn-id: svn://tug.org/texlive/trunk@8691 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/context/ruby/base/tex.rb')
-rw-r--r--Master/texmf-dist/scripts/context/ruby/base/tex.rb233
1 files changed, 135 insertions, 98 deletions
diff --git a/Master/texmf-dist/scripts/context/ruby/base/tex.rb b/Master/texmf-dist/scripts/context/ruby/base/tex.rb
index 8c5cc63ef53..582ff640c6e 100644
--- a/Master/texmf-dist/scripts/context/ruby/base/tex.rb
+++ b/Master/texmf-dist/scripts/context/ruby/base/tex.rb
@@ -72,6 +72,7 @@ class TEX
@@backends = Hash.new
@@mappaths = Hash.new
@@runoptions = Hash.new
+ @@tcxflag = Hash.new
@@draftoptions = Hash.new
@@texformats = Hash.new
@@mpsformats = Hash.new
@@ -89,29 +90,12 @@ class TEX
@@luafiles = "luafiles.tmp"
@@luatarget = "lua/context"
- # we now drop pdfetex definitely
-
- # ENV['PATH'].split(File::PATH_SEPARATOR).each do |p|
- # if System.unix? then
- # pp, pe = "#{p}/pdftex" , "#{p}/pdfetex"
- # else
- # pp, pe = "#{p}/pdftex.exe", "#{p}/pdfetex.exe"
- # end
- # if FileTest.file?(pe) then # we assume no update
- # @@pdftex = 'pdfetex'
- # break
- # elsif FileTest.file?(pp) then # we assume an update
- # @@pdftex = 'pdftex'
- # break
- # end
- # end
-
- # ['etex','pdfetex','standard'] .each do |e| @@texengines[e] = @@pdftex end
- # ['tex','pdftex'] .each do |e| @@texengines[e] = 'pdftex' end
+ @@platformslash = if System.unix? then "\\\\" else "\\" end
['tex','etex','pdftex','pdfetex','standard'] .each do |e| @@texengines[e] = 'pdftex' end
['aleph','omega'] .each do |e| @@texengines[e] = 'aleph' end
['xetex'] .each do |e| @@texengines[e] = 'xetex' end
+ ['petex'] .each do |e| @@texengines[e] = 'petex' end
['luatex'] .each do |e| @@texengines[e] = 'luatex' end
['metapost','mpost', 'standard'] .each do |e| @@mpsengines[e] = 'mpost' end
@@ -119,6 +103,8 @@ class TEX
['pdfetex','pdftex','pdf','pdftex','standard'] .each do |b| @@backends[b] = 'pdftex' end
['dvipdfmx','dvipdfm','dpx','dpm'] .each do |b| @@backends[b] = 'dvipdfmx' end
['xetex','xtx'] .each do |b| @@backends[b] = 'xetex' end
+ ['petex'] .each do |b| @@backends[b] = 'dvipdfmx' end
+ ['aleph'] .each do |b| @@backends[b] = 'dvipdfmx' end
['dvips','ps','dvi'] .each do |b| @@backends[b] = 'dvips' end
['dvipsone'] .each do |b| @@backends[b] = 'dvipsone' end
['acrobat','adobe','distiller'] .each do |b| @@backends[b] = 'acrobat' end
@@ -126,7 +112,7 @@ class TEX
['tex','standard'] .each do |b| @@mappaths[b] = 'dvips' end
['pdftex','pdfetex'] .each do |b| @@mappaths[b] = 'pdftex' end
- ['aleph','omega','xetex'] .each do |b| @@mappaths[b] = 'dvipdfm' end
+ ['aleph','omega','xetex','petex'] .each do |b| @@mappaths[b] = 'dvipdfm' end
['dvipdfm', 'dvipdfmx', 'xdvipdfmx'] .each do |b| @@mappaths[b] = 'dvipdfm' end
['xdv','xdv2pdf'] .each do |b| @@mappaths[b] = 'dvips' end
@@ -148,34 +134,40 @@ class TEX
['plain','mpost'] .each do |f| @@mpsformats[f] = 'plain' end
['metafun','context','standard'] .each do |f| @@mpsformats[f] = 'metafun' end
- # no 'standard' progname ! / beware, when using texexec we always use the context/metafun values
-
- ['pdftex','pdfetex','aleph','omega',
+ ['pdftex','pdfetex','aleph','omega','petex',
'xetex','luatex'] .each do |p| @@prognames[p] = 'context' end
['mpost'] .each do |p| @@prognames[p] = 'metafun' end
+ ['latex','pdflatex'] .each do |p| @@prognames[p] = 'latex' end
['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
- ['latex'] .each do |f| @@texmethods[f] = 'latex' end
+ ['latex','pdflatex'] .each do |f| @@texmethods[f] = 'latex' end
['plain','default','standard'] .each do |f| @@mpsmethods[f] = 'plain' end
['metafun'] .each do |f| @@mpsmethods[f] = 'metafun' end
- @@texmakestr['plain'] = "\\dump"
- @@mpsmakestr['plain'] = "\\dump"
+ @@texmakestr['plain'] = @@platformslash + "dump"
+ @@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] = "\\emergencyend" end
+ 'cont-fr','cont-cz','cont-ro','cont-uk'] .each do |f| @@texprocstr[f] = @@platformslash + "emergencyend" end
- # @@runoptions['xetex'] = ['--output-driver \\\"-d 4 -V 5\\\"'] # we need the pos pass
- # @@runoptions['xetex'] = ['--8bit','-no-pdf'] # from now on we assume (x)dvipdfmx to be used
- @@runoptions['xetex'] = ['--8bit','-output-driver="xdvipdfmx -E -d 4 -V 5"']
- @@runoptions['pdfetex'] = ['--8bit'] # obsolete
- @@runoptions['pdftex'] = ['--8bit'] # pdftex is now pdfetex
- @@runoptions['luatex'] = ['--file-line-error']
@@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"']
+
+ @@tcxflag['aleph'] = true
+ @@tcxflag['luatex'] = false
+ @@tcxflag['mpost'] = true
+ @@tcxflag['pdfetex'] = true
+ @@tcxflag['pdftex'] = true
+ @@tcxflag['petex'] = false
+ @@tcxflag['xetex'] = false
@@draftoptions['pdftex'] = ['--draftmode']
@@ -480,8 +472,10 @@ class TEX
def validprogname(str)
if str then
[str].flatten.each do |s|
+ s = s.sub(/\.\S*/,"")
return @@prognames[s] if @@prognames.key?(s)
end
+ return str[0].sub(/\.\S*/,"")
else
return nil
end
@@ -497,11 +491,7 @@ class TEX
else return ""
end
if format then
- # if engine then
- # "#{prefix}=#{engine}/#{format}"
- # else
- "#{prefix}=#{format}"
- # end
+ "#{prefix}=#{format.sub(/\.\S+$/,"")}"
else
prefix
end
@@ -542,11 +532,16 @@ class TEX
"--ini"
end
end
- def tcxflag(file="natural.tcx")
- if Kpse.miktex? then
- "-tcx=#{file}"
+ def tcxflag(engine)
+ if @@tcxflag[engine] then
+ file = "natural.tcx"
+ if Kpse.miktex? then
+ "-tcx=#{file}"
+ else
+ "-translate-file=#{file}"
+ end
else
- "-translate-file=#{file}"
+ ""
end
end
@@ -582,7 +577,7 @@ class TEX
if data = (IO.readlines(@@luafiles) rescue nil) then
report("compiling lua files (using #{File.expand_path(@@luafiles)})")
begin
- Dir.makedirs(@@luatarget) rescue false
+ File.makedirs(@@luatarget) rescue false
data.each do |line|
luafile = line.chomp
lucfile = File.basename(luafile).gsub(/\..*?$/,'') + ".luc"
@@ -612,15 +607,12 @@ class TEX
report('using existing database')
else
report('updating file database')
- Kpse.update
+ Kpse.update # obsolete here
if getvariable('luatex') then
begin
- luatools = `texmfstart luatools --format=texmfscripts luatools.lua`.chomp.strip
- unless luatools.empty? then
- runcommand(["luatex","--luaonly #{luatools}","--generate","--verbose"])
- end
+ runcommand(["luatools","--generate","--verbose"])
rescue
- report("run 'luatex --luaonly pathto/luatools.lua --generate' manually")
+ report("run 'luatools --generate' manualy")
exit
end
end
@@ -666,12 +658,13 @@ class TEX
texformats.each do |texformat|
report("generating tex format #{texformat}")
progname = validprogname([getvariable('progname'),texformat,texengine])
- runcommand([quoted(texengine),prognameflag(progname),iniflag,tcxflag,prefixed(texformat,texengine),texmakeextras(texformat)])
+ runcommand([quoted(texengine),prognameflag(progname),iniflag,tcxflag(texengine),prefixed(texformat,texengine),texmakeextras(texformat)])
end
end
else
report("unable to make format due to lack of permissions")
texformatpath = ''
+ setvariable('error','no permissions to write')
end
else
texformatpath = ''
@@ -686,7 +679,7 @@ 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,runoptions(mpsengine),mpsformat,mpsmakeextras(mpsformat)]) then
+ if not runcommand([quoted(mpsengine),prognameflag(progname),iniflag,tcxflag(mpsengine),runoptions(mpsengine),mpsformat,mpsmakeextras(mpsformat)]) then
setvariable('error','no format made')
end
end
@@ -783,12 +776,12 @@ class TEX
result = runtexexec([tempfilename], flags, 1)
if FileTest.file?("#{@@temprunfile}.log") then
logdata = IO.read("#{@@temprunfile}.log")
- if logdata =~ /^\s*This is (.*?)[\s\,]+(.*?)$/mois then
+ if logdata =~ /^\s*This is (.*?)[\s\,]+(.*?)$/moi then
if validtexengine($1.downcase) then
results.push("#{$1} #{$2.gsub(/\(format.*$/,'')}".strip)
end
end
- if logdata =~ /^\s*(ConTeXt)\s+(.*int:\s+[a-z]+.*?)\s*$/mois then
+ if logdata =~ /^\s*(ConTeXt)\s+(.*int:\s+[a-z]+.*?)\s*$/moi then
results.push("#{$1} #{$2}".gsub(/\s+/,' ').strip)
end
else
@@ -817,12 +810,12 @@ class TEX
private
- def makeuserfile
+ def makeuserfile # not used in luatex (yet)
language = getvariable('language')
mainlanguage = getvariable('mainlanguage')
bodyfont = getvariable('bodyfont')
if f = openedfile("cont-fmt.tex") then
- f << "\\unprotect"
+ f << "\\unprotect\n"
case language
when 'all' then
f << "\\preloadallpatterns\n"
@@ -910,9 +903,14 @@ class TEX
end
if ok then
# we have a valid line
+
@@preamblekeys.each do |v|
setvariable(v[1],vars[v[0]]) if vars.key?(v[0]) && vars[v[0]]
end
+
+if getvariable('given.backend') == "standard" or getvariable('given.backend') == "" then
+ setvariable('backend',@@backends[getvariable('texengine')] || 'standard')
+end
break
end
else
@@ -932,7 +930,8 @@ class TEX
case str.chomp
when /^\%/o then
# next
- when /\\(starttekst|stoptekst|startonderdeel|startdocument|startoverzicht)/o then
+ # when /\\(starttekst|stoptekst|startonderdeel|startdocument|startoverzicht)/o then
+ when /\\(starttekst|stoptekst|startonderdeel|startoverzicht)/o then
setvariable('texformats','nl') ; break
when /\\(stelle|verwende|umgebung|benutze)/o then
setvariable('texformats','de') ; break
@@ -1104,8 +1103,10 @@ class TEX
end
rescue TimeoutError
report("job aborted due to timeout '#{delay}'")
+ setvariable('error','timeout')
rescue
report("job aborted due to error")
+ setvariable('error','fatal error')
else
report("job finished within timeout '#{delay}'")
end
@@ -1153,18 +1154,22 @@ class TEX
public
- def run_luatools(args)
+ # def run_luatools(args)
# dirty trick: we know that the lua path is relative to the ruby path; of course this
# will not work well when stubs are used
- [(ENV["_CTX_K_S_texexec_"] or ENV["_CTX_K_S_THREAD_"] or ENV["TEXMFSTART.THREAD"]), File.dirname($0)].each do |path|
- if path then
- script = "#{path}/../lua/luatools.lua"
- if FileTest.file?(script) then
- return runcommand("luatex --luaonly #{script} #{args}")
- end
- end
- end
- return runcommand("texmfstart luatools #{args}")
+ # [(ENV["_CTX_K_S_texexec_"] or ENV["_CTX_K_S_THREAD_"] or ENV["TEXMFSTART.THREAD"]), File.dirname($0)].each do |path|
+ # if path then
+ # script = "#{path}/../lua/luatools.lua"
+ # if FileTest.file?(script) then
+ # return runcommand("luatex --luaonly #{script} #{args}")
+ # end
+ # end
+ # end
+ # return runcommand("texmfstart luatools #{args}")
+ # end
+
+ def run_luatools(args)
+ return runcommand("luatools #{args}")
end
def processmpgraphic
@@ -1182,7 +1187,7 @@ class TEX
begin
data = IO.read(File.suffixed(filename,'log'))
basename = filename.sub(/\.mp$/, '')
- if data =~ /output files* written\:\s*(.*)$/mois then
+ if data =~ /output files* written\:\s*(.*)$/moi then
files, number, range, list = $1.split(/\s+/), 0, false, []
files.each do |fname|
if fname =~ /^.*\.(\d+)$/ then
@@ -1268,7 +1273,7 @@ class TEX
File.open("texexec.tex",'w') do |f|
f << "\\setupoutput[pdftex]\n"
f << "\\setupcolors[state=start]\n"
- data.sub!(/^%mpenvironment\:\s*(.*?)$/mois) do
+ data.sub!(/^%mpenvironment\:\s*(.*?)$/moi) do
f << $1
"\n"
end
@@ -1448,9 +1453,10 @@ class TEX
end
end
opt << "\\protect\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
+ # begin getvariable('modes' ).split(',').uniq.each do |e| opt << "\\enablemode [#{e}]\n" end ; rescue ; end
+ 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"
@@ -1485,7 +1491,14 @@ class TEX
[getvariable('runpath'),getvariable('path')].each do |pat|
unless pat.empty? then
if ENV.key?(res) then
- ENV[res] = if ENV[res].empty? then pat else pat + ":" + ENV[res] end
+ # ENV[res] = if ENV[res].empty? then pat else pat + ":" + ENV[res] end
+if ENV[res].empty? then
+ ENV[res] = pat
+elsif ENV[res] == pat || ENV[res] =~ /^#{pat}\:/ || ENV[res] =~ /\:#{pat}\:/ then
+ # skip
+else
+ ENV[res] = pat + ":" + ENV[res]
+end
else
ENV[res] = pat
end
@@ -1544,7 +1557,7 @@ class TEX
run_luatools("--fmt=#{texformat} #{filename}")
else
progname = validprogname([getvariable('progname'),texformat,texengine])
- runcommand([quoted(texengine),prognameflag(progname),formatflag(texengine,texformat),tcxflag,runoptions(texengine),filename,texprocextras(texformat)])
+ runcommand([quoted(texengine),prognameflag(progname),formatflag(texengine,texformat),tcxflag(texengine),runoptions(texengine),filename,texprocextras(texformat)])
end
# true
else
@@ -1559,8 +1572,7 @@ class TEX
if mpsengine && mpsformat then
ENV["MPXCOMMAND"] = "0" unless mpx
progname = validprogname([getvariable('progname'),mpsformat,mpsengine])
- runcommand([quoted(mpsengine),prognameflag(progname),formatflag(mpsengine,mpsformat),tcxflag,runoptions(mpsengine),mpname,mpsprocextras(mpsformat)])
- # runcommand([quoted(mpsengine),formatflag(mpsengine,mpsformat),tcxflag,runoptions(mpsengine),mpname,mpsprocextras(mpsformat)])
+ runcommand([quoted(mpsengine),prognameflag(progname),formatflag(mpsengine,mpsformat),tcxflag(mpsengine),runoptions(mpsengine),mpname,mpsprocextras(mpsformat)])
true
else
false
@@ -1728,14 +1740,9 @@ class TEX
takeprecautions
report("using search method '#{Kpse.searchmethod}'") if getvariable('verbose')
+
rawname = getvariable('filename')
jobname = getvariable('filename')
- suffix = getvariable('suffix')
- result = getvariable('result')
- forcexml = getvariable('forcexml')
- runonce = getvariable('once')
- finalrun = getvariable('final') || (getvariable('arrange') && ! getvariable('noarrange'))
- globalfile = getvariable('globalfile')
if getvariable('autopath') then
jobname = File.basename(jobname)
@@ -1748,18 +1755,11 @@ class TEX
jobname = File.unixfied(jobname)
inppath = File.unixfied(inppath)
- result = File.unixfied(result)
orisuffix = jobsuffix # still needed ?
- setvariable('nomprun',true) if orisuffix == 'mpx' # else cylic run
-
- PDFview.setmethod('xpdf') if getvariable('xpdf')
-
- PDFview.closeall if getvariable('autopdf')
-
if jobsuffix =~ /^(htm|html|xhtml|xml|fo|fox|rlg|exa)$/io then
- forcexml = true
+ setvariable('forcexml',true)
end
dummyfile = false
@@ -1776,7 +1776,6 @@ class TEX
# we can have funny names, like 2005.10.10 (given without suffix)
rawname = jobname + '.' + jobsuffix
-
rawpath = File.dirname(rawname)
rawbase = File.basename(rawname)
@@ -1786,16 +1785,22 @@ class TEX
end
end
- if dummyfile || forcexml then
+ forcexml = getvariable('forcexml')
+
+ if dummyfile || forcexml then # after ctx?
jobsuffix = makestubfile(rawname,rawbase,forcexml)
checkxmlfile(rawname)
end
-
# preprocess files
unless getvariable('noctx') then
ctx = CtxRunner.new(rawname,@logger)
+ if pth = getvariable('path') then
+ pth.split(',').each do |p|
+ ctx.register_path(p)
+ end
+ end
if getvariable('ctxfile').empty? then
if rawname == rawbase then
ctx.manipulate(File.suffixed(rawname,'ctx'),'jobname.ctx')
@@ -1810,6 +1815,7 @@ class TEX
envs = ctx.environments
mods = ctx.modules
flags = ctx.flags
+ mdes = ctx.modes
flags.each do |f|
f.sub!(/^\-+/,'')
@@ -1825,24 +1831,47 @@ class TEX
# merge environment and module specs
envs << getvariable('environments') unless getvariable('environments').empty?
- mods << getvariable('modules') unless getvariable('modules') .empty?
+ mods << getvariable('usemodules') unless getvariable('usemodules') .empty?
+ mdes << getvariable('modes') unless getvariable('modes') .empty?
envs = envs.uniq.join(',')
mods = mods.uniq.join(',')
+ mdes = mdes.uniq.join(',')
report("using search method '#{Kpse.searchmethod}'") if getvariable('verbose')
+
report("using environments #{envs}") if envs.length > 0
report("using modules #{mods}") if mods.length > 0
+ report("using modes #{mdes}") if mdes.length > 0
setvariable('environments', envs)
- setvariable('modules', mods)
+ setvariable('usemodules', mods)
+ setvariable('modes', mdes)
end
# end of preprocessing and merging
+ setvariable('nomprun',true) if orisuffix == 'mpx' # else cylic run
+ PDFview.setmethod('xpdf') if getvariable('xpdf')
+ PDFview.closeall if getvariable('autopdf')
+
+ runonce = getvariable('once')
+ finalrun = getvariable('final') || (getvariable('arrange') && ! getvariable('noarrange'))
+ suffix = getvariable('suffix')
+ result = getvariable('result')
+ globalfile = getvariable('globalfile')
+ forcexml = getvariable('forcexml') # can be set in ctx file
+
+if dummyfile || forcexml then # after ctx?
+ jobsuffix = makestubfile(rawname,rawbase,forcexml)
+ checkxmlfile(rawname)
+end
+
+ result = File.unixfied(result)
+
if globalfile || FileTest.file?(rawname) then
- if not dummyfile and not globalfile then
+ if not dummyfile and not globalfile and not forcexml then
scantexpreamble(rawname)
scantexcontent(rawname) if getvariable('texformats').standard?
end
@@ -1897,7 +1926,15 @@ class TEX
end
end
# goto .
+
ok = runtex(File.suffixed(if dummyfile || forcexml then rawbase else rawname end,jobsuffix))
+
+if getvariable('texengine') == "xetex" then
+ ok = true
+end
+
+############################
+
# goto tmp/jobname when present
if ok && (nofruns > 1) then
unless getvariable('nompmode') then
@@ -1951,7 +1988,7 @@ class TEX
# next line is empty
ok = 2
when 2 then
- if line =~ /^\%\s+\>\s+(.*?)\s+(\d+)/mois then
+ if line =~ /^\%\s+\>\s+(.*?)\s+(\d+)/moi then
filename, n = $1, $2
done = File.delete(filename) rescue false
if done && getvariable('verbose') then
@@ -1961,7 +1998,7 @@ class TEX
break
end
else
- if line =~ /^\%\s+temporary files\:\s+(\d+)/mois then
+ if line =~ /^\%\s+temporary files\:\s+(\d+)/moi then
if $1.to_i == 0 then
break
else
@@ -2021,7 +2058,7 @@ class TEX
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