def h_latex_div(e, doc): r"""make every div with class=foo to begin{foo} ... end{foo} if there is title then it is begin{foo}[title] instead if there is an identifier then we add \label[foo]{id}""" if not isinstance(e, pf.Div): return None if not len(e.classes): return None c = e.classes[0] title = e.attributes.get("title", "") label = labelref(e, doc) if label in doc.labels: name = getlabel(label, doc)[0] else: name = c.capitalize() if title: name += f" ({title}) " e.attributes["name"] = name if e.identifier: doc.label_descriptions[e.identifier] = c.capitalize() if doc.format == 'html' and c == 'quote': return pf.BlockQuote(e) if doc.format != 'latex': return None dref = e.attributes.get("data-ref", None) if not title and c == "proof" and dref and dref != doc.lastlabel: title = fr"Proof of \cref{{{dref}}}" label = labelref(e, doc) doc.lastlabel = label before = rf"\begin{{{c}}}[{title}]" if title else rf"\begin{{{c}}}" if label: before += rf" \label[{c}]{{{label}}}" if c == "algorithm": before += r"~ \\ \noindent" + "\n" after = rf"\end{{{c}}}" _before = pf.RawBlock(before, format='latex') _after = pf.RawBlock(after, format='latex') e.content = [_before] + list(e.content) + [_after] return e
def bq(elem, doc): """ Add a ::: bq div to make a <blockquote> """ if not isinstance(elem, pf.Div): return None if elem.classes == ['bq']: return pf.BlockQuote(*elem.content)
def prepare(doc): if u'abstract' in doc.metadata : text = [ pf.Para(pf.Str(txt)) for txt in doc.get_metadata('abstract').split('\n\n') ] abstract = pf.Div(pf.BlockQuote(*text),identifier="abstract") doc.content.insert(0,abstract)