[This article was first published on Yongfu's Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

## Usage

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")
# sort_def_list("glossary.Rmd", "reordered.Rmd")

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

## Notes

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