Not finding my bookdown bibliography file - r

My document is simply this
---
title: "The Visual Speech (VISP) Handbook"
author: "Fredrik Karlsson & Linda Sandström"
site: bookdown::bookdown_site
documentclass: book
output:
bibliography: references.bib
#bookdown::pdf_book: default
bookdown::gitbook: default
biblio-style: "apalike"
link-citations: true
---
# Preface {-}
[#R-base]
and I have a reference file:
> dir(pattern = "*.bib")
[1] "references.bib"
but I am unable to find this bib file when knitting the book:
Error in eval(parse(text = name)) : object 'references.bib' not found
Calls: ... create_output_format ->
create_output_format_function -> eval -> eval Please delete _main.Rmd
after you finish debugging the error. Execution halted
Any ideas on how to set this up properly (in Rstudio)
Thanks!
Fredrik

It's just a location problem in the code (see more information here).
You could try:
---
title: "The Visual Speech (VISP) Handbook"
author: "Fredrik Karlsson & Linda Sandström"
site: bookdown::bookdown_site
documentclass: book
output:
#bookdown::pdf_book: default
bookdown::gitbook: default
bibliography: references.bib
biblio-style: "apalike"
link-citations: true
---
# Preface {-}
[#R-base]

Related

"sort&compress" and "nocite" do not work for latex-pdf in rmarkdown

My pure-latex demo.tex is as follows:
\documentclass{article}
\usepackage[hidelinks]{hyperref}
\usepackage[numbers,super,square,sort&compress]{natbib}
\begin{document}
statistics \cite{anderson2003introduction,efron2004least,hastie2009elements}
\bibliographystyle{unsrtnat}
\nocite{*}
\bibliography{ref}
\addcontentsline{toc}{section}{References}
\end{document}
and it works well, where ref.bib contains
#Book{anderson2003introduction,
author = {Anderson, Theodore Wilbur},
publisher = {Wiley},
title = {An introduction to multivariate statistical analysis},
year = {2003},
address = {New Jersey},
edition = {3},
}
#Article{efron2004least,
author = {Efron, Bradley and Hastie, Trevor and Johnstone, Iain and Tibshirani, Robert},
title = {Least angle regression},
journal = {The Annals of Statistics},
year = {2004},
volume = {32},
number = {2},
pages = {407--499},
}
#Book{hastie2009elements,
author = {Hastie, Trevor and Tibshirani, Robert and Friedman, Jerome},
publisher = {Springer},
title = {The elements of statistical learning: {Data} mining, inference, and prediction},
year = {2009},
address = {New York},
edition = {2},
}
#Book{fan2020statistical,
author = {Fan, Jianqing and Li, Runze and Zhang, Cun-Hui and Zou, Hui},
publisher = {CRC},
title = {Statistical foundations of data science},
year = {2020},
address = {Boca Raton},
}
I want to translate demo.tex to the rmarkdown file tex2rmd.rmd and I try
---
output:
pdf_document:
keep_tex: yes
citation_package: natbib
natbiboptions: "numbers,super,square,sort&compress"
# natbiboptions: "numbers,super,square" #test
biblio-style: unsrtnat
nocite: '#*'
bibliography: ref.bib
link-citations: yes
colorlinks: no
---
statistics [#anderson2003introduction; #efron2004least; #hastie2009elements]
# References
which gives errors like
! Missing \endcsname inserted.
<to be read again>
\&
l.351 \newcommand
\NAT#aysep{,} \newcommand\NAT#yrsep{,}
Then I check the tex2rmd.tex file from the keep_tex: yes functionality, and I find the problem happens at
\usepackage[numbers,super,square,sort\&compress]{natbib}
where there is sort\&compress instead of sort&compress. How can I fix this?
Moreover, I use natbiboptions: "numbers,super,square" instead for test purpose and find the nocite: '#*' does't work either (it should show all 4 items other than the cited 3 items). Do I ignore something?
Replacing the & from sort&compress with , solves the issue of sort&compress.
And it seems the nocite YAML key doesn't work when you use natbib or biblatex as the citation package. Because nocite key is used by pandoc-citeproc filter, but when natbib or biblatex is used as citation method (default is citeproc), pandoc-citeproc is not used then and nocite doesn't work as well.
In that case, you need to use the raw LaTeX command \nocite (as explained here)
---
output:
pdf_document:
keep_tex: yes
citation_package: natbib
natbiboptions: "numbers,super,square,sort,compress"
biblio-style: unsrtnat
bibliography: ref.bib
link-citations: yes
colorlinks: no
---
\nocite{*}
statistics [#anderson2003introduction; #efron2004least; #hastie2009elements]
# References
To avoid all the problems with rmarkdown parsing and give you much more freedom, you can directly use the latex code in rmarkdown:
---
output:
pdf_document:
keep_tex: yes
link-citations: yes
colorlinks: no
header-includes:
- \usepackage[numbers,super,square,sort&compress]{natbib}
---
\nocite{*}
statistics \cite{anderson2003introduction,efron2004least,hastie2009elements}
# References
\bibliographystyle{unsrtnat}
\bibliography{ref}

Using custom LaTeX class changes numbering in R Markdown

I recently discovered that you can include your own LaTeX class in an R-Markdown doc to change the appearance of the PDF. Here is a minimal example:
R Markdown
---
title: "Test"
date: "`r format(Sys.time(), '%d %B, %Y')`"
documentclass: book
output:
pdf_document:
citation_package: natbib
toc: yes
toc_depth: 3
number_sections: true
fontsize: 12pt
---
# A
## AA
### AAA
### AAA
## AB
# B
This works as intended.
But when I define my own class, the numbering is preceded by 0s and the page numbering is off.
myclass.cls
I place a file called "myclass.cls" in the same direcoty as the RMD file above and change documentclass: myclass:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{glasgowthesis}
\LoadClass{book}
My understanding is that this should simply call the same class as above but the file now looks like this:
Maybe somebody can give me a hint what I'm doing wrong. I would like to copy the book class 1:1 before starting to change things.
I found the solution in the bookdown book and wanted to share it in case anyone wanders off to this question through google etc.
Note that when you change documentclass, you are likely to specify an
additional Pandoc argument --top-level-division=chapter so that Pandoc
knows the first-level headers should be treated as chapters instead of
sections (this is the default when documentclass is book)
So this YAML header solved the issue:
---
title: "Test"
date: "`r format(Sys.time(), '%d %B, %Y')`"
documentclass: myclass
output:
pdf_document:
pandoc_args: --top-level-division=chapter
citation_package: natbib
toc: yes
toc_depth: 3
number_sections: true
fontsize: 12pt
---
# A
## AA
### AAA
### AAA
## AB
# B

rticles and rmarkdown not removing table of contents

I cannot seem to remove the table of contents from my RMarkdown pdf document. I have tried a number of different things such as.
Changing toc: no to false
using differrent base_format: rticles::ieee_article artiles from the getNamespaceExports("rticles").
removing csl: elsevier-harvard.csl
Nothing seems to work and everytime I compile the table of contents appears - what am I missing?
Markdown:
---
title: some title
author:
- name: some name
email: some email
affiliation: some department
footnote: some footnote
- name: some name
email: some email
affiliation: some department
footnote: 2
footnote:
- code: 1
text: "Corresponding Author"
- code: 2
text: "Corresponding Author"
abstract: |
some abstract here
journal: "An awesome journal"
date: "`r Sys.Date()`"
bibliography: mybibfile.bib
#linenumbers: true
#numbersections: true
csl: elsevier-harvard.csl
output:
bookdown::pdf_document2:
base_format: rticles::ieee_article
number_sections: no
toc: no
tables: true
header-includes:
- \usepackage{floatrow}
- \floatplacement{figure}{H}
- \usepackage{booktabs}
- \usepackage{array}
---
Try to format your output section of the YAML header as follows:
output:
bookdown::pdf_document2:
number_sections: no
toc: no
tables: true
base_format: rticles::ieee_article
Then the TOC should disappear. I hope that the base_format argument will be taken into consideration. Please try and report.

LuaLaTex and _output.yml configuration - Error in base format()

I am learning how to use bookdown package and right now I am practicing with Yihui Xie minimal example. In my test I want a gitbook and a pdf output.
What I would like to do is to specifying some options for pdf output with LuaLaTeX engine. So if I do something like that :
bookdown::gitbook:
css: style.css
config:
toc:
before: |
<li>A Minimal Book Example</li>
after: |
<li>Published with bookdown</li>
download: ["pdf", "epub"]
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: lualatex
fontsize: 12pt
citation_package: natbib
keep_tex: yes
bookdown::epub_book: default
I have this error when I try to build the book :
Error in base_format(toc = toc, number_sections = number_sections, fig_caption = fig_caption, :
unused argument (fontsize = "12pt")
Calls: <Anonymous> ... <Anonymous> -> create_output_format -> do.call -> <Anonymous>
Execution stoped
Exited with status 1.
If I put fontsize: 12pt in the YAML header of the index.Rmd, I don't have this error. If I use bookdown::pdf_document2: I don't have this error either.
I really don't know what I am missing here... Should I place LaTeX configuration options only in the YAML header of my index.Rmdfile ?

remove facebook and twitter links in `bookdown` in R, Rmarkdown

I am using the bookdown package in R to write a gitbook, but I don't want the final book to have the sharing links to facebook, twitter. I am using something like this in the YAML
---
title: "A Minimal Book Example"
author: "SN"
date: "`r Sys.Date()`"
output:
bookdown::gitbook
gitbook_config:
sharing:
facebook: false
twitter: false
documentclass: book
link-citations: yes
description: "This book ... ."
---
but I am getting an error
Error in yaml::yaml.load(enc2utf8(string), ...) :
Scanner error: mapping values are not allowed in this context at line 6, column 19
Calls: <Anonymous> ... yaml_load_utf8 -> mark_utf8 -> <Anonymous> -> .Call
Execution halted
Can anyone help me in setting options in YAML so that no sharing options show up in the final rendering?
thanks!
SN
Two mistakes:
You omitted a colon after bookdown::gitbook;
gitbook_config should be config.
---
title: "A Minimal Book Example"
author: "SN"
date: "`r Sys.Date()`"
output:
bookdown::gitbook:
config:
sharing:
facebook: false
twitter: false
documentclass: book
link-citations: yes
description: "This book ... ."
---

Resources