首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >自动将RMarkdown文本样式从一种更改为另一种

自动将RMarkdown文本样式从一种更改为另一种
EN

Stack Overflow用户
提问于 2019-05-10 05:49:16
回答 1查看 137关注 0票数 0

由于不同的日志要求,我需要频繁地将Rmarkdown中的某些文本样式从一种更改为另一种。例如,下面是一个示例Rmarkdown文档。

代码语言:javascript
运行
复制
---
title: "Changing format of Rmarkdown"
author: "Paul Hargarten"
date: "5/9/2019"
output: html_document
---

```{r setup, include=FALSE}

knitr::opts_chunk$set(echo =真)

代码语言:javascript
运行
复制
## R Markdown

This is an $\mathcal{R}$ Markdown document. Markdown is a simple formatting syntax for authoring **HTML**, **PDF**, and **MS Word* documents. For more details on using $\mathcal{R}$ Markdown see <http://rmarkdown.rstudio.com>. $\matcal{R}$ is based on $\mathcal{S}$.

When you click the `Knit` button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. Calculate a `summary` as follows: 

```{r cars}

摘要(汽车)

代码语言:javascript
运行
复制
## Including Plots
You can also embed plots, for example: `r  plot(pressure)`.

在不搜索确切短语的情况下,假设我想要查找并替换以下项目:

除以r开头的项目外,将以粗体显示的项目更改为斜体,将看起来像$\mathcal{ ... }$的项目更改为特殊字体`...`,将以r开头的项目更改为`r ... ` => $`r ... `$的美元符号。

是否可以使用regex在Rmarkdown中进行这些格式化样式的更改?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2019-05-10 20:14:52

如果您完全使用LaTeX,则可以根据该标记的用法定义自己的宏。例如,

代码语言:javascript
运行
复制
\newcommand{\booktitle}[1]{\textbf #1}

作为\booktitle{The Book}用于书名。

在R Markdown中可以做到这一点,但您不能使用**标记书名。你可以这样做(你可以在R Markdown中嵌入LaTeX ),但是它很丑陋。例如,

代码语言:javascript
运行
复制
---
title: Using LaTeX
output: pdf_document
---

```{r setup, include=FALSE}

knitr::opts_chunk$set(echo =真)

代码语言:javascript
运行
复制
\newcommand{\booktitle}[1]{\textbf{#1}}

This is \booktitle{The Book}.

一旦你这样做了,你最好切换到类似*.Rnw的格式,或者一直切换到LaTeX。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56068056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档