本文整理汇总了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
示例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)
示例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))
示例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'
示例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)
示例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')
示例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)
示例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)
示例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
示例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))
示例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"]
示例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']
示例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
示例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'
示例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))