Exemple #1
0
 def __init__(self, env, objs=None):
     TeXCollection.__init__(self, objs)
     # We need to add the \n by hand here because the separator
     # isn't included for the start/end delimiters
     self.start = TeXSet([TeXCommand("begin", env), "\n"])
     self.end = TeXSet(["\n", TeXCommand("end", env)])
     self.sep = TeXObject("\n")
Exemple #2
0
def ensure_math(obj):
    return TeXSet([
        TeXCommand("ifmmode"),
        TeXGroup(obj),
        TeXCommand("else"),
        TeXGroup(obj),
        TeXCommand("fi")
    ])
Exemple #3
0
def simple_latex_document(body, packages=None, pagestyle="empty"):
    if packages is None:
        packages = []
    extra_packages = TeXCollection(sep="\n")
    for package in packages:
        if type(package) is str:
            extra_packages.addObj(TeXCommand("usepackage", package))
        else:
            extra_packages.addObj(
                TeXCommand("usepackage", package[0], package[1]))
    return TeXCollection([
        TeXCommand("documentclass", "article", opts=["12pt"]),
        TeXCommand("usepackage", "geometry", opts=["margin=1in"]),
        extra_packages,
        TeXCommand("pagestyle", pagestyle),
        LaTeXEnvironment("document", body)
    ],
                         sep="\n").compile()
Exemple #4
0
def tex_escape_string(s):
    special_chars = {
        "#": TeXCommand("#"),
        "$": TeXCommand("$"),
        "%": TeXCommand("%"),
        "&": TeXCommand("&"),
        "_": TeXCommand("_"),
        "{": TeXCommand("{"),
        "}": TeXCommand("}"),
        "~": TeXEmptyCommand("~"),
        "^": TeXEmptyCommand("^"),
        "\\": ensure_math(TeXCommand("backslash")),
    }
    escaped = []
    for c in s:
        if c in special_chars:
            escaped.append(special_chars[c].compile())
        else:
            escaped.append(c)
    return "".join(escaped)
Exemple #5
0
 def __init__(self, env, colfmt, objs=None):
     LaTeXEnvironment.__init__(self, env, objs)
     self.start = TeXSet([TeXCommand("begin", env, colfmt), "\n"])
Exemple #6
0
 def __init__(self, cmd):
     TeXCommand.__init__(self, cmd, TeXObject(""))
Exemple #7
0
def unmath(x):
    return TeXCommand("mbox", x)
Exemple #8
0
 def __init__(self, cmd):
     TeXCommand.__init__(self, cmd, TeXObject(""))