예제 #1
0
class TeXCollection(TeXObject):
    """
    A collection of one ore more TeXObjects. When compiled, may be
    enclosed in some starting and ending strings and may have some
    separator.
    """
    start = TeXObject("")
    end = TeXObject("")
    sep = TeXObject(" ")
    def __init__(self, objs=None, start=None, end=None, sep=None):
        if objs is None:
            objs = []
        elif type(objs) is not list:
            objs = [objs]
        for obj in objs:
            obj = TeXObject(obj)
            obj.parent = self
        self.objs = objs
        if start is not None:
            self.start = TeXObject(start)
        if end is not None:
            self.end = TeXObject(end)
        if sep is not None:
            self.sep = TeXObject(sep)
    def addObj(self, obj):
        obj.parent = self
        self.objs.append(obj)
    def compile(self):
        start = self.start.compile()
        sep = self.sep.compile()
        objs = map(lambda o: TeXObject(o).compile(), self.objs)
        end = self.end.compile()
        return "".join([start, sep.join(objs), end])
예제 #2
0
class TeXGroup(TeXCollection):
    """
    A semantically grouped collection. Often used for scope
    (e.g. "{\bf foo bar baz} quux" will limit the effect of
    the "\bf" to "foo bar baz".
    """
    start = TeXObject("{", raw=True)
    end = TeXObject("}", raw=True)
예제 #3
0
class TeXRow(TeXCollection):
    """
    A "row" that requires any sort of alignment or newline markers
    """
    end = TeXObject("\\\\", raw=True)
    sep = TeXObject(" & ", raw=True)

    def compile(self):
        if self.parent and self.parent.objs[-1] is self:
            self.end = TeXObject()
        return TeXCollection.compile(self)
예제 #4
0
 def __init__(self, objs=None, start=None, end=None, sep=None):
     if objs is None:
         objs = []
     elif type(objs) is not list:
         objs = [objs]
     for obj in objs:
         obj = TeXObject(obj)
         obj.parent = self
     self.objs = objs
     if start is not None:
         self.start = TeXObject(start)
     if end is not None:
         self.end = TeXObject(end)
     if sep is not None:
         self.sep = TeXObject(sep)
예제 #5
0
 def __init__(self, objs=None, start=None, end=None, sep=None):
     if objs is None:
         objs = []
     elif type(objs) is not list:
         objs = [objs]
     for obj in objs:
         obj = TeXObject(obj)
         obj.parent = self
     self.objs = objs
     if start is not None:
         self.start = TeXObject(start)
     if end is not None:
         self.end = TeXObject(end)
     if sep is not None:
         self.sep = TeXObject(sep)
예제 #6
0
class TeXCollection(TeXObject):
    """
    A collection of one ore more TeXObjects. When compiled, may be
    enclosed in some starting and ending strings and may have some
    separator.
    """
    start = TeXObject("")
    end = TeXObject("")
    sep = TeXObject(" ")

    def __init__(self, objs=None, start=None, end=None, sep=None):
        if objs is None:
            objs = []
        elif type(objs) is not list:
            objs = [objs]
        for obj in objs:
            obj = TeXObject(obj)
            obj.parent = self
        self.objs = objs
        if start is not None:
            self.start = TeXObject(start)
        if end is not None:
            self.end = TeXObject(end)
        if sep is not None:
            self.sep = TeXObject(sep)

    def addObj(self, obj):
        obj.parent = self
        self.objs.append(obj)

    def compile(self):
        start = self.start.compile()
        sep = self.sep.compile()
        objs = map(lambda o: TeXObject(o).compile(), self.objs)
        end = self.end.compile()
        return "".join([start, sep.join(objs), end])
예제 #7
0
 def compile(self):
     if self.parent and self.parent.objs[-1] is self:
         self.end = TeXObject()
     return TeXCollection.compile(self)
예제 #8
0
class TeXBlockMath(TeXCollection):
    start = TeXObject("$$", raw=True)
    end = TeXObject("$$", raw=True)
    sep = TeXObject()
예제 #9
0
class TeXInlineMath(TeXCollection):
    start = TeXObject("$", raw=True)
    end = TeXObject("$", raw=True)
    sep = TeXObject()
예제 #10
0
class TeXSet(TeXCollection):
    """
    A collection with no separator. This is useful for e.g a bunch of
    commands following one another
    """
    sep = TeXObject()
예제 #11
0
 def compile(self):
     start = self.start.compile()
     sep = self.sep.compile()
     objs = map(lambda o: TeXObject(o).compile(), self.objs)
     end = self.end.compile()
     return "".join([start, sep.join(objs), end])