2

I'm trying to write python code that can convert an rmd file to html. Rmd was not listed as one of the built in formats for pypandoc, so I tried to use regular markdown for the format parameter.

output = pypandoc.convert_file(
            f"{file_path}/{file}", 'html', format = 'markdown', outputfile= f"{file_path}/{file}.html", encoding = 'utf-8')

But I get the error that it could not be converted "[WARNING] Could not convert TeX math site."

Is there another way to convert the file without changing the TeX math?

0

1 Answer 1

0

It depends on the style of TeX math content used in the Rmd file, but if you used dollar signs, something like this should work

output = pypandoc.convert_file(
    f"{file_path}/{file}",
    'html',
    format='markdown+tex_math_dollars',
    outputfile=f"{file_path}/{file}.html",
    encoding='utf-8'
)

You can find examples for other styles (e.g. single backslash) here: https://pandoc.org/MANUAL.html#extension-tex_math_single_backslash

Also, you can take a look at https://pypi.org/project/knitpy/ which is a port of knitr for Python, as there are elements of RMarkdown which won't be recognized by pandoc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.