How to use the panflute.RawInline function in panflute

To help you get started, we’ve selected a few panflute examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chdemko / pandoc-latex-tip / pandoc_latex_tip.py View on Github external
def _add_latex(elem, latex):
    if bool(latex):
        # Is it a Span or a Code?
        if isinstance(elem, (Span, Code)):
            return [elem, RawInline(latex, "tex")]

        # It is a CodeBlock: create a minipage to ensure the _tip to be on the same page as the codeblock
        if isinstance(elem, CodeBlock):
            return [
                RawBlock("\\begin{minipage}{\\textwidth}" + latex, "tex"),
                elem,
                RawBlock("\\end{minipage}", "tex"),
            ]

        # It is a Div: try to insert an inline raw before the first inline element
        inserted = [False]

        def insert(element, _):
            if (
                not inserted[0]
                and isinstance(element, Inline)
github sergiocorreia / panflute / examples / panflute / myemph.py View on Github external
def latex(s):
    return pf.RawInline(s, format='latex')
github chdemko / pandoc-latex-tip / pandoc_latex_tip.py View on Github external
doc.metadata["header-includes"] = MetaList()
    # Convert header-includes to MetaList if necessary
    elif not isinstance(doc.metadata["header-includes"], MetaList):
        doc.metadata["header-includes"] = MetaList(doc.metadata["header-includes"])

    doc.metadata["header-includes"].append(
        MetaInlines(RawInline("\\usepackage{needspace}", "tex"))
    )
    doc.metadata["header-includes"].append(
        MetaInlines(RawInline("\\usepackage{graphicx,grffile}", "tex"))
    )
    doc.metadata["header-includes"].append(
        MetaInlines(RawInline("\\usepackage{marginnote}", "tex"))
    )
    doc.metadata["header-includes"].append(
        MetaInlines(RawInline("\\usepackage{etoolbox}", "tex"))
    )
    doc.metadata["header-includes"].append(
        MetaInlines(RawInline("\\usepackage{changepage}\n\\strictpagecheck", "tex"))
    )
    doc.metadata["header-includes"].append(
        MetaInlines(
            RawInline(
                r"""
\makeatletter%
\@ifpackagelater{marginnote}{2018/04/12}%
{%
\newcommand{\oddinnertip}{\reversemarginpar}%
\newcommand{\eveninnertip}{\reversemarginpar}%
\newcommand{\oddoutertip}{\normalmarginpar}%
\newcommand{\evenoutertip}{\normalmarginpar}%
\newcommand{\oddlefttip}{\reversemarginpar}%
github chdemko / pandoc-latex-admonition / pandoc_latex_admonition.py View on Github external
\makeatletter%
\if@twoside%
\setboolean{admonitiontwoside}{true}
\else%
\setboolean{admonitiontwoside}{false}
\fi%
\makeatother%
""",
                "tex",
            )
        )
    )
    # Define specific environments
    for environment in doc.defined + doc.added:
        doc.metadata["header-includes"].append(
            MetaInlines(RawInline(new_environment(doc, environment), "tex"))
        )
github sergiocorreia / panflute-filters / filters / acronyms.py View on Github external
def action(e, doc):
    if isinstance(e, pf.Link) and e.url == 'acro':
        acronym = pf.stringify(e)
        definition = e.title
        # Only update dictionary if definition is not empty
        if definition:
            doc.acronyms[acronym] = definition
        
        if doc.format == 'latex':
            tex = '\gls{{}}'.format(acronym)
            tex = TEMPLATE_GLS.safe_substitute(acronym=acronym)
            return pf.RawInline(tex, format='latex')
github chdemko / pandoc-latex-color / pandoc_latex_color.py View on Github external
# Add usefull LaTexPackage
    doc.metadata["header-includes"].append(
        MetaInlines(RawInline("\\usepackage{xcolor}", "tex"))
    )
    doc.metadata["header-includes"].append(
        MetaInlines(RawInline("\\usepackage{soulutf8,color}", "tex"))
    )
    doc.metadata["header-includes"].append(
        MetaInlines(RawInline("\\soulregister\\cite7", "tex"))
    )
    doc.metadata["header-includes"].append(
        MetaInlines(RawInline("\\soulregister\\ref7", "tex"))
    )
    doc.metadata["header-includes"].append(
        MetaInlines(RawInline("\\soulregister\\pageref7", "tex"))
    )

    for color, value in x11colors().items():
        doc.metadata["header-includes"].append(
            MetaInlines(
                RawInline("\\definecolor{" + color + "}{HTML}{" + value + "}", "tex")
            )
        )

    if doc.format == "beamer":
        special_beamer = [
            "\\makeatletter",
            "\\let\\HL\\hl",
            "\\renewcommand\\hl{%",
            "\\let\\set@color\\beamerorig@set@color",
            "\\let\\reset@color\\beamerorig@reset@color",
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
replace_section_number(self._link, self._section_number)
        replace_local_number(self._link, self._local_number)
        if self._doc.format == "latex":
            replace_page_number(self._link, self._tag)

        # Compute entry
        replace_description(self._entry, self._description)
        replace_title(self._entry, self._title)
        replace_global_number(self._entry, self._global_number)
        replace_section_number(self._entry, self._section_number)
        replace_local_number(self._entry, self._local_number)

        # Finalize the content
        if self._doc.format == "latex":
            self._get_content()[0].content.insert(
                0, RawInline("\\label{" + self._tag + "}", "tex")
            )

            latex_category = re.sub("[^a-z]+", "", self._basic_category)
            latex = (
                "\\phantomsection\\addcontentsline{"
                + latex_category
                + "}{"
                + latex_category
                + "}{\\protect\\numberline {"
                + self._leading
                + self._number
                + "}{\\ignorespaces "
                + to_latex(self._entry)
                + "}}"
            )
            self._get_content().insert(0, RawInline(latex, "tex"))
github sergiocorreia / panflute / examples / panflute / lilypond.py View on Github external
def latex(code):
    """LaTeX inline"""
    return RawInline(code, format='latex')
github chdemko / pandoc-latex-color / pandoc_latex_color.py View on Github external
def add_latex(elem, color, bgcolor):
    # Is it a Span?
    if isinstance(elem, Span):
        if bgcolor:
            elem.content.insert(0, RawInline(bgcolor + "\\hl{", "tex"))
            elem.content.append(RawInline("}", "tex"))

        elem.content.insert(0, RawInline(color, "tex"))

    # Is it a Div?
    elif isinstance(elem, Div):
        if bgcolor:
            elem.content.insert(0, RawBlock("{" + color + bgcolor + "\\hl{", "tex"))
            elem.content.append(RawBlock("}", "tex"))
        else:
            elem.content.insert(0, RawBlock("{" + color, "tex"))
            elem.content.append(RawBlock("}", "tex"))