def invoke(self, tex): Command.invoke(self, tex) value = self.attributes["info"].firstChild doc = self.ownerDocument bibcites = doc.userdata.getPath("bibliography/bibcites", {}) bibcites[self.attributes["key"]] = value doc.userdata.setPath("bibliography/bibcites", bibcites)
def invoke(self, tex): if isinstance(self, Environment): Environment.invoke(self, tex) else: Command.invoke(self, tex) self.attributes['title'] = self.ownerDocument.createElement( 'indexname').expand(tex)
def invoke(self, tex): Command.invoke(self, tex) value = self.attributes['info'].firstChild doc = self.ownerDocument bibcites = doc.userdata.getPath('bibliography/bibcites', {}) bibcites[self.attributes['key']] = value doc.userdata.setPath('bibliography/bibcites', bibcites)
def invoke(self,tex): Command.invoke(self,tex) if self.attributes['var']: self.ownerDocument.userdata['modulecodes'][self.attributes['var']] = self.attributes['code'] else: self.ownerDocument.userdata['modulecodes'][1] = self.attributes['code']
def invoke(self, tex): Command.invoke(self, tex) self.attributes['filename'] = tex.filename self.attributes['linenum'] = tex.lineNumber self.attributes['url'] = '%s/%s#L%s' % (self.attributes['url_root'].source, tex.filename, tex.lineNumber) # print "root=%s, name=%s" % (self.attributes['url_root'].source, self.attributes['name'].source) print " --> edXgitlink: file=%s, line=%s, url=%s" % (tex.filename, tex.lineNumber, self.attributes['url'])
def invoke(self, tex): Command.invoke(self, tex) self.ownerDocument.userdata[ 'sectlet'] = self.attributes['sectlet'] or '' self.ownerDocument.userdata['sectsep'] = self.attributes['sep'] or '' self.section = self.ownerDocument.userdata[ 'sectlet'] + self.ownerDocument.userdata['sectsep'] self.ownerDocument.context.newcommand('thesect', 0, self.section)
def invoke(self,tex): Command.invoke(self,tex) if self.attributes['semestertext'] == '1': self.ownerDocument.userdata['semestertext'] = "Semester 1" elif self.attributes['semestertext'] == '2': self.ownerDocument.userdata['semestertext'] = "Semester 2" else: self.ownerDocument.userdata['semestertext'] = self.attributes['semestertext']
def invoke(self, tex): Command.invoke(self, tex) try: print " --> marginote in %s: note=%s, linenum=%s" % ( tex.filename, self.attributes['note'].source, tex.lineNumber) except Exception as err: print(" --> marginnote in %s: note=<unicode error>, linenum=%s" % (tex.filename, tex.lineNumber)) print(err)
def invoke(self, tex): Command.invoke(self, tex) self.attributes['filename'] = tex.filename self.attributes['linenum'] = tex.lineNumber self.attributes['url'] = '%s/%s#L%s' % ( self.attributes['url_root'].source, tex.filename, tex.lineNumber) # print "root=%s, name=%s" % (self.attributes['url_root'].source, self.attributes['name'].source) print " --> edXgitlink: file=%s, line=%s, url=%s" % ( tex.filename, tex.lineNumber, self.attributes['url'])
def invoke(self,tex): Command.invoke(self,tex) var = self.ownerDocument.userdata['variant'] self.variantMarkString = 'num_v%d' % var while not self.attributes[self.variantMarkString]: var = var - 1 self.variantMarkString = 'num_v%d' % var try: self.mark = int(self.attributes[self.variantMarkString]) self.markText = "%d mark" % self.mark if self.mark != 1: self.markText += "s" except: pass
def invoke(self, tex): Command.invoke(self, tex) c = self.ownerDocument.context name = str(self.attributes['name']) options = self.attributes['options'] or {} # Create new subfloat class newclass = type(name, (subfloat,), {'options':options,'counter':name}) c.addGlobal(name, newclass) # Create new counter c.newcounter(name, resetby='figure', format='${%s.alph}' % name) # Create the float name macro c.newcommand(name+'name', 0, name)
def invoke(self, tex): res = Command.invoke(self, tex) output = [x.textContent.strip() for x in self.attributes['paths']] output = [x for x in output if x] self.ownerDocument.userdata.setPath( 'packages/%s/paths' % self.packageName, output) return res
def invoke(self, tex): res = Command.invoke(self, tex) f = self.attributes['file'] ext = self.ownerDocument.userdata.getPath( 'packages/%s/extensions' % self.packageName, ['.png','.jpg','.jpeg','.gif','.pdf','.ps','.eps']) paths = self.ownerDocument.userdata.getPath( 'packages/%s/paths' % self.packageName, ['.']) img = None # Check for file using graphicspath for p in paths: for e in ['']+ext: fname = os.path.join(p,f+e) if os.path.isfile(fname): img = os.path.abspath(fname) break if img is not None: break # Check for file using kpsewhich if img is None: for e in ['']+ext: try: img = os.path.abspath(tex.kpsewhich(f+e)) break except (OSError, IOError): pass self.imageoverride = img return res
def invoke(self, tex): res = Command.invoke(self, tex) self.ownerDocument.context.loadLanguage( # pylint: disable=no-member self.attributes['lang'], self.ownerDocument ) return res
def invoke(self, tex): if self.disableMath: return Command.invoke(self,tex) o = self.ownerDocument.createElement('math') o.macroMode = Command.MODE_END self.ownerDocument.context.pop(o) return [o]
def invoke(self, tex): res = Command.invoke(self, tex) f = self.attributes['file'] ext = self.ownerDocument.userdata.getPath( 'packages/%s/extensions' % self.packageName, ['.png', '.jpg', '.jpeg', '.gif', '.pdf', '.ps', '.eps']) paths = self.ownerDocument.userdata.getPath( 'packages/%s/paths' % self.packageName, ['.']) img = None # Check for file using graphicspath for p in paths: for e in [''] + ext: fname = os.path.join(p, f + e) if os.path.isfile(fname): img = os.path.abspath(fname) break if img is not None: break # Check for file using kpsewhich if img is None: for e in [''] + ext: try: img = os.path.abspath(tex.kpsewhich(f + e)) break except (OSError, IOError): pass self.imageoverride = img return res
def invoke(self, tex): """ Set up counter for this list depth """ try: self.counter = List.counters[List.depth-1] self.position = self.ownerDocument.context.counters[self.counter].value + 1 except (KeyError, IndexError): pass return Command.invoke(self, tex)
def invoke(self, tex): # Add the footnotemarks to the document output = Command.invoke(self, tex) userdata = self.ownerDocument.userdata if "footnotemarks" not in userdata: userdata["footnotemarks"] = [] userdata["footnotemarks"].append(self) self.mark = self return output
def invoke(self, tex): res = Command.invoke(self, tex) data = self.ownerDocument.userdata if "packages" not in data: data["packages"] = {} if "hyperref" not in data["packages"]: data["packages"]["hyperref"] = {} self.ownerDocument.userdata["packages"]["hyperref"]["baseurl"] = self.attributes["base"] return res
def invoke(self, tex): res = Command.invoke(self, tex) data = self.ownerDocument.userdata if 'packages' not in data: data['packages'] = {} if 'hyperref' not in data['packages']: data['packages']['hyperref'] = {} self.ownerDocument.userdata['packages']['hyperref']['baseurl'] = self.attributes['base'] return res
def invoke(self, tex): Command.invoke(self, tex) name = str(self.attributes['name']) # Create the float class and the caption class floatcls = type(name, (Float,), {}) captioncls = type('caption', (Caption,), {'macroName':'caption', 'counter':name}) floatcls.caption = captioncls c = self.ownerDocument.context c.addGlobal(name, floatcls) # Create a counter resetby = self.attributes['reset'] or 'chapter' c.newcounter(name, resetby, 0, format='${the%s}.${%s}' % (resetby,name)) # Create the float name macro c.newcommand(name+'name', 0, name)
def invoke(self, tex): res = Command.invoke(self, tex) data = self.ownerDocument.userdata if 'packages' not in list(data.keys()): data['packages'] = {} if 'hyperref' not in list(data['packages'].keys()): data['packages']['hyperref'] = {} self.ownerDocument.userdata['packages']['hyperref']['baseurl'] = self.attributes['base'] return res
def invoke(self, tex): # Add the footnotemarks to the document output = Command.invoke(self, tex) userdata = self.ownerDocument.userdata if 'footnotemarks' not in userdata: userdata['footnotemarks'] = [] userdata['footnotemarks'].append(self) self.mark = self return output
def invoke(self, tex): res = Command.invoke(self, tex) f = self.attributes['file'] img = _locate_image_file( self, tex, f, self.packageName, self.default_extensions ) options = self.attributes['options'] if options is not None: scale = options.get('scale') if scale is not None: scale = float(scale) from PIL import Image w, h = Image.open(img).size self.style['width'] = '%spx' % (w * scale) self.style['height'] = '%spx' % (h * scale) height = options.get('height') if height is not None: self.style['height'] = height width = options.get('width') if width is not None: self.style['width'] = width def getdimension(s): m = re.match(r'^([\d\.]+)\s*([a-z]*)$', s) if m and '.' in m.group(1): return float(m.group(1)), m.group(2) elif m: return int(m.group(1)), m.group(2) keepaspectratio = options.get('keepaspectratio') if img is not None and keepaspectratio == 'true' and \ height is not None and width is not None: from PIL import Image w, h = Image.open(img).size height, hunit = getdimension(height) width, wunit = getdimension(width) scalex = float(width) / w scaley = float(height) / h if scaley > scalex: height = h * scalex else: width = w * scaley self.style['width'] = '%s%s' % (width, wunit) self.style['height'] = '%s%s' % (height, hunit) self.imageoverride = img return res
def invoke(self, tex): result = Command.invoke(self, tex) name = self.attributes['arg'] if name == 'year': return [Other(datetime.datetime.now().strftime('%Y'))] elif name == 'month': return [Other(datetime.datetime.now().strftime('%-m'))] elif name == 'day': return [Other(datetime.datetime.now().strftime('%-d'))] return [Other('???')]
def invoke(self, tex): result = Command.invoke(self, tex) name = self.attributes['arg'] if name == 'year': return [Other(datetime.now().strftime('%Y'))] elif name == 'month': return [Other(datetime.now().strftime('%-m'))] elif name == 'day': return [Other(datetime.now().strftime('%-d'))] return [Other('???')]
def invoke(self, tex): output = Command.invoke(self, tex) userdata = self.ownerDocument.userdata if 'collaborations' not in userdata: userdata['collaborations'] = [] if 'author' in userdata: self.author = userdata['author'][-1] userdata['collaborations'].append(self) return output
def invoke(self, tex): output = Command.invoke(self, tex) userdata = self.ownerDocument.userdata if 'affiliations' not in userdata: userdata['affiliations'] = [] if 'author' in userdata: known = [author for a in userdata['affiliations'] for author in a.authors] self.authors = [author for author in userdata['author'] if author not in known] userdata['affiliations'].append(self) return output
def invoke(self, tex): res = Command.invoke(self, tex) if 'alttext' not in self.attributes: self.attributes['alttext'] = '' f = self.attributes['file'] img = _locate_image_file( self, tex, f, self.packageName, self.default_extensions ) self.imageoverride = img return res
def invoke(self, tex): # Parse arguments res = Command.invoke(self, tex) # Get the specified character from the command sequence in # the `char` attribute char = str(self.attributes['char'].macroName) # Set the specified character as active self.ownerDocument.context.catcode(char, Token.CC_ACTIVE) # Create a new macro for the active character that calls _ShortVerb newclass = new.classobj('active::%s' % char, (_ShortVerb,),{}) # Add the new macro to the global namespace self.ownerDocument.context['active::%s' % char] = newclass return res
def invoke(self, tex): Command.invoke(self, tex) entry = self.attributes['argument'] if entry.find('!') != -1: primary, secondary = entry.split('!') primary, prisort, see, seealso= parse_indexentry(primary) if see or seealso: secondary, secsort, _, _ = parse_indexentry(secondary) else: secondary, secsort, see, seealso = parse_indexentry(secondary) else: primary, prisort, see, seealso = parse_indexentry(entry) self.data = { 'primary': primary, 'secondary':secondary, 'prisort': prisort, 'secsort': secsort, 'see': see, 'seealso': seealso, }
def invoke(self, tex): # This macro can be an environment or a command each # with different arguments. if self.macroMode == Command.MODE_BEGIN or \ self.macroMode == Command.MODE_END: f = self.ownerDocument.createElement('columnenv') f.parentNode = self.parentNode f.macroMode = self.macroMode res = f.invoke(tex) if res is None: res = [f] return res return Command.invoke(self, tex)
def invoke(self, tex): res = Command.invoke(self, tex) if 'alttext' not in self.attributes: self.attributes['alttext'] = '' f = self.attributes['file'] img = _locate_image_file(self, tex, f, self.packageName, self.default_extensions) self.imageoverride = img return res
def invoke(self, tex): # This macro can be an environment or a command each # with different arguments. if self.macroMode == Command.MODE_BEGIN or \ self.macroMode == Command.MODE_END: f = self.ownerDocument.createElement('frameenv') f.parentNode = self.parentNode f.macroMode = self.macroMode f.invoke(tex) # Add to frames collection if self.macroMode == Command.MODE_BEGIN: f.addToFrames() return [f] # Add to frames collection self.addToFrames() return Command.invoke(self, tex)
def not_invoke(self, tex): a = Command.invoke(self, tex) print 'MathSymbol.invoke' print self, self.tagName, type(self) if self.unicode is None: return a if self.unicode == -1: code = self.tagName else: code = self.unicode o = self.ownerDocument.createElement('mathsymbol') child = self.ownerDocument.createTextNode(code) o.append(child) self.ownerDocument.context.push(o) return [o]
def invoke(self, tex): output = Command.invoke(self, tex) userdata = self.ownerDocument.userdata if self.attributes['prefix'] is not None: self.attributes['self'] = self.attributes['prefix'] + self.attributes['self'] if 'footnotes' not in userdata: userdata['footnotes'] = [] if 'altaffiliations' not in userdata: userdata['altaffiliations'] = [] if 'author' in userdata: self.author = userdata['author'][-1] userdata['altaffiliations'].append(self) userdata['footnotes'].append(self) self.mark = self return output
def invoke(self, tex): res = Command.invoke(self, tex) f = self.attributes["file"] ext = self.ownerDocument.userdata.getPath( "packages/%s/extensions" % self.packageName, [".png", ".jpg", ".jpeg", ".gif", ".pdf", ".ps", ".eps"] ) paths = self.ownerDocument.userdata.getPath("packages/%s/paths" % self.packageName, ["."]) img = None # Check for file using graphicspath for p in paths: for e in [""] + ext: fname = os.path.join(p, f + e) if os.path.isfile(fname): img = os.path.abspath(fname) break if img is not None: break # Check for file using kpsewhich if img is None: for e in [""] + ext: try: img = os.path.abspath(tex.kpsewhich(f + e)) break except (OSError, IOError): pass options = self.attributes["options"] if options is not None: height = options.get("height") if height is not None: self.style["height"] = height width = options.get("width") if width is not None: self.style["width"] = width self.imageoverride = img return res
def invoke(self, tex): Command.invoke(self, tex) self.ownerDocument.userdata['thanks'] = self
def invoke(self, tex): Command.invoke(self, tex) print " --> edXdndtex in %s: dndtex=%s, line=%s" % ( tex.filename, self.attributes['self'].source, tex.lineNumber)
def invoke(self, tex): Command.invoke(self, tex) self.attributes['filename'] = tex.filename self.attributes['linenum'] = tex.lineNumber
def invoke(self, tex): res = Command.invoke(self, tex) self.attributes['url'] = addBaseURL(self, 'url') return res
def invoke(self, tex): Command.invoke(self, tex) self.attributes['argument'] = self.attributes['argument'].upper()
def invoke(self, tex): Command.invoke(self, tex) self.title = self.ownerDocument.createElement(self.titleMacro).expand(tex)
def invoke(self, tex): Command.invoke(self, tex) print " --> edXdndtex in %s: dndtex=%s, line=%s" % (tex.filename, self.attributes['self'].source, tex.lineNumber)
def invoke(self, tex): res = Command.invoke(self, tex) self.title = self.captionName return res
def invoke(self, tex): Command.invoke(self, tex) self.ownerDocument.userdata['author'] = self
def invoke(self, tex): Command.invoke(self, tex) if not self.ownerDocument.userdata.has_key('title'): self.ownerDocument.userdata['title'] = self
def invoke(self, tex): result = Command.invoke(self, tex) sortkey, key, format = [], [], [] entry = iter(self.attributes['entry']) current = [] alphanumeric = [Token.CC_OTHER, Token.CC_LETTER, Token.CC_SPACE] # Parse the index tokens for tok in entry: if tok.catcode in alphanumeric: # Escape character if tok == '"': for tok in entry: current.append(tok) break # Entry separator elif tok == '!': key.append(current) if len(sortkey) < len(key): sortkey.append(current) current = [] # Sort key separator elif tok == '@': sortkey.append(current) current = [] # Format separator elif tok == '|': key.append(current) if len(sortkey) < len(key): sortkey.append(current) current = format else: current.append(tok) continue # Everything else current.append(tok) # Make sure to get the stuff at the end if not format: key.append(current) if len(sortkey) < len(key): sortkey.append(current) # Convert the sort keys to strings for i, item in enumerate(sortkey): sortkey[i] = tex.expandTokens(item).textContent # Expand the key tokens for i, item in enumerate(key): key[i] = tex.expandTokens(item) # Get the format element type = IndexEntry.TYPE_NORMAL if not format: format = None else: macro = [] while format and format[0].catcode == Token.CC_LETTER: macro.append(format.pop(0)) if macro: macro = ''.join(macro) format.insert(0, EscapeSequence(macro)) if macro == 'see': type = IndexEntry.TYPE_SEE elif macro == 'seealso': type = IndexEntry.TYPE_SEEALSO format.append(EscapeSequence('index-page-number')) format = tex.expandTokens(format) # Store the index information in the document userdata = self.ownerDocument.userdata if 'index' not in userdata: userdata['index'] = [] userdata['index'].append(IndexEntry(key, self, sortkey, format, type)) return result
def invoke(self, tex): Command.invoke(self, tex) self.ownerDocument.context.counters[self.counterName].addtocounter(1)