Skip to content

Pandoc filter for embedding file in Latex output #9524

Answered by BongoKnight
BongoKnight asked this question in Q&A
Discussion options

You must be logged in to vote

Here is a python filter which does that :

from pandocfilters import toJSONFilter, RawInline, Str, Image
import re
from pathlib import Path

def latex(x):
    return RawInline('latex', x)


def latexembed(key, value, format, meta):
    if format == "latex":
        if key == 'Image':
            placeholder_image = Path(__file__).parent / 'paperclip.png'
            style, caption, file = value
            path = file[0]
            if headers := meta.get("header-includes"):
                if absolute_path_regex := re.search(r"graphicspath\{\{([^\}]+)\}\}", str(headers)):
                    path = absolute_path_regex.group(1) + path
            if re.search(r"\.(csv|xlsx|pdf|py|zip|md|tx…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by BongoKnight
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant