diff options
-rwxr-xr-x | Master/texmf/scripts/texlive/texconf.tlu | 527 |
1 files changed, 527 insertions, 0 deletions
diff --git a/Master/texmf/scripts/texlive/texconf.tlu b/Master/texmf/scripts/texlive/texconf.tlu new file mode 100755 index 00000000000..dca57b12d13 --- /dev/null +++ b/Master/texmf/scripts/texlive/texconf.tlu @@ -0,0 +1,527 @@ +#! /usr/bin/env texlua +--*- Lua -*- +-- $Id: $ + +-- Copyright (C) 2008 Reinhard Kotucha. +-- You may freely use, modify and/or distribute this file. + +-- texconf is a subset of Thomas Esser's texconfig shell script. + +function fixwin(args_unix) + if os.type == 'windows' then + local args_win={} -- new table + args_win[0]=args_unix[1] + for i=1, #args_unix do + args_win[i]='"'..args_unix[i]..'"' + end + return args_win + else + return args_unix + end +end + +if string.find(arg[0], '/') then -- UNIX path + filename=select(1, string.gsub(arg[0], '.*/', '')) +elseif string.find(arg[0], '\\') then -- Windows path + filename=select(1, string.gsub(arg[0], '.*\\', '')) +else -- no path + filename=arg[0] +end + +basename=select(1, string.gsub(filename, '\.texlua$', '')) + +sys=false + +if string.find(basename, '-sys$') then + basename=select(1, string.gsub(basename, '-sys$', '')) + sys=true +end + +kpse.set_program_name(filename, basename) + +if (sys) then + texmfconfig=kpse.expand_path('$TEXMFSYSCONFIG') +else + texmfconfig=kpse.expand_path('$TEXMFCONFIG') +end + + +pdftex_papersize={} +pdftex_papersize['letter']={'8.5 true in', '11 true in'} +pdftex_papersize['a4']={'210 true mm', '297 true mm'} + +xdvi_papersize={} +xdvi_papersize['us']='8.5x11' +xdvi_papersize['usr']='11x8.5' +xdvi_papersize['legal']='8.5x14' +xdvi_papersize['foolscap']='13.5x17.0' +xdvi_papersize['a1']='59.4x84.0cm' +xdvi_papersize['a2']='42.0x59.4cm' +xdvi_papersize['a3']='29.7x42.0cm' +xdvi_papersize['a4']='21.0x29.7cm' +xdvi_papersize['a5']='14.85x21.0cm' +xdvi_papersize['a6']='10.5x14.85cm' +xdvi_papersize['a7']='7.42x10.5cm' +xdvi_papersize['a1r']='84.0x59.4cm' +xdvi_papersize['a2r']='59.4x42.0cm' +xdvi_papersize['a3r']='42.0x29.7cm' +xdvi_papersize['a4r']='29.7x21.0cm' +xdvi_papersize['a5r']='21.0x14.85cm' +xdvi_papersize['a6r']='14.85x10.5cm' +xdvi_papersize['a7r']='10.5x7.42cm' +xdvi_papersize['b1']='70.6x100.0cm' +xdvi_papersize['b2']='50.0x70.6cm' +xdvi_papersize['b3']='35.3x50.0cm' +xdvi_papersize['b4']='25.0x35.3cm' +xdvi_papersize['b5']='17.6x25.0cm' +xdvi_papersize['b6']='13.5x17.6cm' +xdvi_papersize['b7']='8.8x13.5cm' +xdvi_papersize['b1r']='100.0x70.6cm' +xdvi_papersize['b2r']='70.6x50.0cm' +xdvi_papersize['b3r']='50.0x35.3cm' +xdvi_papersize['b4r']='35.3x25.0cm' +xdvi_papersize['b5r']='25.0x17.6cm' +xdvi_papersize['b6r']='17.6x13.5cm' +xdvi_papersize['b7r']='13.5x8.8cm' +xdvi_papersize['c1']='64.8x91.6cm' +xdvi_papersize['c2']='45.8x64.8cm' +xdvi_papersize['c3']='32.4x45.8cm' +xdvi_papersize['c4']='22.9x32.4cm' +xdvi_papersize['c5']='16.2x22.9cm' +xdvi_papersize['c6']='11.46x16.2cm' +xdvi_papersize['c7']='8.1x11.46cm' +xdvi_papersize['c1r']='91.6x64.8cm' +xdvi_papersize['c2r']='64.8x45.8cm' +xdvi_papersize['c3r']='45.8x32.4cm' +xdvi_papersize['c4r']='32.4x22.9cm' +xdvi_papersize['c5r']='22.9x16.2cm' +xdvi_papersize['c6r']='16.2x11.46cm' +xdvi_papersize['c7r']='11.46x8.1cm' + +dvipdfm_papersize={'letter', 'legal', 'ledger', 'tabloid', 'a4', 'a3'} + +function mkdirhier(path) + local dirs={} + local dir=path + while string.match(dir, '/') do + dirs[#dirs+1]=dir + dir=select(1, string.gsub(dir, '/[^/]*$', '')) + end + -- reverse the list + local dirlist={} + for i=1, #dirs do + dirlist[#dirlist+1]=dirs[#dirs-i+1] + end + for i=1, #dirlist do + if not lfs.isdir(dirlist[i]) then + lfs.mkdir(dirlist[i]) + end + end +end + +function set_dvips_papersize(papersize) + -- If the argument is 'list' then a list of available paper sizes is + -- returned to stdout. It can be used by dialog(1) or */Tk + -- interfaces in order to build up the menu. The topmost entry is + -- the one which is actually used by dvips. + local i, key, val + local partab={} + local par=1 + local line + local lin=1 + partab[par]={} + -- Read the file. partab{} contains all paragraphs. + kpse.set_program_name('dvips') + local filename=kpse.find_file('config.ps', 'dvips config') + -- print ('< '..filename) + local infile=assert(io.open(filename, 'r')) + while true do + line=infile:read('*line') + if line == nil then break end + if string.find(line, '^\s*$') then + par=par+1 + partab[par]={} + lin=1 + else + partab[par][lin]=line + lin=lin+1 + end + end + -- par_papersize{} is a list which associates papersizes with + -- paragraphs. Paregraphs containing no papersize information are + -- denoted by 'NO_SIZE_PAR'. + local par_papersize={} + for i=1, #partab do + par_papersize[i]='NO_SIZE_PAR' + for k=1, #partab[i] do + if string.find(partab[i][k], '^@%s') then + par_papersize[i]=string.match(partab[i][k], '^@%s+(%w+)%s') + end + end + end + infile:close() + + local index=-1 --the papagraph wich contains the desired size. + if papersize=='--list' then + -- print a list of available sizes to stdout. + -- the topmost item is the one currently used by dvips. + for key, val in ipairs(par_papersize) do + if val ~= 'NO_SIZE_PAR' and val ~= 'unknown' then + io.stdout:write(val..'\n') + end + end + elseif papersize=='help' then + io.stdout:write('Usage: texconf dvips paper PAPER\n\n'.. + 'Valid PAPER settings:\n ') + local buffer='' + for key, val in ipairs(par_papersize) do + if val ~= 'NO_SIZE_PAR' and val ~= 'unknown' then + if #buffer + #val < 77 then + buffer=buffer..' '..val + else + io.stdout:write(buffer..'\n') + buffer=' '..val + end + end + end + io.stdout:write(buffer..'\n') + else --change paper size + for key, val in ipairs(par_papersize) do + if string.find(val, '^'..papersize..'$') then + index=key + end + end + if index == -1 then + io.stderr:write('Error: Paper Size "'..papersize.. + '" undefined. Aborting...\n') + os.exit(1) + end + -- print stuff which doesn't contain paper size information. + local outfile={} + for key, val in ipairs(par_papersize) do + if val == 'NO_SIZE_PAR' then + for i=1, #partab[key] do + outfile[#outfile+1]=partab[key][i]..'\n' + end + outfile[#outfile+1]='\n' + end + end + -- print selected par + for i=1, #partab[index] do + outfile[#outfile+1]=partab[index][i]..'\n' + end + outfile[#outfile+1]='\n' + -- print other pars to outfile table + for key, val in ipairs(par_papersize) do + if val ~= 'NO_SIZE_PAR' then + if key~=index then + for i=1, #partab[key] do + outfile[#outfile+1]=partab[key][i]..'\n' + end + outfile[#outfile+1]='\n' + end + end + end + -- write file + mkdirhier(texmfconfig..'/dvips/config') + local config=assert(io.open(texmfconfig..'/dvips/config/config.ps', 'w')) + for i=1, #outfile do + if not (string.match(outfile[i],'^%s*$') + and string.match(outfile[i-1],'^%s*$')) then + config:write(outfile[i]) + end + end + config:close() + print ('> '..texmfconfig..'/dvips/config/config.ps') + end +end -- set_dvips_papersize + + +function set_xdvi_papersize(papersize) + local current_setting + -- Read the file. + kpse.set_program_name('xdvi') + local filename=kpse.find_file('XDvi', 'other text files') + + -- print ('< '..filename) + local infile=assert(io.open(filename, 'r')) + local lines={} + while true do + line=infile:read('*line') + if line == nil then break end + lines[#lines+1]=line + end + infile:close() + + if papersize=='--list' then + current_setting='a4' + for n, line in ipairs(lines) do + if string.find(line, '^\*paper:') then + current_setting=string.match(line, '^\*paper:%s+(%S+)') + for ptype, psize in pairs(xdvi_papersize) do + if current_setting==psize then + current_setting=ptype + end + end + end + end + print (current_setting) + for key, val in pairs(xdvi_papersize) do + if key ~= current_setting then + print(key) + end + end + elseif papersize=='help' then + io.stdout:write('Usage: texconf xdvi paper PAPER\n\n'.. + 'Valid PAPER settings:\n ') + local buffer='' + for ptype, psize in pairs(xdvi_papersize) do + if #buffer + #ptype < 77 then + buffer=buffer..' '..ptype + else + io.stdout:write(buffer..'\n') + buffer=' '..ptype + end + end + io.stdout:write(buffer..'\n') + else --change paper size + mkdirhier(texmfconfig..'/xdvi') + local config=assert(io.open(texmfconfig..'/xdvi/XDvi', 'w')) + for n=1, #lines do + if string.find(lines[n], '^!*\*paper:') then + config:write('*paper: '..papersize..'\n') + else + config:write(lines[n]..'\n') + end + end + config:close() + print ('> '..texmfconfig..'/xdvi/XDvi') + end +end + + +function set_pdftex_papersize(papersize) + local current_setting + --Read the file. + kpse.set_program_name('pdftex') + local filename=kpse.find_file('pdftexconfig.tex', 'tex') + + -- print ('< '..filename) + local infile=assert(io.open(filename, 'r')) + local lines={} + while true do + line=infile:read('*line') + if line == nil then break end + if string.find(line, '^\\pdfpagewidth') then + pagewidth=string.match(line, '^\\pdfpagewidth%s*=?%s*(.+)%s*$') + end + if string.find(line, '^\\pdfpageheight') then + pageheight=string.match(line, '^\\pdfpageheight%s*=?%s*(.+)%s*$') + end + lines[#lines+1]=line + end + infile:close() + + current_setting='a4' + for ptype, sizes in pairs(pdftex_papersize) do + if pagewidth == pdftex_papersize[ptype][1] then + ptype_x=ptype + end + if pageheight == pdftex_papersize[ptype][2] then + ptype_y=ptype + end + end + if ptype_x == ptype_y then + current_setting=ptype_x + end + + if papersize=='--list' then + print(current_setting) + for ptype, sizes in pairs(pdftex_papersize) do + if ptype ~= current_setting then + print(ptype) + end + end + elseif papersize=='help' then + io.stdout:write('Usage: texconf pdftex paper PAPER\n\n'.. + 'Valid PAPER settings:\n ') + local buffer='' + for ptype, sizes in pairs(pdftex_papersize) do + if #buffer + #ptype < 77 then + buffer=buffer..' '..ptype + else + io.stdout:write(buffer..'\n') + buffer=' '..ptype + end + end + io.stdout:write(buffer..'\n') + else --change paper size + mkdirhier(texmfconfig..'/tex/generic/config') + local outfile=texmfconfig..'/tex/generic/config/pdftexconfig.tex' + local config=assert(io.open(outfile, 'w')) + for n=1, #lines do + line=lines[n] + if string.find(line, '^\\pdfpagewidth') then + config:write('\\pdfpagewidth='..pdftex_papersize[papersize][1]..'\n') + elseif string.find(line, '^\\pdfpageheight') then + config:write('\\pdfpageheight='..pdftex_papersize[papersize][2]..'\n') + else + config:write(line..'\n') + end + end + config:close() + print ('> '..outfile) + end +end + + +function set_dvipdfm_papersize(papersize, program) + local current_setting + -- Read the file. + local filename + kpse.set_program_name('dvipdfm') + if program == 'dvipdfm' then + filename=kpse.find_file('config', 'other text files') + elseif program == 'dvipdfmx' then + filename=kpse.find_file('dvipdfmx.cfg', 'other text files') + end + -- print ('< '..filename) + local infile=assert(io.open(filename, 'r')) + local lines={} + local current_setting='a4' + while true do + line=infile:read('*line') + if line == nil then break end + if string.find(line, '^p ') then + current_setting=string.match(line, '^p%s+(%S+)') + end + lines[#lines+1]=line + end + infile:close() + + if papersize=='--list' then + print(current_setting) + for i, ptype in ipairs(dvipdfm_papersize) do + if ptype ~= current_setting then + print (ptype) + end + end + elseif papersize=='help' then + io.stdout:write('Usage: texconf '..program..' paper PAPER\n\n'.. + 'Valid PAPER settings:\n ') + local buffer='' + for i, ptype in pairs(dvipdfm_papersize) do + if #buffer + #ptype < 77 then + buffer=buffer..' '..ptype + else + io.stdout:write(buffer..'\n') + buffer=' '..ptype + end + end + io.stdout:write(buffer..'\n') + else --change paper size + local outfile + mkdirhier(texmfconfig..'/dvipdfm/config') + if program == 'dvipdfm' then + outfile=texmfconfig..'/dvipdfm/config/config' + mkdirhier(texmfconfig..'/dvipdfm/config') + else + outfile=texmfconfig..'/dvipdfm/config/dvipdfmx.cfg' + end + print ('> '..outfile) + local config=assert(io.open(outfile, 'w')) + for n=1, #lines do + line=lines[n] + if string.find(line, '^p ') then + config:write('p '..papersize..'\n') + else + config:write(line..'\n') + end + end + config:close() + end +end + +function set_papersize(papersize) + if papersize == '--list' then + set_pdftex_papersize('--list') + elseif papersize == 'help' then + io.stdout:write('Usage: '..basename..' paper PAPER\n\n'.. + 'Valid PAPER settings:\n a4 letter\n') + end + if papersize ~= 'a4' and papersize ~= 'letter' then + io.stdout:write('Invalid paper size "'..papersize..'".'.. + ' Valid sizes: a4 letter\n') + os.exit(1) + else + set_dvips_papersize(papersize) + set_pdftex_papersize(papersize) + set_xdvi_papersize(papersize) + set_dvipdfm_papersize(papersize, 'dvipdfm') + set_dvipdfm_papersize(papersize, 'dvipdfmx') + end +end + +function usage_main() + local usage={ + 'help', + 'xdvi paper PAPER (xdvi paper size)', + 'dvips paper PAPER (dvips paper size)', + 'pdftex paper PAPER (pdftex paper size)', + 'dvipdfm paper PAPER (dvipdfm paper size)', + 'dvipdfmx paper PAPER (dvipdfmx paper size)', + 'paper [a4|letter] (paper size for all programs)' + } + io.stdout:write('Usage:\n') + for i, msg in ipairs(usage) do + io.stdout:write(' '..basename..' '..msg..'\n') + end +end + +function usage_paper(progname) + io.stdout:write('Usage: '..basename..' '..progname..' paper PAPER\n') + io.stdout:write(' '..basename..' '..progname..' help\n') +end + +if arg[1] == 'help' then + usage_main() + +elseif arg[1] == 'paper' then + set_papersize(arg[2]) +elseif arg[1] == 'dvips' then + if arg[2] == 'help' or arg[3]==nil then + usage_paper(dvips) + elseif arg[2]=='paper' then + end +elseif arg[1] == 'xdvi' then + if arg[2] == 'help' or arg[3]==nil then + usage_paper('xdvi') + elseif arg[2]=='paper' then + set_xdvi_papersize(arg[3]) + end +elseif arg[1] == 'pdftex' then + if arg[2] == 'help' or arg[3]==nil then + usage_paper(pdftex) + elseif arg[2]=='paper' then + set_pdftex_papersize(arg[3]) + end +elseif arg[1] == 'dvipdfm' then + if arg[2] == 'help' or arg[3]==nil then + usage_paper('dvipdfm') + elseif arg[2]=='paper' then + set_dvipdfm_papersize(arg[3], 'dvipdfm') + end +elseif arg[1] == 'dvipdfmx' then + if arg[2] == 'help' or arg[3]==nil then + usage_paper('dvipdfmx') + elseif arg[2]=='paper' then + set_dvipdfm_papersize(arg[3], 'dvipdfmx') + end +end + +-- Local Variables: +-- lua-indent-level: 2 +-- tab-width: 2 +-- indent-tabs-mode: nil +-- End: +-- vim:set tabstop=2 expandtab: # |