I am trying to write my PhD Thesis with bookdown and am mainly using pdf output. I have easily added a bibliography at the end of the document but would rather have a bibliography at the end of each chapter. I have tried adjusting the .tex output with LaTeX packages that allow this but this fights with the bookdoown defaults. Is there a way of adapting the .yaml options to enable this?
相关问题
- R - Quantstart: Testing Strategy on Multiple Equit
- Using predict with svyglm
- Reshape matrix by rows
- Extract P-Values from Dunnett Test into a Table by
- split data frame into two by column value [duplica
相关文章
- How to convert summary output to a data frame?
- How to plot smoother curves in R
- Paste all possible diagonals of an n*n matrix or d
- ess-rdired: I get this error “no ESS process is as
- How to use doMC under Windows or alternative paral
- dyLimit for limited time in Dygraphs
- Saving state of Shiny app to be restored later
- How to insert pictures into each individual bar in
For HTML output the default is to use per-chapter bibliographies. For PDF output, I have found it is best to use the LaTeX package
biblatex
together withbiber
. Since RStudio does not know about biber, it is best to install a tool likelatexmk
and configure RStudio to use that viaSys.setenv(RSTUDIO_PDFLATEX = "latexmk")
. These programs might have to be installed separately, e.g. on Debian/Ubuntu/...For configuring
biblatex
the solution provided at https://tex.stackexchange.com/questions/199336/biblatex-reference-both-by-chapter-and-at-the-end-of-the-book is appropriate.In the end the following settings are necessary in
_output.yml
:In
Index.Rmd
:At the end of every chapter:
There is no need to escape this raw LaTeX command, since
pandoc
ignores such commands for other output formats.One can see the entire solution at
Original solution
I managed to get chapter bibliographies with PDF output using the following steps:
<R-library-path>/rmarkdown/rmd/latex/default-1.17.0.2.tex
asbook.tex
to the working directorybook.tex
to use the LaTeX packagebibunits
(diff below)_output.yml
to refer tobook.tex
astemplate
(diff below)index.Rmd
(diff below)Rmd
files to write\putbib
command (diff below)After these changes, a PDF file could be produced, but all references where missing, since
bookdown
does not know about the generatedbu?.aux
files. After executingbibtex bu1
andbibtex bu2
, reproducing the PDF file viabookdown
produced a PDF with chapter bibliographies. It is probably best to automate this step with Makefile.Here the diff between the templates:
And the diff of the files from
bookdown-sample
:For a latex-specific solution see this post, i.e. use the
sectionbib
option fornatbib
and load thechapterbib
package. You will need to edit The bookdown template to set the required options fornatbib
and tell bookdown to use your custom template in the yaml. See this post for more info on the bookdown template.I swear I saw instructions in the bookdown docs for doing this with gitbook format, but I can't seem to find it...
EDIT I went and looked at an old bookdown project of mine. For
gitbook
output, you specify the following in_output.yml
:Which will (you guessed it) split the bibliography by chapter. I'm actually a bit surprised that bookdown doesn't support the equivalent options for
bookdown::pdf_book
yaml options, but should be easy enough to do by setting upsectionbib
/chapterbib
in the LaTeX preamble.