2
votes

I'd like to use the bib2gls latex package in my rmarkdown document to insert a list of acronyms from a .bib file when I knit to a pdf document.

Doesn't work:

Using a .bib file to store my acronyms. Example:

abbreviations.bib file:

@abbreviation{ecoli, 
short={E.~coli},
long={Escherichia coli}
}


@abbreviation{raustralis ,
short ={R.~ australis},
long={Rickettsia australis}
}

preamble.tex

% fixes problem with glossaries causing mathspec
% to return an error asking for amsmath to be loaded first    
\makeatletter 
\let\RequirePackage\original@RequirePackage
\let\usepackage\RequirePackage
\makeatother

% using bib2gls
\usepackage[record,abbreviations,style=index]{glossaries-extra}
\setabbreviationstyle{long-short}
\GlsXtrLoadResources[src={abbreviations},selection={all}]

rmarkdown file:

---
output: 
  pdf_document:
    latex_engine: xelatex
    includes:
      in_header: preamble.tex
title: "mwe"

---

## R Markdown

This is the first instance \gls{ecoli}, \gls{raustralis}. This is the second instance: \gls{ecoli}, \gls{raustralis}.

\printunsrtglossary[title={Abbreviations},type=abbreviations]

The output when I knit the rmarkdown documents looks like: enter image description here

What works:

Removing \GlsXtrLoadResources[src={abbreviations},selection={all}] and adding my entries into the preamble.

% using bib2gls
\usepackage[abbreviations,style=index]{glossaries-extra}
\setabbreviationstyle{long-short}
\newabbreviation{ecoli}{E.~coli}{Escherichia coli}
\newabbreviation{raustralis}{R.~australis}{Rickettsia australis}

enter image description here

I'd like to use the separate .bib file in the first approach if possible. Unless there is a better approach to do this in R. Session info is below:

R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252  
1

1 Answers

2
votes

The Problem is that bib2gls requires an additional program to be run, which extracts the glossary entries from the bib file, but rmarkdown does not know about that. In general, if you want to do something more complicated on the LaTeX side, there is a good chance that latexmk already knows how to do that. I am not sure if this is here the case, c.f. https://tex.stackexchange.com/questions/400325/latexmkrc-for-bib2gls. However, you can give it a try using

```{r echo=FALSE}
Sys.setenv(RSTUDIO_PDFLATEX = "latexmk")
```