def hook_multiinclude(loc, options_a, options_b, file): options = parse_keyval(options_b) if options_b is not None else parse_keyval(options_a) fileformat = "." + options["format"] if options.has_key("format") else "" graphicoptions = options["graphics"] if options.has_key("graphics") else None start = int(options["start"]) if options.has_key("start") else 0 stop = int(options["end"]) if options.has_key("end") else 1000000 seperator = "." if fileformat == "" else "-" for i in range(start, stop): number = "%d" % i ok = hook_includegraphics(loc, graphicoptions, file+seperator+number+fileformat, False) if not ok: break
def __init__(self, document, context): self.doc = document document.hook_macro('includegraphics', '*oa', self.hook_includegraphics) document.hook_macro('graphicspath', 'a', self.hook_graphicspath) document.hook_macro('DeclareGraphicsExtensions', 'a', self.hook_declareExtensions) document.hook_macro('DeclareGraphicsRule', 'aaaa', self.hook_declareRule) self.prefixes = [os.path.join(x, '') for x in document.env.path] self.files = [] # I take dvips as the default, but it is not portable. if document.vars['engine'] == 'pdfTeX' and document.products[0][ -4:] == '.pdf': self.suffixes = drv_suffixes['pdftex'] elif document.vars['engine'] == 'VTeX': self.suffixes = drv_suffixes['vtex'] else: self.suffixes = drv_suffixes['dvips'] # If the package was loaded with an option that matches the name of a # driver, use that driver instead. opts = parse_keyval(context['opt']) for opt in opts.keys(): if drv_suffixes.has_key(opt): self.suffixes = drv_suffixes[opt] document.vars['graphics_suffixes'] = self.suffixes
def __init__(self, document, context): self.doc = document document.hook_macro("includegraphics", "*oa", self.hook_includegraphics) document.hook_macro("graphicspath", "a", self.hook_graphicspath) document.hook_macro("DeclareGraphicsExtensions", "a", self.hook_declareExtensions) document.hook_macro("DeclareGraphicsRule", "aaaa", self.hook_declareRule) self.prefixes = [os.path.join(x, "") for x in document.env.path] self.files = [] # Latex accepts upper and lowercase filename extensions # to keep the above lists clean we auto-generate the # uppercase versions of the extensions automatically for engine, suffixes in drv_suffixes.iteritems(): suffixes += [x.upper() for x in suffixes] # I take dvips as the default, but it is not portable. if document.vars["engine"] == "pdfTeX" and document.products[0][-4:] == ".pdf": self.suffixes = drv_suffixes["pdftex"] elif document.vars["engine"] == "VTeX": self.suffixes = drv_suffixes["vtex"] else: self.suffixes = drv_suffixes["dvips"] # If the package was loaded with an option that matches the name of a # driver, use that driver instead. opts = parse_keyval(context["opt"]) for opt in opts.keys(): if drv_suffixes.has_key(opt): self.suffixes = drv_suffixes[opt] document.vars["graphics_suffixes"] = self.suffixes
def hook_includegraphics(self, loc, starred, optional, name): # no suffixes are tried when the extension is explicit allowed_suffixes = self.suffixes options = parse_keyval(optional) if 'ext' in options: allowed_suffixes = [''] if options['ext']: name = name + options['ext'] for suffix in self.suffixes: if name[-len(suffix):] == suffix: allowed_suffixes = [''] break # If the file name looks like it contains a control sequence or a macro # argument, forget about this \includegraphics. if name.find('\\') >= 0 or name.find('#') >= 0: return # We only accept conversions from file types we don't know and cannot # produce. def check(vars): source = vars['source'] if os.path.exists( vars['target']) and self.doc.env.may_produce(source): return False if self.suffixes == ['']: return True for suffix in allowed_suffixes: if source[-len(suffix):] == suffix: return False return True node = self.doc.env.convert(name, suffixes=allowed_suffixes, prefixes=self.prefixes, check=check, context=self.doc.vars) if node: msg.log(_("graphics `%s' found") % name, pkg='graphics') for file in node.products: self.doc.add_source(file) self.files.append(node) else: msg.warn(_("graphics `%s' not found") % name, **dict(loc))
def hook_includegraphics(self, loc, starred, optional, name): # no suffixes are tried when the extension is explicit allowed_suffixes = self.suffixes options = parse_keyval(optional) if "ext" in options: allowed_suffixes = [""] if options["ext"]: name = name + options["ext"] for suffix in self.suffixes: if name[-len(suffix) :] == suffix: allowed_suffixes = [""] break # If the file name looks like it contains a control sequence or a macro # argument, forget about this \includegraphics. if name.find("\\") >= 0 or name.find("#") >= 0: return # We only accept conversions from file types we don't know and cannot # produce. def check(vars): source = vars["source"] if os.path.exists(vars["target"]) and self.doc.env.may_produce(source): return False if self.suffixes == [""]: return True for suffix in allowed_suffixes: if source[-len(suffix) :] == suffix: return False return True node = self.doc.env.convert( name, suffixes=allowed_suffixes, prefixes=self.prefixes, check=check, context=self.doc.vars ) if node: msg.log(_("graphics `%s' found") % name, pkg="graphics") for file in node.products: self.doc.add_source(file) self.files.append(node) else: msg.warn(_("graphics `%s' not found") % name, **dict(loc))
def __init__(self, document, context): self.doc = document document.hook_macro('includegraphics', '*oa', self.hook_includegraphics) document.hook_macro('graphicspath', 'a', self.hook_graphicspath) document.hook_macro('DeclareGraphicsExtensions', 'a', self.hook_declareExtensions) document.hook_macro('DeclareGraphicsRule', 'aaaa', self.hook_declareRule) self.prefixes = [os.path.join(x, '') for x in document.env.path] self.files = [] #Latex accepts upper and lowercase filename extensions # to keep the above lists clean we auto-generate the # uppercase versions of the extensions automatically for engine, suffixes in drv_suffixes.iteritems(): suffixes += [x.upper() for x in suffixes] # I take dvips as the default, but it is not portable. if document.vars['engine'] == 'pdfTeX' and document.products[0][ -4:] == '.pdf': self.suffixes = drv_suffixes['pdftex'] elif document.vars['engine'] == 'VTeX': self.suffixes = drv_suffixes['vtex'] else: self.suffixes = drv_suffixes['dvips'] # If the package was loaded with an option that matches the name of a # driver, use that driver instead. opts = parse_keyval(context['opt']) for opt in opts.keys(): if drv_suffixes.has_key(opt): self.suffixes = drv_suffixes[opt] document.vars['graphics_suffixes'] = self.suffixes
def hook_epsfig(self, loc, argument): # We just translate this into an equivalent call to \includegraphics. options = parse_keyval(argument) if 'file' not in options: return self.hook_includegraphics(loc, False, argument, options['file'])
def hook_epsfig (self, loc, argument): # We just translate this into an equivalent call to \includegraphics. options = parse_keyval(argument) if 'file' not in options: return self.hook_includegraphics(loc, False, argument, options['file'])
def hook_includegraphics(self, loc, starred, optional, name): # no suffixes are tried when the extension is explicit options = parse_keyval(optional) allowed_suffixes = self.suffixes # work out the file extension if given explicitly if 'ext' in options and options['ext']: # \includegraphics[ext=.png]{foo} and \includegraphics[ext=.png]{{{foo}}} allowed_suffixes = [''] if name.startswith('{{') and name.endswith('}}'): name = name[2:-2] name = name + options['ext'] elif name.startswith('{{') and name.endswith('}}'): # \includegraphics{{{foo}}} name = name[2:-2] else: for suffix in self.suffixes: # if extension is given, includegraphics will always search for that # and disable automatic discovery if suffix and name.endswith(suffix): allowed_suffixes = [''] # support special syntax \includegraphics{subdir/{foo.1}.png} # at least some of the time if name.endswith('}' + suffix): # try to emulate what the TeX parser does. name = re.sub('{([^{]*)}', '\\1', name) break # If the file name looks like it contains a control sequence or a macro # argument, forget about this \includegraphics. if name.find('\\') >= 0 or name.find('#') >= 0: return # We only accept conversions from file types we don't know and cannot # produce. def check(vars): source = vars['source'] if os.path.exists( vars['target']) and self.doc.env.may_produce(source): return False if self.suffixes == ['']: return True for suffix in allowed_suffixes: if source[-len(suffix):] == suffix: return False return True node = self.doc.env.convert(name, suffixes=allowed_suffixes, prefixes=self.prefixes, check=check, context=self.doc.vars) if isinstance(node, str): msg.debug(_("graphics %s found in %s"), name, node) self.doc.add_source(node) elif isinstance(node, rubber.depend.Node): msg.debug(_("graphics %s converted from %s"), name, node.primary_product()) self.doc.add_source(node.primary_product()) self.files.append(node) else: assert node is None msg.warning( rubber.util._format(loc, _("graphics `%s' not found") % name))