Change font size for HTML / PDF
dr-harper opened this issue · 1 comments
Based on this answer here, we can change the font size of code chunks using hooks:
def.chunk.hook <- knitr::knit_hooks$get("chunk")
knitr::knit_hooks$set(chunk = function(x, options) {
x <- def.chunk.hook(x, options)
ifelse(options$size != "normalsize", paste0("\\", options$size,"\n\n", x, "\n\n \\normalsize"), x)
})
I played around with this to also create a way for changing the size of HTML font:
def.chunk.hook <- knitr::knit_hooks$get("chunk")
knitr::knit_hooks$set(output = function(x, options) {
x <- def.chunk.hook(x, options)
if (!is.null(options$sizehtml)) {
paste0(
'<pre style = font-size:', options$sizehtml,'>', x, "</pre>")
} else {
x
}
})
It would be nice if there was a consistent way to change font size for both outputs with the same hook, but they use fundamentally different commands. What we could do is create our own scale of say 1 to 5, whereby:
1 = \tiny in Latex and rel(0.4) in HTML
2: \small in LaTeX and rel(0.7) in HTML
3: \normalsize in LaTeX and rel(1) in HTML
and so on
I haven't had enough time to examine your code to see how to format a PR for this, but I may get time over the weekend if you don't have time to work on the idea.
This sounds like a cool idea. I won't get a chance to work on it until Sunday at the earliest so if you do get a chance then feel free to submit a PR. Otherwise I'll take a look over the weekend :)