AMH
AMH

Reputation: 23

Embedding \sigma (or \mu) into R-Markdown quiz question

I am trying to render the Greek sigma notation within a Quiz in R Markdown. If I use dollar signs, it only italicizes the word \sigma. If I use <span class="math inline">\sigma</span> I get an error".

question_radio(
  "Is this a statement about the standard deviation, $/sigma$, a proportion $p$, or something else?",
  answer("Standard deviation", correct = TRUE),
  answer("Proportion"),
  answer("Something else altogether"),
  allow_retry = TRUE,
  random_answer_order = TRUE
)

yields

enter image description here

question_radio(
  "Is this a statement about the standard deviation, <span class="math inline">\mu</span>, a proportion $p$, or something else?",
  answer("Standard deviation", correct = TRUE),
  answer("Proportion"),
  answer("Something else altogether"),
  allow_retry = TRUE,
  random_answer_order = TRUE
)

yields

Error in parse(): ! :2:67: unexpected symbol 1: question_radio( 2: "Is this a statement about the standard deviation, <span class="math ^ Backtrace:

  1. rmarkdown::run(...)
  2. rmarkdown:::shiny_prerendered_app(target_file, render_args = render_args)
  3. rmarkdown:::shiny_prerendered_html(input_rmd, render_args)
  4. rmarkdown (local) <fn>(...)
  5. knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet) ...
  6. knitr:::eng_r(options)
  7. rmarkdown (local) evaluate(...)
  8. evaluate::evaluate(code, envir, ...)
  9. evaluate:::parse_all.character(...)
  10. base::parse(text = x, srcfile = src) Execution halted

I have looked through much documentation on writing quizzes, but I've had no luck.

EDIT: Answer: Use $\sigma$ or $\\sigma$ within the question function. I mistakenly used forward slashes. Ugh.

Upvotes: 2

Views: 810

Answers (1)

Ali Safari
Ali Safari

Reputation: 1775

You need to enclose it in double backslashes to escape the backslash character in R Markdown. By using $\\sigma$, the Greek sigma symbol should be rendered correctly in the quiz question:

question_radio(
  "Is this a statement about the standard deviation, $\\sigma$, a proportion $p$, or something else?",
  answer("Standard deviation", correct = TRUE),
  answer("Proportion"),
  answer("Something else altogether"),
  allow_retry = TRUE,
  random_answer_order = TRUE
)

Upvotes: 0

Related Questions