1

I'm creating Quarto book and I would like key terms in the book to link to definitions in a glossary. Additionally, I'd like the glossary to work in both HTML and PDF formats. Here's what I have so far.

For the examples below, assume my project has two files:

  1. chapter.qmd
  2. glossary.qmd

Method 1: Link to glossary headings

Let's say that we want to define the term data frame in the glossary. The first thing I did was turn the word "data frame" into a heading and assign it an ID in glossary.qmd.

## Data frame {#glossary-data-frame .unnumbered}

Next, I used a hyperlink to reference that heading in the narrative of chapter.qmd.

We want to define the term [data frame](glossary.qmd#glossary-data-frame) in the glossary.

This works, but because each glossary term is a heading, it appears in the table of contents of the PDF version of the book. Because I may end up with hundreds of terms, that isn't ideal.

Method 2: Use anchor tags

Following this SO post, I tried using anchor tags in glossary.qmd instead of headings. I also used a little bit of CSS to increase the font size and bold the linked term in the glossary. For example:

.glossary-term {
  font-size: 14pt;
  font-weight: bold;
}
<a name="glossary-data-frame">
  <span class="glossary-term">
    Data frame
  </span>
</a>

Next, I once again used a hyperlink to reference that anchor in the narrative of chapter.qmd.

We want to define the term [data frame](glossary.qmd#glossary-data-frame) in the glossary.

That also works fine for the HTML version of the book. However, the links aren't active in the PDF version of the book and none of the CSS styling is applied. I'm not necessarily surprised by that, but I have no idea how to fix it.

So, I'd appreciate guidance on:

  1. Removing the glossary terms from the PDF table of contents if I use method 1, or
  2. Making the links active and adjusting the font styling in the PDF version of the book if I use method 2, or
  3. Some other solution that achieves the result I'm shooting for.

Thanks for your time and consideration!

This question is also posted on Posit Community

Brad Cannell
  • 3,020
  • 2
  • 23
  • 39

1 Answers1

1

Instead of using section to reference to the glossary:

Pandoc already supports definition lists. , which for HTML output render to description list (<dl>) elements. -- all credits to Salim!

# Glossary {.unnumbered}

[Data frame]{#glossary-data-frame}

:   A data frame has columns and rows.

And only the glossary without its definitions will be produced:

enter image description here

and work in both PDF and HTML:

enter image description here

Julian
  • 6,586
  • 2
  • 9
  • 33