carpentries / glosario-r

glosario create and retrieve multilingual glossaries.
https://carpentries.github.io/glosario-r
Other
6 stars 5 forks source link

Generate different text for inline glossary reference depending on output format #16

Closed gvwilson closed 7 months ago

gvwilson commented 4 years ago

When an R Markdown document is being compiled into HTML, we want something like the following for a glossary entry:

<a href="https://glosario.carpentries.org/en/#some_key">some term</a>

But when the same document is being compiled into LaTeX/PDF, we want:

\glossref{some term}{some\_key}

(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.

fmichonneau commented 4 years 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
}
ian-flores commented 4 years ago

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 ?

gvwilson commented 4 years ago
  1. Clone https://github.com/yihui/bookdown-crc/
  2. Add a glossary reference.
  3. Build PDF. How do you see the glossary reference formatted?