'Define color of newthought() with Tufte style when rendering to pdf

I have no problem defining color of newthought() with Tufte style when rendering to HTML, as follows:

<font color = "blue">`r newthought('The Lab Supervisor')`</font> ...

However, it does not work out when rendering to pdf.

I learned to define color when rendering to both HTML and pdf by the following code:

em <- function(x, color) {
  if (knitr::is_latex_output()) {
    sprintf("\\textcolor{%s}{%s}", color, x)
  } else if (knitr::is_html_output()) {
    sprintf("<span style='color: %s;'>%s</span>", color,
      x)
  } else x
}

Then I apply in-line R expression as follows:
``` `r em("The Lab Supervisor", "blue")` ```

Is there any solution that I could combine both `r newthought()`and `r em()` so that The Lab Supervisor is set to small caps in blue when rendering to pdf?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source