Escape problematic characters to allow compilation in LaTeX
Copied from knitr
for internal use because it is unexported and CRAN rejects :::
escape_latex(x, newlines = FALSE, spaces = FALSE)
x
: a character string to escapenewlines
: booleanspaces
: boolean