Create a Glossary in R Markdown

October 23, 2018

(This article was first published on Yongfu's Blog, and kindly contributed to R-bloggers)

I was thinking about creating a glossary in bookdown and found out that there was already an issue about it. I like Yihui’s recommendation: use Pandoc’s definition lists. This was exactly what I had been doing, but I quickly found out that there was a major drawback – the definition lists won’t order alphabetically unless written in that way.

So I wrote an R function to reorder the definition lists written in R Markdown. Note that this functions only works for R Markdown files containing defintion lists exclusively. If the R Markdown files aren’t whole-definition-lists, the function will fail.


To order the definition lists alphabetically, simply put the Rmd file path in the function. To have a different output file, provide the output file path as the second argument.

# sort_def_list("glossary.Rmd", "reordered.Rmd")

The output in PDF looks like this (I used the multicol package)1:

Source Code


  1. To see the source R Markdown file, visit glossary.rmd. To see the output PDF, visit glossary.pdf

Visit R-bloggers
Last updated: 2018-10-24

To leave a comment for the author, please follow the link and comment on their blog: Yongfu's Blog. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)