当前位置: 首页>>代码示例>>Python>>正文


Python TeX.TeX类代码示例

本文整理汇总了Python中plasTeX.TeX.TeX的典型用法代码示例。如果您正苦于以下问题:Python TeX类的具体用法?Python TeX怎么用?Python TeX使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TeX类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testStringCommand

 def testStringCommand(self):
     class figurename(Command): unicode = 'Figure'
     s = TeX()
     s.input(r'\figurename')
     s.ownerDocument.context['figurename'] = figurename
     output = [x for x in s]
     assert output[0].unicode == 'Figure', output
开发者ID:AllenDowney,项目名称:plastex-oreilly,代码行数:7,代码来源:NewCommands.py

示例2: testNewcommand

 def testNewcommand(self):
     s = TeX()
     s.input(r'\newcommand\mycommand[2][optional]{\itshape{#1:#2}}\newcommand{ \foo }{{this is foo}}\mycommand[hi]{{\foo}!!!}')
     res = [x for x in s]
     text = [x for x in res if x.nodeType == Node.TEXT_NODE]
     expected = list('hi:this is foo!!!')
     assert text == expected, '%s != %s' % (text, expected)
开发者ID:AllenDowney,项目名称:plastex-oreilly,代码行数:7,代码来源:NewCommands.py

示例3: testMath

 def testMath(self):
     tex_input = r'a $ x^{y_3} $ b'
     s = TeX()
     s.input(tex_input)
     output = s.parse()
     source = normalize(output.source)
     assert_that( source, is_(tex_input))
开发者ID:NextThought,项目名称:nti.plasTeX,代码行数:7,代码来源:test_Source.py

示例4: testTokenArgument

 def testTokenArgument(self):
     s = TeX()
     s.input(r'\foo a ')
     arg = s.readArgument(type='Tok')
     assert arg == 'foo'
     arg = s.readArgument(type='Tok')
     assert arg == 'a'
开发者ID:NextThought,项目名称:nti.plasTeX,代码行数:7,代码来源:test_ArgumentParsing.py

示例5: testLocalCatCodes

    def testLocalCatCodes(self):
        """ Make sure that category codes are local """
        class code(Macro):
            args = 'self:nox'
            def parse(self, tex):
                self.ownerDocument.context.catcode('#',11)
                self.ownerDocument.context.catcode('&',11)
                self.ownerDocument.context.catcode('^',11)
                self.ownerDocument.context.catcode('_',11)
                self.ownerDocument.context.catcode('$',11)
                return Macro.parse(self, tex)
        s = TeX()
        s.input('\code{this # is $ some & nasty _ text}&_2')
        s.ownerDocument.context['code'] = code
        tokens = [x for x in s]

        tok = type(tokens[0])
        cs = type(s.ownerDocument.createElement('code'))
        assert tok is cs, '"%s" != "%s"' % (tok, cs)

        assert not [x.catcode for x in tokens[0].attributes['self'] if x.catcode not in [10,11]], \
               'All codes should be 10 or 11: %s' % [x.code for x in tokens[0]]

        tok = type(tokens[-3])
        cs = type(s.ownerDocument.createElement('active::&'))
        assert tok is cs, '"%s" != "%s"' % (tok, cs)
开发者ID:AllenDowney,项目名称:plastex-oreilly,代码行数:26,代码来源:CategoriesAndChars.py

示例6: WordPressLatexPost

class WordPressLatexPost(WordPressPost):
    """Encapsulate a LaTeX Post to Wordpress
    """
    
    def __init__(self, latex):
        """
        
        Arguments:
        - `latex`:
        """
        WordPressPost.__init__(self)

        self._tex = TeX()
        self._renderer = WPRenderer()

        self._tex.input(latex)
        self._document = self._tex.parse()

        # Before rendering, let's pass through and extract the images
        self.images = findImageNodes(self._document)
        
    def render(self):
        """Render this post
        """
        # Have to encode the unicode string to print it correctly.
        self.description = self._renderer.render(self._document).encode('utf-8')
        self.title = self._document.userdata['title'].textContent.encode('utf-8')
        self.tags = self._document.userdata['tags'].textContent.encode('utf-8')
开发者ID:ericfinster,项目名称:wplatex,代码行数:28,代码来源:wp.py

示例7: testMath

 def testMath(self):
     input = r'a $ x^{y_3} $ b'
     s = TeX()
     s.input(input)
     output = s.parse()
     source = normalize(output.source)
     assert input == source, '"%s" != "%s"' % (input, source)
