how to include an abstract in a rmakdown Rmd file - r

In a .Rmd file with the header below, I want to include an abstract, so I tried the standard LateX article form,
\abstract{This paper explores a variety of topics related to the question of testing the equality of
covariance matrices in multivariate linear models, particularly in the MANOVA setting.
The main focus is on graphical methods that can be used to understand features of data related
to this question.}
But, surprisingly (I know this seems weird), the references in my References section become badly formatted -- no spacing between references, odd indentations. So, how can I include something that looks like an abstract?
My YAML header is:
---
title: "Notes on Testing Equality of Covariance Matrices"
author: "Michael Friendly"
date: '`r format(Sys.time(), "%B %d, %Y")`'
output:
pdf_document:
fig_caption: yes
keep_tex: yes
number_sections: yes
includes:
in_header: mystyles.tex
csl: apa.csl
bibliography:
- "C:/Users/friendly/Dropbox/localtexmf/bibtex/bib/statistics.bib"
- "C:/Users/friendly/Dropbox/localtexmf/bibtex/bib/graphics.bib"
---
Edit: Thinking this over, the problem may be that pandoc-citeproc is somehow confused by something done by using \abstract{} in the document.

The rmarkdown package now allows for including an abstract in your YAML. Like so:
abstract: "This is my abstract."
See this blog post for an example.

Related

R Bookdown: Append chapter without re-rending whole book

I am rather experienced with R but new to markdown and especially bookdown. I wonder how to render a single chapter and merge it with the existing book without re-building the whole book. The reason why I am asking is that I am creating a book that contains parameterised chapters and each chapter runs very long (1-2 hours). All in all, it will be hundreds of chapters with the same analysis, but different input data and would time-wise add up. I am aware of the knit-and-merge approach, in fact, that's the reason why I chose bookdown, but somehow it is not working as expected.
I am honestly also a little bit confused by the different rendering possibilities. There is the built-book button, the knit button, serve_book(), render_book(), preview_chapter(), ... I figured that one should avoid using the knit button in bookdown and that serve_book() will automatically compile changes. My approach so far is entering serve_book() into console, where it renders the whole book, then I create a new chapter, hit save and it runs the chunks of only that chapter (exactly what I want!) and the single HTML file of the new chapter appears. However, it doesn't show them when I look at the book via the index.html file.
I am only interested in an HTML book and do not need any other output formats.
In order to recreate the problem, I am just using the bookdown example and adding chapters to it.
_bookdown.yaml
book_filename: "book_name"
new_session: yes #true
before_chapter_script: _common.R
delete_merged_file: true
language:
ui:
chapter_name: "Chapter "
_output.html
bookdown::bs4_book:
css: style.css
theme:
primary: "#10395B"
#repo: https://github.com/rstudio/bookdown-demo
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
bookdown::epub_book: default
_index.yaml
---
title: |
![](./Logo_PureGene.png){width=200px}|
|-|
||
author: "Name"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
#output: bookdown::bs4_book
documentclass: book
bibliography: [book.bib, packages.bib]
# url: your book url like https://bookdown.org/yihui/bookdown
# cover-image: path to the social sharing image like images/cover.jpg
description: |
This is a minimal example of using the bookdown package to write a book.
The HTML output format for this example is bookdown::bs4_book,
set in the _output.yml file.
biblio-style: apalike
csl: chicago-fullnote-bibliography.csl
---
# About {-}
I would appreciate any help!
Thanks in advance :)

Using Unicode characters in math mode with Bookdown (xelatex)

