Search code examples
rlatexr-markdownmarkdownbeamer

How to escape a colon in the header-includes in a YAML header


I use a custom LaTex beamer theme in an rmarkdown::beamer_presentation.

The custom theme contains a title frame. As per this SO post markdown can be tricked to use the new title frame using header-includes: - \AtBeginDocument{\titleframe}.

My title contains a colon and ideally a linebreak: First line of title:\n second line of title. However, if I include the colon, the compilation of the presentation fails.

How can I escape the colon and, if feasible, force a linebreak right after it?

MWE (YAML header)

---
# 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}   
---

For remainder of MWE, i.e. the beamertheme*.sty files, see the mentioned SO post.


Solution

  • You can hide the title from markdown in a .tex file:

    ---
    # 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}