开发者ID:AllenDowney,项目名称:plastex-oreilly,代码行数:7,代码来源:Source.py

示例8: testTabular

 def testTabular(self):
     input = r'\begin{tabular}{lll} \hline a & b & c \\[0.4in] 1 & 2 & 3 \end{tabular}'
     s = TeX()
     s.input(input)
     output = s.parse()
     source = normalize(output.source)
     assert input == source, '"%s" != "%s"' % (input, source)
开发者ID:AllenDowney,项目名称:plastex-oreilly,代码行数:7,代码来源:Source.py

示例9: testParentage

    def testParentage(self):
        class myenv(Environment):
            pass
        class foo(Command):
            args = 'self'
        s = TeX()
        s.ownerDocument.context.importMacros(locals())
        s.input(r'\begin{myenv}\foo{TEST}\end{myenv}')
        output = s.parse()

        myenv = output[0]
        assert myenv.nodeName == 'myenv', myenv.nodeName

        foo = output[0][0]
        assert foo.nodeName == 'foo', foo.nodeName

        children = output[0][0].childNodes
        fooself = output[0][0].attributes['self']
        assert children is fooself

        # Check parents
        assert fooself[0].parentNode is fooself, fooself[0].parentNode
        assert foo.parentNode is myenv, foo.parentNode
        assert myenv.parentNode is output, myenv.parentNode
        assert output.parentNode is None, output.parentNode

        # Check owner document
        assert fooself[0].ownerDocument is output
        assert foo.ownerDocument is output
        assert myenv.ownerDocument is output
        assert output.ownerDocument is output
开发者ID:AllenDowney,项目名称:plastex-oreilly,代码行数:31,代码来源:Document.py

示例10: testTabular

 def testTabular(self):
     tex_input = r'\begin{tabular}{lll} \hline a & b & c \\[0.4in] 1 & 2 & 3 \end{tabular}'
     s = TeX()
     s.input(tex_input)
     output = s.parse()
     source = normalize(output.source)
     assert_that( source, is_(tex_input))
开发者ID:NextThought,项目名称:nti.plasTeX,代码行数:7,代码来源:test_Source.py

示例11: testSimpleNewEnvironment

 def testSimpleNewEnvironment(self):
     s = TeX()
     s.input(r"\newenvironment{myenv}{\it}{}\begin{myenv}hi\end{myenv}")
     for key, value in list(self.macros.items()):
         s.ownerDocument.context[key] = value
     output = [x for x in s]
     assert type(output[2]) == s.ownerDocument.context["it"]
     assert output[-3:-1] == ["h", "i"]
开发者ID:NextThought,项目名称:nti.plasTeX,代码行数:8,代码来源:test_NewCommands.py

示例12: testSimpleNewEnvironment

 def testSimpleNewEnvironment(self):
     s = TeX()
     s.input(r'\newenvironment{myenv}{\it}{}\begin{myenv}hi\end{myenv}')
     for key, value in self.macros.items():
         s.ownerDocument.context[key] = value
     output = [x for x in s]
     assert type(output[2]) == s.ownerDocument.context['it']
     assert output[-3:-1] == ['h','i']
开发者ID:AllenDowney,项目名称:plastex-oreilly,代码行数:8,代码来源:NewCommands.py

示例13: testLabelStar

 def testLabelStar(self):
     s = TeX()
     s.input(r'\section{hi} text \section*{bye\label{two}}')
     output = s.parse()
     one = output[0]
     two = output[-1]
     assert one.id == 'two', one.id
     assert two.id != 'two', two.id
开发者ID:AllenDowney,项目名称:plastex-oreilly,代码行数:8,代码来源:Crossref.py

示例14: test_numberwithin

def test_numberwithin():
    s = TeX()
    s.input(DOC)
    output = s.parse()
    equations =output.getElementsByTagName('equation')
    assert equations[0].ref.textContent == '1.1'
    assert equations[1].ref.textContent == '2.1'
    assert equations[2].ref.textContent == '2.2'
开发者ID:tiarno,项目名称:plastex,代码行数:8,代码来源:Amsmath.py

示例15: testEquation

    def testEquation(self):
        tex_input = r'\sqrt{\pi ^{3}}'
        s = TeX()
        s.input(tex_input)

        output = s.parse()
        source = normalize(output.source)
        assert_that( source, is_(tex_input))
开发者ID:NextThought,项目名称:nti.plasTeX,代码行数:8,代码来源:test_Source.py


注:本文中的plasTeX.TeX.TeX类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。