Bookdown in-chapter formatting: different pages per paragraph - r

We - bookdown noobs - are making a bookdown with a lot of text per paragraph (using the minimal bookdown as a template, we only added new Rmd files from here). At the moment, one has to scroll a long time before reaching the end of a chapter, because we have many paragraphs per chapter and all paragraphs are pasted on 1 page. In the bookdown example however, each paragraph appears on a separate page. I have looked in the code of the example and tried to copy some index code to ours, but that still pastes everything to one page when knitting to html.
How can we make sure each paragraph (e.g, 3.1, 3.2) appears on a separate page, instead of all paragraphs appearing on the same page (chapter 3 in its entirety)?
This is our index.Rmd code (don't know whether of any use):
site: bookdown::bookdown_site
documentclass: book
output:
bookdown::gitbook: default
R version 3.6.2 (2019-12-12); Bookdown version 0.18
Thanks very much in advance. I am a Latex/Pandoc noob so this may be a very stupid question.

Related

Hashtag appears in R Markdown html [duplicate]

Well, I've been working with Markdown for a year and today, suddenly, next to the headings an a tag has been automatically added.
Someone would know why these anchors have been generated automatically and how I could remove them?
Pd: one way to solve it is with h1,h2, etc., but then with the pdf output the index is eliminated, so it would not really solve the problem.
This is a new feature in rmarkdown 2.5.
You can change this in your YAML header at the top of your rmd file:
html_document:
anchor_sections: false

How to fix toggle sections issue in the toc of a bookdown?

After cloning the bookdown-demo. I want to use the toggle function of sections.
For this, I modified the file _output.yml adding the collapse line:
bookdown::gitbook:
config:
toc:
collapse: section
As shown in: bookdown manual
And added some sections in index.Rmd
# Prerequisites
## second
### third
After building the book in Rstudio, with:
bookdown::render_book("index.Rmd", "bookdown::gitbook")
It works with a little defect. When I click some chapter without sections, (and also sometimes the chapter with sections), there is a rapid movement of the menu as if it opens and immediately closes the sections of the (other) chapter with sections.
Does someone have a solution?
Possibly related issue: https://github.com/rstudio/bookdown/issues/556

Multiple headers/footers when using custom TeX in r bookdown

Loved bookdown. However, I'm porting my book from LaTeX into bookdown, and would like some help with headers/footers.
I have a custom code that generates headers and footers in my LaTeX:
% HEADER AND FOOTER MANIPULATION
% for normal pages
\nouppercaseheads
\headsep = 0.16in
\makepagestyle{mystyle}
\setlength{\headwidth}{\dimexpr\textwidth+\marginparsep+\marginparwidth\relax}
\makerunningwidth{mystyle}{\headwidth}
\makeevenhead{mystyle}{}{\textls[100]{\textsf{\small\scshape\thetitle}}}{}
\makeoddhead{mystyle}{}{\textls[100]{\textsf{\small\scshape\leftmark}}}{}
\makeevenfoot{mystyle}{}{\textls[100]{\textsf{\small\thepage}}}{}
\makeoddfoot{mystyle}{}{\textls[100]{\textsf{\small\thepage}}}{}
\clearmark{section} % removing section in the headers
\makeatletter
\makepsmarks{mystyle}{%
\createmark{chapter}{left}{nonumber}{\#chapapp\ }{.\ }}
\makeatother
% for pages where chapters begin
\makepagestyle{plain}
\makerunningwidth{plain}{\headwidth}
\makeevenfoot{plain}{}{}{}
\makeoddfoot{plain}{}{}{}
\pagestyle{mystyle}
% END HEADER AND FOOTER MANIPULATION
I placed my entire LaTeX preamble in preamble.tex (and I've not added content to the book just yet). It renders the following:
The render should actually look like this:
Also, here's what's in the YAML in index.Rmd.
documentclass: memoir
papersize: smalldemyvo
indent: yes
microtypeoptions:
- protrusion
- tracking
fontfamily: Alegreya
fontfamilyoptions:
- osf
fontsize: 11pt
output:
bookdown::pdf_book:
template: null
I'm new to bookdown, but I did read the documentation. I feel I need help with two things.
How do I remove the auto-generated headers and footers?
How do I make "Contents" disappear from the ToC table?
Thank you!
By default, bookdown uses some built-in template(s). If you need more adjustments, you could make your own .tex files (preamble.tex, before_body.tex, after_body.tex, template.tex) and specify them in the yaml part of index.Rmd like this:
bookdown::pdf_book:
includes:
in_header: preamble.tex
before_body: before_body.tex
after_body: after_body.tex
template: template.tex
bookdown merges preamble.tex, before_body.tex, and after_body.tex with the main body (marked as $body$ in template.tex) of your book into one .tex file in the structure under the control of template.tex, and compile it into a pdf book with pandoc and LaTex.
In your case, you have to insert your custom code into template.tex in the right way. #yihui's demo shows a good example.
For more examples to customize these .tex files, I would suggest that you could either look into the 'bookdownplus' package I developed, which gives you 19 examples showing how to tailor a LaTeX template into bookdown's frame, or read Chapter 8.3 Create Your Own Templates in the bookdownplus textbook.
Edited answer
bookdown has built-in templates (decided mostly by documentclass and/or Pandoc). Refer the Theming and Templates sections of bookdown documentation.
An example to learn from, as #pzhao suggested, is the template in the bookdown-chinese repo. Observe the variables that bring in data from the Rmd files. They're enclosed between $$, such as $body$. _output.yml has a reference to this template. This way, you override the default template, thereby eliminating duplicate headers/footers. Your LaTeX template decides what forms part of your headers/footers. An example is the LaTeX code in my question.
The appearance of Contents in the ToC table can also be controlled by tweaking your custom LaTeX template. I use the memoir class, and help to remove self-reference can be found here. My custom LaTeX template already took care of it, so it fixed itself as soon as I figured out how to use my custom template.

bookdown with specific latex template

I very much believe that Rmarkdown and bookdown are the future of content publishing, however some publishers use specific LaTeX templates, and in order to submit the manuscript they need it in that precise template.
For example, see this Springer manuscript template:
http://resource-cms.springer.com/springer-cms/rest/v1/content/20566/data/v3/monographs
Is it possible to make bookdown use this template in order to produce a PDF file?
EDIT: in this book (https://bookdown.org/yihui/bookdown/) on section 4.2 Theming I read it is indeed possible, but I might end up designing a "custom Pandoc LaTeX template".
I guess the question is now about how to design this Pandoc template, and section 4.3 provides some details about it.
You don't really have to use a custom Pandoc LaTeX template (of course you can if you want). Tweaking a few options and you will be done. I just put an example in the bookdown-demo repository. See this commit for what I changed, and see here for a PDF example.
You almost surely still have to tweak other things, one of which might be the index page. I also made an example for that.

In RStudio, making slide deck with RMarkdown, how can I easily change the theme?

I'm writing an .rmd file in RStudio, and using the Knit button to create a slide deck. I have two options, it appears, ioslides and slidy. I don't really like the default look-and-feel of either. (I think ioslides uses screen real estate inefficiently, and slidy feels like a graphic designer wasn't involved.)
I did a web search for alternative templates/styles/themes, and came upon pages like this gallery, but the tools there seem to be for use outside RStudio, as completely independent projects. In other words, they're not just themes for what I've got, but entirely other solutions that would change my workflow.
Is there a simple way to tell RStudio to use a different template/theme with either ioslides or slidy? For example, can I download a CSS file from somewhere, and point RStudio to it with the css: option in the yaml header of my .rmd file? If so, is there a gallery of such CSS templates?
Here's what I ended up doing. It's not as smooth as I'd like it to be, but it's decent. I'm glad to entertain better answers.
Download any of the style files linked to from this knitrBootstrap code into the same folder as your R Markdown file.
Edit it so that the URL at the start of the file begins with http: so that knitr knows not to look on your filesystem for the additional resources (fonts), but on the Web.
Edit it further to remove any pipes (|) in that URL, because knitr can't handle them (as far as I can tell). (Remove everything after the pipe, too.)
Edit it further to change everything of the form url('../fonts/***.eot'); to now instead be of the form url('https://netdna.boostrapcdn.com/bootswatch/3.0.0/fonts/***.eot');.
Link to it from your R Markdown file with the css: attribute in the YAML header.
Have you tried using the built in Bootswatch themes? They're fairly limited, but in doing so you can quickly customise many elements.
e.g
title: "Test"
author: "John"
date: "5 June 2017"
output:
slidy_presentation:
fig_width: 12.5
font_adjustment: -1
theme: readable
Other themes may be found here Bootswatch.
edit: removed a typo

Resources