windows - 将 Markdown 斜体和粗体转换为 latex

标签 windows r latex markdown

我希望能够即时将 Markdown 斜体和粗体转换为 latex 版本(即,提供一个文本字符串返回一个文本字符串)。我以为很简单。错误的! (它仍然可能是)。请参阅我在底部尝试的阈值业务和错误。

我有什么(注意在 markdown 中被转义的起始星号):

x <- "\\*note: I *like* chocolate **milk** too ***much***!"

我想要什么:

"*note: I \\emph{like} chocolate \\textbf{milk} too \\textbf{\\emph{much}}!"

我不喜欢正则表达式,但更喜欢基本解决方案(尽管不是必需的)。

愚蠢的生意:

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'

我有this toy Ananda Mahto 帮我做的,如果有帮助的话。您可以通过 wheresPandoc <- reports:::wheresPandoc 从报告中访问它

编辑 我试过 Per Ben 的评论:

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 我试过 Dason 的评论:

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

最佳答案

Windows 上缺少管道使这变得棘手,但您可以使用 input 来提供 stdin 来绕过它:

> x = system("pandoc -t latex", intern=TRUE, input="\\*note: I *like* chocolate **milk** too ***much***!")
> x
[1] "*note: I \\emph{like} chocolate \\textbf{milk} too \\textbf{\\emph{much}}!"

关于windows - 将 Markdown 斜体和粗体转换为 latex ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15539121/

相关文章:

javascript - 无法在桌面上为远程 IP 文件创建快捷方式

windows - 如何从批处理文件运行命令并立即返回?

r - 每组唯一值的累积计数

r - 如何使用多个变量和因子的所有可能组合运行 lm 模型

latex - 如何对具有多行单元格的表格进行编码

python - matplotlib:在文本框中使用 LaTeX 时覆盖字符串中的下划线

windows - ClientPerfCountersInstaller.exe 停止工作,现在无法运行 Azure 解决方案

r - 如何生成和绘制所有生成树?

python - Sphinx Latex 输出文件名

windows - 是否可以在Windows CE 5.0 浏览器中查看部署在IIS 6.0 上的silverlight 或asp.net 3.5 网站?