1

I am using functions described here to render multiple independent R scripts in a single markdown files. But I am not able to include a formatted equation in those scripts. My .Rmd file looks like:

--- 
title: "My title"
author: "Nacho"
output: 
  bookdown::html_document2:
    base_format: rmdformats::downcute
--- 

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

join <- function(ls, sep = ", "){
do.call(paste, append(ls, list(sep = sep))) 
}

inline_render <- function(script_name){
suppressMessages(capture.output(rmarkdown::render(paste0(script_name, ".R"), 
output_format = "rmarkdown::md_document"), file = "tmp"))
cat(join(readLines(paste0(script_name, ".md")), "\n"))
}
```

Here is some text defining the scope of the analysis...

```{r script, echo=FALSE, results='asis'}
inline_render("script")
```

And in my script I have defined an equation:

#'
#'  $$\frac{d_{A}}{dt} = K_{rel}\times A$$
#'

But when this .R is rendered to .md, I get this warning:

[WARNING] Could not convert TeX math \frac{A}{dt} = K_{rel}\times A, rendering as TeX

and this is what is what I find in the .md

$$\\frac{d\_{DXD}}{dt} = K\_{rel}\\times A\_{T-DXd}$$

So, when this is rendered to the final .html I just the plain text ignoring all \*.

I tried to edit the intermediate .md file to remove one of the \ but the one remaining seems to be ignored by the cat() call.

Could anyone help me with this?

Nacho Glez
  • 385
  • 3
  • 15
  • There is an extra curly brace `}` at the end of your math formula. – Stéphane Laurent Nov 21 '22 at 11:26
  • Hi @StéphaneLaurent, that was a typo in the post, but not in my actual code. – Nacho Glez Dec 08 '22 at 10:22
  • I'm currently puzzling over a (possibly similar) problem when trying to include $\sqrt{x}$ in the github-hosted README of my RStudio project. Possibly relevant: https://stackoverflow.com/questions/59775941/rstudio-readme-rmd-and-readme-md-should-be-both-staged-use-git-commit-no-veri https://rmarkdown.rstudio.com/docs/news/index.html#rmarkdown-217 https://stackoverflow.com/questions/52313094/pandoc-warning-could-not-convert-tex-math/74935912#74935912. This/that; esto/eso/aquello; “When I use a word… it means just what I choose it to mean – neither more nor less.” – Clark Thomborson Dec 28 '22 at 05:46

0 Answers0