Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change font size for HTML / PDF #9

Open
dr-harper opened this issue Oct 10, 2018 · 1 comment
Open

Change font size for HTML / PDF #9

dr-harper opened this issue Oct 10, 2018 · 1 comment

Comments

@dr-harper
Copy link
Contributor

dr-harper commented Oct 10, 2018

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.

@nathaneastwood
Copy link
Owner

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants