In an R Markdown document, “includes” for docx output?

时光毁灭记忆、已成空白 提交于 2019-12-12 22:57:41

问题


In the .Rmd below I have includes: in_header: for pdf output and includes: before_body: for docx output. Is there something analogous for docx output?

My current hack is to include the <!--- For DOCX Only ---> code chunk conditionally when producing docx output. But I'd prefer not to have this clutter up the body of my .Rmd and move it out into some sort of preamble-word.tex file.

tinytextest.Rmd

---
title: "TinyTeX Test"
author: "Me"
date: "5/3/2019"
output:
  word_document: default
  html_document:
    includes:
      before_body: preamble-mathjax.tex
  pdf_document:
    includes:
      in_header: preamble-v02.tex
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

<!--- For DOCX Only --->
`r if (!knitr:::is_latex_output() & !knitr:::is_html_output()) '
\\newcommand{\\mathbbm}[1]{\\mathbf{#1}}
'`

Hello

\[\mathbbm{1}_{S}(x)\]

preamble-mathjax.tex

\(\\newcommand{\\mathbbm}[1]{\\mathbf{#1}}\)

preamble.tex

\usepackage{bbm}

来源:https://stackoverflow.com/questions/56211083/in-an-r-markdown-document-includes-for-docx-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!