I try to use a Unicode character (U+2685) in math mode with Bookdown, I set mathfont: STIX Two Math (which contains this character), yet the resulting PDF contains an empty space. (At the same time the HTML is correct.)
What's wrong here?
(My best guess is that I should perhaps use the unicode-math package. Unfortunately I can't include it in the preamble.tex as it is incompatible with the mathspec, but at the same time I see no way to get rid of mathspec; it seems to be hardcoded in Bookdown that mathspec is usepackaged when xelatex is used.)
Minimal reproducible example (showing index.Rmd, all other file is the same as with the default new project created with RStudio):
---
title: "A Minimal Book Example"
author: "Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
link-citations: yes
description: "This is a minimal example of using the bookdown package to write a book. The output format for this example is bookdown::gitbook."
mainfont: STIX Two Math
mathfont: STIX Two Math
---
# Prerequisites
In text: ⚀.
In math mode: $⚀$.
This is how the result looks like:
This issue is now solved (after an update to rmarkdown), see here.

R markdown / bookdown - how to switch to rticles?

Input data
I prepared an example Rmd file with references to figure, table and equation, setting as an output 'bookdown::pdf_document2'. It compiles without errors to PDF.
I placed it on dropbox:
https://www.dropbox.com/sh/zmu0a4wq95ywssv/AAD-nHlkDiLknLk2NVR4Xup3a?dl=0
Question
Now I wish to set as an output format 'rticles::elsevier_article'
How can I do that?
Issue
When I change output line from:
bookdown::pdf_document2
to
rticles::elsevier_article
I'm receiving an error message.
Even if I remove other parameters from output:
I still receive an error message:
! Undefined control sequence.
Accented characters when input "as is" do not appear to behave well with elsevier_article. See suggestions below.
Bare-bones document
Here is a bare-bones document using rticles::elsevier_article:
---
title: "Sample document"
author:
- name: "Mateusz Kędzior"
affiliation: Some Institute of Technology
email: Mateusz#example.com
footnote: Corresponding Author
- name: Żąćł Źęń
csl: https://www.zotero.org/styles/geoderma
output:
rticles::elsevier_article:
citation_package: natbib
keep_tex: yes
number_sections: yes
toc: no
keywords: keywordA, keywordB
abstract: This is a sample abstract \newline This is the second line of abstract.
---
Hello world.
which renders with no complaints:
Reference with accents
Now, we wish to add a reference with accents. We follow the answer here: https://tex.stackexchange.com/questions/57743/how-to-write-%C3%A4-and-other-umlauts-and-accented-letters-in-bibliography. I imported your bibliography into Zotero, and then exported the item with a "Central European (ISO)" encoding (not UTF-8) to obtain
#article{kedzior_this_2018,
title = {This is sample title only {\k A} {\L }},
volume = {99},
url = {http://megooglethat.com/},
journal = {Some journal},
author = {K{\k e}dzior, Mateusz and {\'Z}{\k e}{\'n}, {\.Z}{\k a}{\'c}{\l }},
year = {2018},
keywords = {keywordC},
pages = {21 -- 31}
}
The R Markdown document now becomes
---
title: "Sample document"
author:
- name: "Mateusz Kędzior"
affiliation: Some Institute of Technology
email: Mateusz#example.com
footnote: Corresponding Author
- name: Żąćł Źęń
csl: https://www.zotero.org/styles/geoderma
output:
rticles::elsevier_article:
citation_package: natbib
keep_tex: yes
number_sections: yes
toc: no
biblio-files: bibliography2.bib
keywords: keywordA, keywordB
abstract: This is a sample abstract \newline This is the second line of abstract.
---
## Citations and references
Let me cite an article: [#kedzior_this_2018]
# References
I then knited this in RStudio, but realised that I had to get the tex output and rebuild it (outside of RStudio) to get the desired output
Other problems
For accented characters in figure captions, encode them accordingly (as with the bibliography). You may find http://w2.syronex.com/jmr/latex-symbols-converter helpful. In addition, to the best of my knowledge bookdown style cross-referencing does not work with rticles. If you have follow-up questions, you may get more helpful answers if you break your question down into smaller chunks.
I've added a bit of updated material to the commenthttps://github.com/rstudio/rticles/issues/92#issuecomment-402784283 where it states (may be updated):
output:
bookdown::pdf_document2:
base_format: rticles::elsevier_article
number_sections: yes
such that the way I've had this work is using pdf_book versus pdf_document2:
output:
bookdown::pdf_book:
base_format: rticles::elsevier_article
number_sections: yes
This allows for figure and table referencing within an rticles document.

References Truncated in Beamer Presentation prepared in Knitr/RMarkdown

I'm currently preparing a presentation in RStudio (using RMarkdown and Knitr, outputting to a Beamer presentation) that has quite a few references.
I'm using a pretty typical YAML header:
---
title: "Title"
author: "Me"
date: "February 27th, 2016"
output:
beamer_presentation
csl: ../../apa.csl
bibliography: ../../RefenceDesk.bib
---
This presentation compiles and the references appear as they should, but unfortunately they all appear on one slide (and actually run off the page). Is there any way to have the references appear on multiple slides?
{.allowframebreaks} is the solution for multislides bibliographies in beamer. It works out of the box with regular pandoc templates (see my previous answer). However, knitr has a setting that prevents it, by redefining \widowpenalties in its beamer template. You can verify that if you examine the .tex file with keep_tex: true.
In my opinion, this is a bug. A quick fix would be to reset \widowpenalties to its default value. It can be done in your yaml front matter:
---
title: Title
header-includes:
- \widowpenalties 1 150
output:
beamer_presentation
---
Then, you can indicate the reference section as such:
## References {.allowframebreaks}
As #David above said in the comments:
For me it didnt work with ## References {.allowframebreaks} but it worked out with # References {.allowframebreaks}.
I would like to point out that, apparently for the reference slide to work you have to create a last slide with the same heading level es set by slide_level: __ at the YAML section.
So, the user should set one of the following:
# References {.allowframebreaks}. for those using slide_level: 1, OR
## References {.allowframebreaks}. for those using slide_level: 2, OR
### References {.allowframebreaks}. for those using slide_level: 3 and so on...
While this goes outside of using the regular pandoc citation template, I have found another approach that can be used to put the references across slides but it relies on the natbib citation package.
In the YAML front matter, I added:
---
title: "Title"
output:
beamer_presentation:
citation_package: natbib
bibliography: ../../RefenceDesk.bib
biblio-style: "apalike"
---
The reference slide does not get a title and I cannot seem to adjust the font size (by using a \scriptsize at the end of the .Rmd file), but at least they appear coherently.
EDIT: For parsimony, I removed the csl: ../../apa.csl line, since natbib does not require it.

How to insert appendix after references in Rmd using Rstudio?

I am using Rstudio, to create a pdf / html document from an Rmd file. The header looks sth like this:
title: "Title"
author: "Me"
date: "`r format(Sys.time(), '%B %d, %Y')`"
bibliography: bibliography.bib
output:
html_document:
toc: true
number_sections: true
Now, I have some sections, and then include the references. After that, an appendix should follow, but I encounter the exact same problem as described here: Pandoc insert appendix after bibliography
There is a fixed solution in this thread, but I have no idea how I can do that within RStudio directly. To get the document, I just press the "Knit html" button, and do not run any pandoc commands myself. So where should I put the
--include-after-body
part, and how should the appendix rmd file look like?
As noted in the rmarkdown manual, you could use this syntax:
---
output:
html_document:
includes:
after_body: appendix.md
---
This is equivalent to the general way to add arbitrary pandoc arguments to a Rmd file:
---
output:
html_document:
pandoc_args: ["--include-after-body=appendix.md"]
---
The following might be easier; works if you knit to PDF, Word or HTML:
Everything I wanted to say in the main document.
# References
<div id="refs"></div>
\newpage
# Appendix
Some details that will bore the readers of the main document.
In the original post, this was also posted as an answer (few years after current question was asked): see https://stackoverflow.com/a/44294306/8234333 and https://stackoverflow.com/a/16428699/8234333

Resources