aboutsummaryrefslogtreecommitdiff
path: root/texall
diff options
context:
space:
mode:
authorSebastian Kuhnert2008-08-21 12:41:30 +0000
committerSebastian Kuhnert2008-08-21 12:41:30 +0000
commit2e4af8c3561ea94c33a70b92c6eae87a0929532a (patch)
tree50bab0d41cda9671367b1a8f8ffd1c915d2057f1 /texall
parent6f15ced1c19e5e100624f3852113ed0e539d43ae (diff)
downloadexercisesheets-2e4af8c3561ea94c33a70b92c6eae87a0929532a.tar.gz
exercisesheets-2e4af8c3561ea94c33a70b92c6eae87a0929532a.tar.bz2
exercisesheets-2e4af8c3561ea94c33a70b92c6eae87a0929532a.zip
texall script: smarter rmligs integration, works for documents spread over several files
Diffstat (limited to 'texall')
-rwxr-xr-xtexall121
1 files changed, 70 insertions, 51 deletions
diff --git a/texall b/texall
index 9c79120..c9bd3c7 100755
--- a/texall
+++ b/texall
@@ -59,6 +59,11 @@ def error(file, desc, warning=False):
print msg
errors.append(msg)
+if os.path.exists("/dev/null"):
+ null = file("/dev/null", "wb")
+else:
+ null = file("nul:", "wb")
+
path = os.path.expandvars("$PATH")
if path == "$PATH":
path = os.path.defpath
@@ -69,7 +74,6 @@ def isinpath(name):
return True
return False
-
if isinpath("rmligs"):
rmligs_name = "rmligs"
elif isinpath("rmligs-german"):
@@ -259,13 +263,17 @@ def processtexfiles(args):
if options.progress:
print "processing %s%s..."%(os.path.normpath(os.path.join(dirname,texname)),reason)
+ # list of temporary files to be removed later
+ tmplist = []
+
# support for pstricks/plain latex:
tex = detecttextype(dirname, texname)
# detect usage of german/ngerman
rmligs = detectrmligs(dirname, texname)
+ realname = preparermligs(texname, dirname, tmplist)
- runtex(tex, texname, dirname, rmligs)
+ runtex(tex, texname, realname, dirname)
#strip .tex extension
jobname=texname[:-4]
@@ -283,7 +291,7 @@ def processtexfiles(args):
else:
reason = " (because of --force)"
run(["bibtex8", "--wolfgang", jobname], dirname, reason=reason)
- runtex(tex, texname, dirname, rmligs, reason=" (because of updated .bbl)")
+ runtex(tex, texname, realname, dirname, reason=" (because of updated .bbl)")
break
# check for undefined references and run requests
@@ -301,7 +309,7 @@ def processtexfiles(args):
if options.verbosity:
reason = " (because of request in .aux file, priority %d)"%rp
if req == "latex":
- runtex(tex, texname, dirname, rmligs, reason=reason)
+ runtex(tex, texname, realname, dirname, reason=reason)
elif req == "bibtex":
run(["bibtex8", "--wolfgang", jobname], dirname, reason=reason)
else:
@@ -315,13 +323,14 @@ def processtexfiles(args):
idx = jobname + ".idx"
if os.path.isfile(os.path.join(dirname, idx)):
run(["makeindex", jobname], dirname, reason=" (because .idx file might have changed)")
- runtex(tex, texname, dirname, rmligs, reason=" (because .ind file might have changed)")
+ runtex(tex, texname, realname, dirname, reason=" (because .ind file might have changed)")
if tex == "latex":
run(["dvips", jobname+".dvi"], dirname)
run(["ps2pdf", jobname+".ps"], dirname)
- rmtempfile(jobname+"-rmligs.tex", dirname)
+ for n in tmplist:
+ rmtempfile(n, dirname)
re_logmatcher = re.compile("^LaTeX Warning: There were undefined references\.$|^LaTeX Warning: Label\(s\) may have changed\. Rerun to get cross-references right\.$|^REQ:(\d+):(\w+):")
def requests(logpath):
@@ -369,64 +378,74 @@ def haderrors(dirname, jobname):
def rmtempfile(filename, dirname):
fullname = os.path.join(dirname, filename)
- if options.deletetempfiles and os.path.isfile(fullname):
+ if options.deletetempfiles:
if options.progress:
print " removing %s"%filename
- os.remove(fullname)
+ if options.act:
+ if os.path.isfile(fullname):
+ os.remove(fullname)
+ else:
+ error(filename, "could not be removed (does not exist)", warning=True)
-def run(arglist, dirname, reason="", infile=None, outfile=None):
+def run(arglist, dirname, reason="", stdin=None, stdout=None):
if options.verbosity>2:
# use default
output=None
else:
- output=file("/dev/null")
- if infile:
- try:
- stdin=open(os.path.join(dirname, infile), "r")
- indesc=" < %s"%infile
- except IOError, (errno, strerror):
- if output:
- output.close()
- error(infile, "input file could not be read: %s"%strerror)
- return
- else:
- stdin=None
- indesc=""
- if outfile:
- try:
- stdout=open(os.path.join(dirname, outfile), "w")
- outdesc=" > %s"%outfile
- except IOError, (errno, strerror):
- if output:
- output.close()
- if stdin:
- stdin.close()
- error(outfile, "output file could not be read: %s"%strerror)
- return
- else:
- stdout=output
- outdesc=""
+ output=null
+ if not stdout:
+ stdout=output
if options.progress:
- print " running %s%s%s%s..."%(" ".join(arglist), indesc, outdesc,reason)
+ print " running %s%s..."%(" ".join(arglist), reason)
if options.act:
ret = subprocess.call(arglist, stdin=stdin, stdout=stdout, stderr=output, cwd=dirname)
if ret:
error(dirname, "failed command: %s"%(" ".join(arglist)))
- if output:
- output.close()
- if stdin:
- stdin.close()
- if stdout and stdout is not output:
- stdout.close()
-
-def runtex(tex, texname, dirname, rmligs=False, reason=""):
- if rmligs and rmligs_name != "":
- jobname=texname[:-4]
- rmligsname=jobname+"-rmligs.tex"
- run([rmligs_name, "-f"], dirname, infile=texname, outfile=rmligsname, reason=reason)
- run([tex, "-interaction", interactionmode, "-jobname", jobname, rmligsname], dirname, reason)
+
+def preparermligs(texname, dirname, tmplist):
+ jobname=texname[:-4]
+ rmligsname=jobname+"-rmligs.tex"
+ if options.progress:
+ print " running rmligs on %s..."%texname
+ try:
+ texfile = open(os.path.join(dirname, texname))
+ except IOError, (errno, strerror):
+ error(texname, "could not be read: %s. Not using rmligs."%strerror)
+ return texname
+ else:
+ try:
+ if options.act:
+ rmligsfile = open(os.path.join(dirname, rmligsname), "w")
+ else:
+ rmligsfile = null
+ except exceptIOError, (errno, strerror):
+ error(rmligsname, "could not be written: %s. Not using rmligs."%strerror)
+ return texname
+ else:
+ tmplist.append(rmligsname)
+ proc = subprocess.Popen([rmligs_name, "-f"], stdin=texfile, stdout=subprocess.PIPE, cwd=dirname)
+
+ def rewriteinputrmligs(m):
+ name=m.group(2)
+ if not os.path.isfile(os.path.join(dirname,name)):
+ name+=".tex"
+ if os.path.isfile(os.path.join(dirname, name)):
+ name = preparermligs(name, dirname, tmplist)
+ else:
+ error(name, "File could not be located. Not using rmligs.", warning=True)
+ return "\\%s{%s}"%(m.group(1), name)
+ for line in proc.stdout:
+ rmligsfile.write(re_inputinclude.sub(rewriteinputrmligs, line))
+ texfile.close()
+ if rmligsfile is not null:
+ rmligsfile.close()
+ return rmligsname
+
+def runtex(tex, texname, realname, dirname, reason=""):
+ if texname != realname:
+ run([tex, "-interaction", interactionmode, "-jobname", texname[:-4], realname], dirname, reason=reason)
else:
- run([tex, "-interaction", interactionmode, texname], dirname, reason)
+ run([tex, "-interaction", interactionmode, texname], dirname, reason=reason)
# main program:
try: