0

I know I can use $$ to write \LaTeX in Rmarkdown documents like $\beta$. My goal is if this is possible inside inline code.

I would do `$\beta$` or `$\\beta$`, but both do not work.

In case it is not possible, is there some way to generate a greek letter inside inline code in Rmarkdown?

Following https://stackoverflow.com/questions/26821326/how-can-i-write-special-characters-in-rmarkdown-latex-documents, I tried `β`.

But it also does not work. What can I do?

Thanks!

  • What is your intended output? – TeXnician Mar 27 at 17:09
  • A greek letter beta highlighted just as (and together other) verbatim code, as in Rmarkdown, markdown or here is done with two backticks, one at the beginning and other at the end of the highlighted expression. – iago Mar 28 at 15:18
  • Have you tried to simply use the unicode character (and an appropriate font) within backticks? – TeXnician Mar 28 at 20:19
  • Yes, I tried the unicode character instead of β (without changing anything about the font; how should I do?), but not success. – iago Mar 28 at 22:26
1

Here I found that it depends on the type of area you are working in and potentially easier if your target is to show it in html rather than pdf so within a code chunk I got best success with <code><mathml><mi>&#x03B2;</mi></mathml></code>

Whereas outside a code chunk I found I had to simply use

β

enter image description here

Note the highlighted β

2

The inline code is to show code verbatim, not to "interpret" that code. What you want is completely contradictory. So you have two options:

  1. Text with `in line` $\beta$ `code`  or ...

  2. Text with \texttt{in line $\beta$ code}. 
  • 1
    Alternately just highlight an imbedded beta ` β ` β – user170109 Mar 31 at 0:05
  • @KJO Maybe with some additional work in the YAML header, but in this Rmarkdown as is that only produce a fatal error with pdflatex (cannot manage U+03B2) or it is silently omitted with xelatex or lualatex. – Fran Mar 31 at 3:44
  • OK I just ran \beta inside rstudio to generate the preview symbol then cut and pasted back into the editor and it looked ok in html (boxed in grey) – user170109 Mar 31 at 3:46
  • But you realized that in this site it is assumed that the final goal is convert to TeX code compile it by a TeX engine, not to HTML code generated by R, right? :D – Fran Mar 31 at 4:34
  • I am just the devils advocate The question is just like others as to how to use TeX to output to XXX (DVI PDF HTML MarkDown some come some go) the way to use the $\Beta$ is either uses a tex package to add a grey "highlight" OR to emulate the way this site/markdown works with such a verbatim environment then include it converted as if it will be done during compilation. hence the suggestion to pre-empt the tex-ps-pdf-html steps the final R output would be without highlighting <mi>&#x03B2;<!-- β --></mi> or with code tags to address the question needs to become <code>β</code> – user170109 Mar 31 at 21:03
0

You can try `r paste0("$\\beta$ = ", mean(mtcars$mpg))`.

  • I do not get what I want., since it is not highlighted like verbatim code. – iago Mar 28 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.