Closed gvwilson closed 7 months ago
I have done things like this in the past by creating a function that looks like:
switch_include <- function(...) {
if (knitr::is_latex_output()) {
## returns something latex specific
}
## returns something for HTML
}
In here we can see that what I implemented adds a Markdown link which then gets rendered as a PDF link or as an HTML anchor tag. It is surrounded by a <span>
tag to add CSS to the defs but it's not obtrusive with the PDF version. Did that cause problems @gvwilson ?
When an R Markdown document is being compiled into HTML, we want something like the following for a glossary entry:
But when the same document is being compiled into LaTeX/PDF, we want:
(Or something like that---the user may want some other LaTeX command for glossary references.) We cannot generate the former and hope that Pandoc will translate it into the latter. We also cannot generate LaTeX and hope that Pandoc will translate it into HTML, since Pandoc doesn't handle user-defined commands.
I have used a Lua filter to solve this problem in a book project https://github.com/merely-useful/py-rse/pull/467, but we should think about how to configure the function for inserting definitions into text to handle this.