7.1 Render Slides
There are two steps to render slides to pdf:
- Render
Rmdtohtmlwithrmarkdown::render - Print
htmltopdfwithpagedown::chrome_print
Two-in-one option:
✅ use renderthis package to render slides and print to pdf in one function.
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.
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-chtmlcontrols 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
@importin 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.