Search code examples
latexr-markdownquarto

How to evaluate variables within LaTeX within Rmd or qmd docs


I want to evaluate these variables within LaTeX, but the inline code convention `r ` will not evaluate within $$ $$.

K <- 1e3
P <- 0.6

$$Binomial(k= `r K`, p = `r P`)$$


Solution

  • I'm not sure if you can execute inline code within LaTeX environment in quarto or RMarkdown.

    Here's a workaround which displays the intended output.

    Chunk options: {r results='asis', echo=FALSE}

    Chunk contents:

    K <- 1e3
    P <- 0.6
    
    cat("$$Binomial(k = ", K, ", p= ", P, ")$$")
    

    Result:

    enter image description here