I want to be able to convert markdown italics and in bold to latex versions "on the fly" (ie give a text string (s), return a text string (s)). I thought easy. Wrong! (What else could be). Look at the windowsill and the error that I tried below.
What I have (pay attention to the starting asterisk, which was escaped as in the markdown method):
x <- "\\*note: I *like* chocolate **milk** too ***much***!"
What I would like:
"*note: I \\emph{like} chocolate \\textbf{milk} too \\textbf{\\emph{much}}!"
I am not attached to regex, but would prefer a basic solution (although not necessarily).
Stupid business:
helper <- function(ins, outs, x) { gsub(paste0(ins[1], ".+?", ins[2]), paste0(outs[1], ".+?", outs[2]), x) } helper(rep("***", 2), c("\\textbf{\\emph{", "}}"), x) Error in gsub(paste0(ins[1], ".+?", ins[2]), paste0(outs[1], ".+?", outs[2]), : invalid regular expression '***.+?***', reason 'Invalid use of repetition operators'
I have this toy that Ananda Mahto helped me make, if it would be useful. You can access it from reports via wheresPandoc <- reports:::wheresPandoc
EDIT In the comments on Bren, I tried:
action <- paste0(" echo ", x, " | ", wheresPandoc(), " -t latex ") system(action) *note: I *like* chocolate **milk** too ***much***! | C:\PROGRA~2\Pandoc\bin\pandoc.exe -t latex
EDIT2 In the comments on Dason, I tried:
out <- paste("echo", shQuote(x), "|", wheresPandoc(), " -t latex"); system(out) system(out, intern = T) > system(out, intern = T) \*note: I *like* chocolate **milk** too ***much***! | C:\PROGRA~2\Pandoc\bin\pandoc.exe -t latex