如何在 YAML 标头中的标头包含中转义冒号

问题描述

我在 LaTex beamer theme 中使用自定义 rmarkdown::beamer_presentation

自定义主题包含一个标题框架。根据 this SO post markdown 可以通过 header-includes: - \AtBeginDocument{\titleframe} 欺骗使用新的标题框架。

我的标题包含一个冒号,最好是一个换行符:First line of title:\n second line of title。 但是,如果我包含冒号,则演示文稿的编译会失败。

如何转义冒号,并在可行的情况下在冒号后立即强制换行?

MWE(YAML 标头)

---
# do not add title here,else markdown generates a second title page
# ==> add title manually below with header-includes
subtitle: "Beamer presentation with R-markdown"
institute: "some place"
date: "`r format(Sys.time(),'%B %d,%Y')`"
author: "Donald Duck"
output:
  bookdown::pdf_book:
    base_format: rmarkdown::beamer_presentation
    theme: "THEMENAME"
    latex_engine: xelatex
    toc: false
    slide_level: 2
    keep_tex: true 
header-includes:
  - \title{First line of the title: second line of the title}
  - \AtBeginDocument{\titleframe}   
---

对于 MWE 的其余部分,即 beamertheme*.sty 文件,请参阅 the mentioned SO post

解决方法

你可以在 .tex 文件中隐藏 markdown 的标题:

---
# do not add title here,else markdown generates a second title page
# ==> add title manually below with header-includes
subtitle: "Beamer presentation with R-markdown"
institute: "some place"
date: "`r format(Sys.time(),'%B %d,%Y')`"
author: "Donald Duck"
output:
  bookdown::pdf_book:
    base_format: rmarkdown::beamer_presentation
    theme: "THEMENAME"
    latex_engine: xelatex
    toc: false
    slide_level: 2
    keep_tex: true 
header-includes:
  - \input{preamble}
  - \AfterBeginDocument{\titleframe}   
---

test

preamble.tex:

\title[short version]{First line of the title: second line of the title}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...