7.1 Render Slides

There are two steps to render slides to pdf:

  1. Render Rmd to html with rmarkdown::render
  2. Print html to pdf with pagedown::chrome_print
rmarkdown::render('equity_valuation.Rmd')
pagedown::chrome_print('equity_valuation.html')

Two-in-one option:

✅ use renderthis package to render slides and print to pdf in one function.

renderthis::to_pdf('equity_valuation.Rmd')

This will call rmarkdown::render and then pagedown::chrome_print automatically. Will generate equity_valuation.html and equity_valuation.pdf accordingly based on your output formats.

Print Notes

print-notes.R is a script to print slides with presenter notes to pdf. See the section Print to PDF with presenter notes for details.

In terminal, run the following command to print slides with notes to pdf:

./print-notes.R <deck>.Rmd

Add Bookmarks

Use add-bookmarks.R to add bookmarks to the pdf output. Run the following command in terminal:

./add-bookmarks.R <deck>.pdf

Issue: Fonts are not embedded / applied in the pdf output.

Fix: Set pdf output font specifically.

@media print {
    body {
        font-family: 'Noto Sans', -apple-system, BlinkMacSystemFont, system-ui, Arial, sans-serif !important;
        font-weight: 400 !important;
    }
    strong, b {
        font-weight: 700 !important;
    }
    /* MathJax font for print */
    .mjx-chtml {
        font-family: 'Georgia Pro', 'Libertinus Serif', serif !important;
        font-weight: 700 !important;
        color: red !important; /* for testing purpose, whether selector is correct */
    }
}
  • Note that .mjx-chtml controls math typesetting. The tricky point is that MathJax CommonHTML math uses its own fonts for math rendering, and CSS font-family is NOT respected.

  • Color and font-weight may work, but font-family is limited by MathJax’s internal font stack. For true font control, you need to change MathJax’s configuration, which is not easily done in xaringan.

  • html output and pdf output may use different fonts.

    Issue: If keeping @import in CSS, I cannot get the font applied in pdf output.

    Fix: What I do, a compromise solution, is to

    • use system font for html output, and
    • specify local font for pdf output.