예제 #1
0
 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('???')]
예제 #2
0
 def testParagraph(self):
     tokens = [x for x in TeX().input('1\n   2\n   \n   3\n').itertokens()]
     expected = [
         Other('1'),
         Space(' '),
         Other('2'),
         Space(' '),
         EscapeSequence('par'),
         Other('3'),
         Space(' ')
     ]
     self.assertEqual(tokens, expected)
예제 #3
0
 def testTokens(self):
     tokens = [x for x in TeX().input(r'{\hskip 36 pt}').itertokens()]
     expected = [
         BeginGroup('{'),
         EscapeSequence('hskip'),
         Other('3'),
         Other('6'),
         Space(' '),
         Letter('p'),
         Letter('t'),
         EndGroup('}')
     ]
     self.assertEqual(tokens, expected)
예제 #4
0
 def invoke(self, tex):
     # Push the active character back to the input stream as
     # an Other token
     tex.pushToken(Other(self.nodeName.split('::')[-1]))
     # Instantiate a `verb` macro and let it take over the parsing
     # from here.  Also, return its return value.
     return self.ownerDocument.createElement('verb').invoke(tex)
예제 #5
0
    def testExercises(self):
        """ Exercises in the TeX book """
        # 8.4
        tokens = [x for x in TeX().input(r' $x^2$~  \TeX  ^^C').itertokens()]
        expected = [
            MathShift('$'),
            Letter('x'),
            Superscript('^'),
            Other('2'),
            MathShift('$'),
            EscapeSequence('active::~'),
            Space(' '),
            EscapeSequence('TeX'),
            Other('\x03')
        ]
        self.assertEqual(tokens, expected)

        # 8.5
        tokens = [x for x in TeX().input('Hi!\n\n\n').itertokens()]
        expected = [
            Letter('H'),
            Letter('i'),
            Other('!'),
            Space(' '),
            EscapeSequence('par')
        ]
        self.assertEqual(tokens, expected)

        # 8.6
        tokens = [
            x for x in TeX().input(r'^^B^^BM^^A^^B^^C^^M^^@\M ').itertokens()
        ]
        expected = [
            Other('\x02'),
            Other('\x02'),
            Letter('M'),
            Other('\x01'),
            Other('\x02'),
            Other('\x03'),
            Space(' '),
            EscapeSequence('M')
        ]
        self.assertEqual(tokens, expected)
예제 #6
0
 def invoke(self, tex):
     """ Parse for matching delimiters """
     self.ownerDocument.context.push(self)
     self.parse(tex)
     self.ownerDocument.context.setVerbatimCatcodes()
     # See what the delimiter is
     for endpattern in tex:
         self.delimiter = endpattern
         if isinstance(endpattern, bgroup):
             self.delimiter = endpattern = Other('}')
         break
     tokens = [self, endpattern]
     # Parse until this delimiter is seen again
     for tok in tex:
         tokens.append(tok)
         if tok == endpattern:
             break
     self.ownerDocument.context.pop(self)
     return tokens
예제 #7
0
 def testDoubleSuper(self):
     tokens = [x for x in TeX().input('^^I ^^A ^^@ ^^M').itertokens()]
     expected = [Other('\x01'), Space(' ')]
     self.assertEqual(tokens, expected)