1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
"""
C.1.2 Environments (p167)
"""
from plasTeX import Command
from plasTeX.Logging import getLogger
envlog = getLogger('parse.environments')
class begin(Command):
""" Beginning of an environment """
args = 'name:str'
def invoke(self, tex):
""" Parse the \\begin{...} """
# name = self.parse(tex)['name']
name = tex.readArgument(type=str)
envlog.debug(name)
self.ownerDocument.context.currenvir = name
# Instantiate the correct macro and let it know
# that it came from a \begin{...} macro
obj = self.ownerDocument.createElement(name)
obj.macroMode = Command.MODE_BEGIN
obj.parentNode = self.parentNode
# Return the output of the instantiated macro in
# place of self
out = obj.invoke(tex)
if out is None:
return [obj]
return out
class end(Command):
""" End of an environment """
args = 'name:str'
def invoke(self, tex):
""" Parse the \\end{...} """
# name = self.parse(tex)['name']
name = tex.readArgument(type=str)
envlog.debug(name)
# Instantiate the correct macro and let it know
# that it came from a \end{...} macro
obj = self.ownerDocument.createElement(name)
obj.macroMode = Command.MODE_END
obj.parentNode = self.parentNode
# Return the output of the instantiated macro in
# place of self
out = obj.invoke(tex)
if out is None:
return [obj]
while self.ownerDocument.context.currenvir is not None and \
not self.ownerDocument.context.currenvir == name:
del self.ownerDocument.context.currenvir
return out
|