diff options
author | Karl Berry <karl@freefriends.org> | 2014-10-11 22:30:33 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2014-10-11 22:30:33 +0000 |
commit | 4888499385c44655bec69496f0e01649d7636627 (patch) | |
tree | b4530c653b64a9b165768c4423d6bcf0dd192c31 /Master/texmf-dist/scripts/latex-make | |
parent | 9406c7d3ffc09ac95d52d72e53d84e010a0a747d (diff) |
latex-make (11oct14)
git-svn-id: svn://tug.org/texlive/trunk@35357 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/latex-make')
-rwxr-xr-x | Master/texmf-dist/scripts/latex-make/figdepth.py | 51 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/latex-make/gensubfig.py | 63 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/latex-make/latexfilter.py | 59 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/latex-make/svg2dev.py | 42 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/latex-make/svgdepth.py | 55 |
5 files changed, 270 insertions, 0 deletions
diff --git a/Master/texmf-dist/scripts/latex-make/figdepth.py b/Master/texmf-dist/scripts/latex-make/figdepth.py new file mode 100755 index 00000000000..7782d0b29e6 --- /dev/null +++ b/Master/texmf-dist/scripts/latex-make/figdepth.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +#coding=utf8 + +""" + +stdin : the original xfig file +stdout : the output xfig file +args : all depths we want to keep + +""" + +import optparse +import os.path +import sys + +def main(): + parser = optparse.OptionParser() + (options, args) = parser.parse_args() + + depths_to_keep = set() + for arg in args: + depths_to_keep.add(arg) + + comment = '' + display = True + def show(depth, line): + if depth in depths_to_keep: + print comment+line, + return True + else: + return False + for line in sys.stdin: + if line[0] == '#': + comment += line + continue + if line[0] in "\t ": + if display: + print line + else: + Fld = line.split(' ', 9999) + if not Fld[0] or Fld[0] not in ('1', '2', '3', '4', '5'): + print comment+line + display = True + elif Fld[0] == '4': + display = show(Fld[3], line) + else: + display = show(Fld[6], line) + comment = '' + +if __name__ == "__main__": + main() diff --git a/Master/texmf-dist/scripts/latex-make/gensubfig.py b/Master/texmf-dist/scripts/latex-make/gensubfig.py new file mode 100755 index 00000000000..a6fcd5d5677 --- /dev/null +++ b/Master/texmf-dist/scripts/latex-make/gensubfig.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +#coding=utf8 + +""" + +Arguments passes : + - fichier image (image.fig ou image.svg) + - -s fichier subfig (image.subfig) + - -p chemin du script pour generer les sous-images (svgdepth.py ou figdepth.py) + +Sortie standard : + - makefile pour creer les sous-images (au format .fig ou .svg), et pour les supprimer + +""" + +from optparse import OptionParser +import os.path + +def main(): + parser = OptionParser(usage='usage: %prog [options] svg file', description='Creates a\ +Makefile generating subfigures using figdepth.py or svgdepth.py') + parser.add_option("-s", "--subfig", dest="subfig", help="subfig file") + parser.add_option("-p", "--depth", dest="depth", help="full path of depth script") + (options, args) = parser.parse_args() + if len(args) < 1: + parser.error("incorrect number of arguments") + if not options.subfig: + parser.error("no subfig file specified") + if not options.depth: + parser.error("no depth script specified") + + (root, ext) = os.path.splitext(args[0]) + sf_name = options.subfig + ds_name = options.depth + varname = '%s_FIGS' % root.upper() + + subfigs = [] + for line in open(options.subfig, 'r'): + t = line.find('#') # looking for comments + if t > -1: line = line[0:t] # remove comments... + line = line.strip() #remove blank chars + if line == '': continue + subfigs.append(line) + + count = 1 + for subfig in subfigs: + print "%s_%d%s: %s%s %s" % (root, count, ext, root, ext, sf_name) + print "\t%s %s" % (ds_name, subfig) + print "" + count += 1 + print "%s := $(foreach n, " % varname, + count = 1 + for subfig in subfigs: + print '%d ' % count, + count += 1 + print ", %s_$(n)%s)" % (root, ext) + print "FILES_TO_DISTCLEAN += $(%s)" % varname + print "FIGS2CREATE_LIST += $(%s)" % varname + print "$(TEMPORAIRE): $(%s)" % varname + print "$(TEMPORAIRE): $(%s)" % varname + +if __name__ == "__main__": + main() diff --git a/Master/texmf-dist/scripts/latex-make/latexfilter.py b/Master/texmf-dist/scripts/latex-make/latexfilter.py new file mode 100755 index 00000000000..1e94870125d --- /dev/null +++ b/Master/texmf-dist/scripts/latex-make/latexfilter.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +#coding=utf8 + +""" + +stdin : the original xfig file +stdout : the output xfig file +args : all depths we want to keep + +""" + +from __future__ import print_function +import optparse +import os.path +import re +import sys + +def main(): + parser = optparse.OptionParser() + (options, args) = parser.parse_args() + + display = 0 + in_display = 0 + start_line = '' + warnerror_re = re.compile(r"^(LaTeX|Package|Class)( (.*))? (Warning:|Error:)") + fullbox_re = re.compile(r"^(Underfull|Overfull) \\[hv]box") + accu = '' + for line in sys.stdin: + if display > 0: + display -= 1 + if line[0:4].lower() in ('info', 'warn') or line[0:5].lower() == 'error': + display = 0 + line_groups = warnerror_re.match(line) + if line_groups: + start_line = line_groups.group(3) + if not start_line: + start_line = '' + if line_groups.group(2): + start_line = "(" + start_line + ")" + display = 1 + in_display = 1 + elif (start_line != '') and (line[0:len(start_line)] == start_line): + display = 1 + elif line == "\n": + in_display = 0 + elif line[0:4] == 'Chap': + display = 1 + elif fullbox_re.match(line): + display = 2 + if display: + print(accu, end="") + accu = line + elif in_display: + print(accu[0:-1], end="") + accu = line + +if __name__ == "__main__": + main() + diff --git a/Master/texmf-dist/scripts/latex-make/svg2dev.py b/Master/texmf-dist/scripts/latex-make/svg2dev.py new file mode 100755 index 00000000000..1b968edfc49 --- /dev/null +++ b/Master/texmf-dist/scripts/latex-make/svg2dev.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +#coding=utf8 + +from optparse import OptionParser +import shutil +import subprocess + +svg2eps = 'inkscape %s -z -C --export-eps=%s --export-latex' +svg2pdf = 'inkscape %s -z -C --export-pdf=%s --export-latex' + +def create_image(input_filename, output_filename, mode): + subprocess.Popen(mode % (input_filename, output_filename), + stdout=subprocess.PIPE, shell=True).communicate()[0] + n1 = output_filename + '_tex' + n2 = output_filename + '_t' + shutil.move(n1, n2) + +def main(): + parser = OptionParser() + parser.add_option("-L", "--format", dest="outputFormat", + metavar="FORMAT", help="output format", default="spstex") + parser.add_option("-p", "--portrait", dest="portrait", help="dummy arg") + (options, args) = parser.parse_args() + if len(args) != 2: return + (input_filename, output_filename) = args + fmt = options.outputFormat + portrait = options.portrait + + if fmt == 'eps': + create_image(input_filename, output_filename, svg2eps) + elif fmt == 'spstex' or fmt == 'pstex': + create_image(input_filename, output_filename, svg2eps) + elif fmt == 'spstex_t' or fmt == 'pstex_t': + pass + elif fmt == 'spdftex' or fmt == 'pdftex': + create_image(input_filename, output_filename, svg2pdf) + elif fmt == 'spdftex_t' or fmt == 'pdftex_t': + pass + +if __name__ == "__main__": + main() + diff --git a/Master/texmf-dist/scripts/latex-make/svgdepth.py b/Master/texmf-dist/scripts/latex-make/svgdepth.py new file mode 100755 index 00000000000..6f146647b15 --- /dev/null +++ b/Master/texmf-dist/scripts/latex-make/svgdepth.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +#coding=utf8 + +import sys +import xml.parsers.expat + +layers = [] +for arg in sys.argv: + layers.append(arg) + +parser = xml.parsers.expat.ParserCreate() +class XmlParser(object): + def __init__(self, layers): + self.state_stack = [True] + self.last_state = True + self.layers = layers + def XmlDeclHandler(self, version, encoding, standalone): + sys.stdout.write("<?xml version='%s' encoding='%s'?>\n" % (version, encoding)) + def StartDoctypeDeclHandler(self, doctypeName, systemId, publicId, has_internal_subset): + if publicId != None: sys.stdout.write("<!DOCTYPE %s PUBLIC \"%s\" \"%s\">\n" %\ + (doctypeName, publicId, systemId)) + else: sys.stdout.write("<!DOCTYPE %s \"%s\">\n" % (doctypeName, systemId)) + def StartElementHandler(self, name, attributes): + if name.lower() == 'g': + r = self.last_state and ('id' not in attributes or \ + attributes['id'] in self.layers) + self.last_state = r + self.state_stack.append(r) + if not self.last_state: return + s = "" + for k, v in attributes.items(): s += ' %s="%s"' % (k, v) + sys.stdout.write("<%s%s>" % (name, s)) + def EndElementHandler(self, name): + r = self.last_state + if name.lower() == 'g': + self.state_stack = self.state_stack[0:-1] + self.last_state = self.state_stack[-1] + if not r: return + sys.stdout.write("</%s>" % (name)) + def CharacterDataHandler(self, data): + if not self.last_state: return + sys.stdout.write(data) + +my_parser = XmlParser(layers) + +parser.XmlDeclHandler = my_parser.XmlDeclHandler +parser.StartDoctypeDeclHandler = my_parser.StartDoctypeDeclHandler +parser.StartElementHandler = my_parser.StartElementHandler +parser.EndElementHandler = my_parser.EndElementHandler +parser.CharacterDataHandler = my_parser.CharacterDataHandler + +for line in sys.stdin: + parser.Parse(line, False) +parser.Parse('', True) + |