def figuretable(rows, cols, placement="t", label=None, caption=None): if label is None: label = randomref() Context.variables['cell'] = np.array([[Context(myparent=Context.context, indent=Context.context.indent+4) for c in range(0, cols)] for r in range(0, rows)], dtype=Context) latex("\\begin{figure*}[%s]" % (placement)) Context.context.add() #latex("\hline") for r in range(0, rows): for c in range(0, cols): Context.variables['cell'][r, c].add() latex("\\\\") if not caption is None: latex("\caption{%s}" % caption) BookKeeping.add_label(label, "figure") latex("\label{%s}" % label) latex("\end{figure*}") return label
def figure(image, caption=None, label=None, placement="t", scale=1.0): if label is None: label = randomref() latex("\\begin{figure}[%s]" % (placement)) Context.context.add() includegraphics(image, scale) if not caption is None: latex("\caption{%s}" % caption) BookKeeping.add_label(label, "figure") latex("\label{%s}" % label) latex("\end{figure}") return label
def latexblock(blockname, full_width=False, label=None): if label is None: label = randomref() if full_width: blockname.append('*') latex("\\begin{%s}" % blockname) Context.context.add() latex("\label{%s}" % label) latex("\end{%s}" % blockname) BookKeeping.add_label(label, "equation") return label
def subfigure(image, caption=None, label=None, placement="t", scale=1.0, width=None): if label is None: label = randomref() if width is None: width = str(1.0/Context.variables['cols']-0.01) + "\\textwidth" latex("\\begin{subfigure}[%s]{%s}" % (placement, width)) Context.context.add() includegraphics(image, scale) if not caption is None: latex("\caption{%s}" % caption) latex("\label{%s}" % label) latex("\end{subfigure}") #BookKeeping.add_label(label, "figure") # we should get this by getting the ref of parent, i.e. figuretable return label
def item(): latex("\item") Context.context.add()
def end_document(): latex("\end{document}")
def begin_document(): latex("\\begin{document}")
def documentclass(documenttype): latex("\documentclass{%s}" % documenttype)
def make_title(title, author): latex("\\title{%s}" % title) latex("\\author{%s}" % author) latex("\maketitle")
def center(): latex("\center")
def includegraphics(image, scale=1.0): latex("\includegraphics[scale=%f]{%s}" % (scale, image))
def table(rows, cols, width="\textwidth", placement="t", caption=None, label=None): if label is None: label = randomref() Context.variables['cell'] = np.array([[ Context(myparent=Context.context, indent=Context.context.indent + 4) for c in range(0, cols) ] for r in range(0, rows)], dtype=Context) #Context.variables['rows'] = rows #Context.variables['cols'] = cols latex("\\begin{table*}[%s]" % placement) Context.context.add() latexl("\\begin{tabular}{|c") for c in range(1, cols): latexl("|c") latex("|}") #context.evaluate() latex("\hline") for r in range(0, rows): for c in range(0, cols): Context.variables['r'] = r Context.variables['c'] = c Context.variables['cell'][r, c].add() if c < cols - 1: latexl("&") latex("\\\\ \hline") latex("\end{tabular}") maybe_caption(caption) latex("\label{%s}" % label) latex("\end{table*}") if caption is not None: BookKeeping.add_label(label, "table") return label
def raggedleft(): latex("\\raggedleft")
def raggedright(): latex("\\raggedright")
def add_bibliography(bibfile, bibstyle): latex("\\bibliography{%s}" % bibfile) latex("\\bibliographystyle{%s}" % bibstyle)
def url(url_string): latex("\url{%s}" % url_string)
def __init__(self, name, nesting=0): self.name = name self.nesting = nesting subsub = "sub" * self.nesting + "section" BookKeeping.add_label(name, subsub) latex("\\" + subsub + "{%s}" % self.name)
def centering(): latex("\centering")