TransWikia.com

Compressing in-line references with natbib and bookdown

TeX - LaTeX Asked by Haakonkas on December 25, 2020

I am using bookdown to generate a pdf book with natbib, and as of now the in-line references look like this:

[118,119,120,121,142]

However, I would like them to compress to:

[118 - 121,142]

I use the following in my preamble:

usepackage{natbib}
setcitestyle{square,comma,numbers}

I have tried the following:

  • biboptions{sort&compress} in preamble, as described here, this throws the error undefined control sequence
  • setcitestyle{square,comma,numbers,sort&compress} in preamble, as described here, this does not change the in-line citations at all, same with PassOptionsToPackage{square,comma,numbers,sort&compress}{natbib} as described in the same post
  • setcitestyle{numbers,sort&compress} alone, to see if something was messing it up

I use a slightly modified version of plainnat.bst, where I have only changed the article and misc function to exclude URLs etc. Otherwise it is completely similar to plainnat.bst.

In my YAML in the index.Rmd file i have specified the following:

date: "`r Sys.Date()`"
site: bookdown::bookdown_site
geometry: "left=4cm,right=3cm,top=3cm,bottom=3cm"
subparagraph: true
output:
  bookdown::pdf_book:
    latex_engine: xelatex
    fig_caption: yes
    toc: false
    citation_package: natbib
    includes:
      before_body: frontpage.tex
      after_body: after_body.tex
      in_header: preamble.tex
fontsize: 11pt
linestretch: 1.2
documentclass: book
bibliography: [packages.bib, library.bib]
biblio-style: [plainnatnew.bst]
link-citations: yes

Any ideas on how to get the compressed numbers?

Working example:

.bib file

@article{OBrien2011,
  title = {Effect of Diet and Gut Dynamics on the Establishment and Persistence of {{Escherichia}} Coli},
  volume = {157},
  issn = {1350-0872},
  number = {5},
  journal = {Microbiology},
  doi = {10.1099/mic.0.047092-0},
  url = {http://mic.microbiologyresearch.org/content/journal/micro/10.1099/mic.0.047092-0},
  author = {O'Brien, Claire L. and Gordon, David M.},
  month = may,
  year = {2011},
  pages = {1375--1384}
}

@article{Fabrega2009,
  title = {Mechanism of Action of and Resistance to Quinolones},
  volume = {2},
  issn = {17517907},
  number = {1},
  journal = {Microbial Biotechnology},
  doi = {10.1111/j.1751-7915.2008.00063.x},
  url = {http://doi.wiley.com/10.1111/j.1751-7915.2008.00063.x},
  author = {F{`a}brega, Anna and Madurga, Sergi and Giralt, Ernest and Vila, Jordi},
  month = jan,
  year = {2009},
  pages = {40--61}
}

@article{Chung2002,
  title = {Overexpression of the {{Escherichia}} Coli {{sugE}} Gene Confers Resistance to a Narrow Range of Quaternary Ammonium Compounds},
  volume = {184},
  number = {9},
  journal = {Journal of Bacteriology},
  url = {http://www.ncbi.nlm.nih.gov/pubmed/11948170},
  author = {Chung, Y J and Saier Jr., M H},
  year = {2002},
  pages = {2543--2545},
  pmid = {11948170}
}

@article{Dierikx2013a,
  title = {Presence of {{ESBL}}/{{AmpC}} -{{Producing Escherichia}} Coli in the {{Broiler Production Pyramid}}: {{A Descriptive Study}}},
  volume = {8},
  language = {English},
  number = {11},
  journal = {PloS One},
  doi = {ARTN e79005 DOI 10.1371/journal.pone.0079005},
  author = {Dierikx, C M and {van der Goot}, J A and Smith, H E and Kant, A and Mevius, D J},
  year = {2013},
  keywords = {antimicrobial agents,chickens,enterobacteriaceae,epidemiology,humans,impact,poultry,resistance,spectrum-beta-lactamase,transmission},
  pages = {e79005}
}

@article{Blaak2015,
  title = {Distribution, {{Numbers}}, and {{Diversity}} of {{ESBL}}-{{Producing E}}. Coli in the {{Poultry Farm Environment}}},
  volume = {10},,
  number = {8},
  journal = {PloS One},
  doi = {10.1371/journal.pone.0135402},
  url = {http://www.ncbi.nlm.nih.gov/pubmed/26270644},
  author = {Blaak, H and {van Hoek}, A H and Hamidjaja, R A and {van der Plaats}, R Q and {Kerkhof-de Heer}, L and {de Roda Husman}, A M and Schets, F M},
  year = {2015},
  pages = {e0135402},
  pmid = {26270644}
}

@article{Kingsford2010,
  title = {Assembly Complexity of Prokaryotic Genomes Using Short Reads},
  volume = {11},
  issn = {1471-2105},
  number = {1},
  journal = {BMC Bioinformatics},
  doi = {10.1186/1471-2105-11-21},
  url = {https://bmcbioinformatics.biomedcentral.com/articles/10.1186/1471-2105-11-21},
  author = {Kingsford, Carl and Schatz, Michael C. and Pop, Mihai},
  month = dec,
  year = {2010},
  pages = {21}
}

Lorem ipsum [@OBrien2011;Fabrega2009;Chung2002;Dierikx2013a;Kingsford2010]

One Answer

Try

documentclass[12pt,a4paper]{article}
usepackage[sort&compress,numbers]{natbib}
usepackage{filecontents}
begin{filecontents}{jobname.bib}
@article{OBrien2011,
  title = {Effect of Diet and Gut Dynamics on the Establishment and Persistence of {{Escherichia}} Coli},
  volume = {157},
  issn = {1350-0872},
  number = {5},
  journal = {Microbiology},
  doi = {10.1099/mic.0.047092-0},
  url = {http://mic.microbiologyresearch.org/content/journal/micro/10.1099/mic.0.047092-0},
  author = {O'Brien, Claire L. and Gordon, David M.},
  month = may,
  year = {2011},
  pages = {1375--1384}
}

@article{Fabrega2009,
  title = {Mechanism of Action of and Resistance to Quinolones},
  volume = {2},
  issn = {17517907},
  number = {1},
  journal = {Microbial Biotechnology},
  doi = {10.1111/j.1751-7915.2008.00063.x},
  url = {http://doi.wiley.com/10.1111/j.1751-7915.2008.00063.x},
  author = {F{`a}brega, Anna and Madurga, Sergi and Giralt, Ernest and Vila, Jordi},
  month = jan,
  year = {2009},
  pages = {40--61}
}

@article{Chung2002,
  title = {Overexpression of the {{Escherichia}} Coli {{sugE}} Gene Confers Resistance to a Narrow Range of Quaternary Ammonium Compounds},
  volume = {184},
  number = {9},
  journal = {Journal of Bacteriology},
  url = {http://www.ncbi.nlm.nih.gov/pubmed/11948170},
  author = {Chung, Y J and Saier Jr., M H},
  year = {2002},
  pages = {2543--2545},
  pmid = {11948170}
}
end{filecontents}
begin{document}

citep{Chung2002,Fabrega2009,OBrien2011}

bibliographystyle{plainnat}
bibliography{jobname}
end{document}

You will obtain

enter image description here

Answered by Denis on December 25, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP