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")
def ensure_math(obj): return TeXSet([ TeXCommand("ifmmode"), TeXGroup(obj), TeXCommand("else"), TeXGroup(obj), TeXCommand("fi") ])
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()
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)
def __init__(self, env, colfmt, objs=None): LaTeXEnvironment.__init__(self, env, objs) self.start = TeXSet([TeXCommand("begin", env, colfmt), "\n"])
def __init__(self, cmd): TeXCommand.__init__(self, cmd, TeXObject(""))
def unmath(x): return TeXCommand("mbox", x)