1#!/usr/bin/env python 2 3from plasTeX import Command 4from plasTeX.Tokenizer import Token, Other 5 6class MakeShortVerb(Command): 7 args = 'char:cs' 8 def invoke(self, tex): 9 # Parse arguments 10 res = Command.invoke(self, tex) 11 # Get the specified character from the command sequence in 12 # the `char` attribute 13 char = str(self.attributes['char'].macroName) 14 # Set the specified character as active 15 self.ownerDocument.context.catcode(char, Token.CC_ACTIVE) 16 # Create a new macro for the active character that calls _ShortVerb 17 newclass = type('active::%s' % char, (_ShortVerb,),{}) 18 # Add the new macro to the global namespace 19 self.ownerDocument.context['active::%s' % char] = newclass 20 return res 21 22class _ShortVerb(Command): 23 """ Command to handle short verbatims """ 24 def invoke(self, tex): 25 # Push the active character back to the input stream as 26 # an Other token 27 tex.pushToken(Other(self.nodeName.split('::')[-1])) 28 # Instantiate a `verb` macro and let it take over the parsing 29 # from here. Also, return its return value. 30 return self.ownerDocument.createElement('verb').invoke(tex) 31