Knitr inline chunk options (no evaluation) or just render highlighted code

后端 未结 1 2012
逝去的感伤
逝去的感伤 2020-12-16 15:50

I cannot find information on whether it is possible to specify options for inline chunks in knitr. I\'ve just tried specifying them, as in the regular chunk, but this gives

1条回答
  •  死守一世寂寞
    2020-12-16 16:33

    Thanks to Yihui you can do,

    \documentclass{article} 
    <>= 
    knit_hooks$set(inline = function(x) { 
      if (is.numeric(x)) return(knitr:::format_sci(x, 'latex')) 
      highr::hi_latex(x) 
    }) 
    @ 
    \begin{document} 
    
    the value of $\pi$ is \Sexpr{pi}, and the function to read a table is 
    \Sexpr{'read.table()'}. 
    
    <>= 
    rnorm(10) 
    @ 
    \end{document} 
    

    0 讨论(0)
提交回复
热议问题