def newcounter(self, name, resetby=None, initial=0, format=None): """ Create a new counter This method corresponds to LaTeX's \\newcounter command Required Arguments: name -- name of the counter. The generate counter class will use this name. Also, a new macro called 'the<name>' will also be generated for the counter format. Keyword Arguments: resetby -- the name of the counter that this counter is reset by initial -- initial value for the counter """ # Counter already exists if name in list(self.counters.keys()): macrolog.debug('counter %s already defined', name) return self.counters[name] = plasTeX.Counter(self, name, resetby, initial) if format is None: format = '${%s}' % name newclass = type('the' + name, (plasTeX.TheCounter,), {'format': format}) self.addGlobal('the' + name, newclass)
def __getitem__(self, name): try: c = dict.__getitem__(self, name) except KeyError: # log.warning('No counter "%s" exists. Creating one.' % name) c = self[name] = plasTeX.Counter(self.context, name) return c