I use the HTML and PDF outputs from bookdown as instructional material in a programming course, and I'd like to achieve the "page break" effect at the subsection level in addition to the chapter and section levels.
From what I have read in the bookdown documentation, "subsection" is not a permissible setting for the split_by argument in my bookdown's "_output.yaml" file.
bookdown::gitbook:
split_by: section
Is there a workaround besides creating individual books for each chapter (thus turning my current book-level subsections into chapter-level sections)? I strongly prefer having one book at the end.
A work around might be using "split_by: rmd"; see this answer for reference.
Then you put contents in each subsection into a separate Rmd file.
I tried this, and it works. The drawback is that I always receive this message when preview the book in Rstudio:
In split_chapters(output, gitbook_page, number_sections, split_by, :
You have 5 Rmd input file(s) but only 3 first-level heading(s). Did
you forget first-level headings in certain Rmd files?
Also, I don't know if there are other drawbacks.
Related
I am about to give up on LaTex through Rmarkdown. I mean honestly what is the point when it is just a constant stream of errors that take an hour to solve. Anyway, the last thing that I need to solve is the bibliography. It does not appear, no matter what I do. I am not sure what esoteric knowledge is required to make this work but simply following instructions through Bookdown is apparently not enough. My header is set up like so:
output:
pdf_document:
toc: true
toc_depth: 3
citation_package: biblatex
bibliography: zika.bib
And the final section I am outputting is as follows:
# References
nocite: |
#*
When I do this, I get "References" in my table of contents in a weird location.
And I also get the default references shown instead of the references in my bib as well as an additional references section with the #* parameter.
I am trying to just cite all bib references for now as a test and I will add in a few more once I get that working. I will probably just cite all at the end instead of referencing throughout, although I tried in-text citations and they were not added to the references section at the end either. I have tried dozens of different ways of writing this out in the YAML header as well as changing the nocite call at the end. I often have the problem shown here, or no references and no errors or I commonly get an error saying that the bibliography cannot be built from either biblatex or biber. I'm not sure what causes one or the other as it seems to be random. I'm guessing that my .bib is somehow not being linked to the .rmd, but I'm not sure what I need to do to change this. I've tried relative and absolute paths, but this produces one of the issues I mention above. Does anyone know what I might be missing?
I guess my question is a potential if not probable duplicate of How to use inline R code in a bookdown theorem or example environment. It's been nearly 3 years since this question was asked, so a refresh might be welcome in any case, all the more given #YiHui's comment: "That is not possible with bookdown (at least for now)"?
Background: I am trying to use #YiHui bookdown package to produce a book with lecture slides (see creating accompanying slides for bookdown project). A key feature for this purpose is to be able to use conditional formatting, such as eval = (out_type=="beamer"). The issue I am facing is therefore to be able to add code chunks or inline R code inside bookdown custom environments (see https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#theorems and https://bookdown.org/yihui/bookdown/custom-blocks.html). I would love to get the following to compile properly. Is there a solution? Would a hook work (see https://yihui.org/knitr/hooks/)? There is a hack that works for forcing pandoc to parse inside a latex environment, but i do no think it applies here. Would a lua filter work (I have no idea how to use this)?
En passant, I am also surprised to see $\digamma$ showing up properly in the html output, but not in the pdf output, though it is parsed correctly in the tex file. The amssymb package is loaded and it's supposedly defined in there - what am I missing?
Much appreciated any help on this. Here is a MWE - I just edited chapter 4 from the default bookdown project. You can simply replace the contents of the file 03-method.Rmd with the following:
# Methods
We describe our methods in this chapter.
So here is a theorem to prove 1+1 = `r 1+1`.
```{theorem, echo=TRUE}
we want to show that in R, 1+1 = 2.
We also wonder why `$\digamma$` ($\digamma$) not showing.
Shows in the html output only, not pdf.
But when I recompile the tex file produced by bookdown - shows up just fine!!
Indeed, is defined correctly from `\usepackage{amssymb}`.
```
```{proof, echo=TRUE}
- If I am not mistaken, I cannot get an Rmarkdown style list to work either in the proof environment.
- Well, this is where i would like to be able to use inline code.
- we use r to compute 1+1: `r 1+1`.
- Does not work.
- Just shows verbatim inline code.
```
With the current development version of bookdown:
remotes::install_github('rstudio/bookdown')
you can write theorems in Pandoc's fenced Divs, e.g.,
# Methods
We describe our methods in this chapter.
So here is a theorem to prove 1+1 = `r 1+1`.
::: {.theorem}
we want to show that in R, 1+1 = 2.
We also wonder why `$\digamma$` ($\digamma$) not showing.
Shows in the html output only, not pdf.
But when I recompile the tex file produced by bookdown - shows up just fine!!
Indeed, is defined correctly from `\usepackage{amssymb}`.
:::
::: {.proof}
- If I am not mistaken, I cannot get an Rmarkdown style list to work either in the proof environment.
- Well, this is where i would like to be able to use inline code.
- we use r to compute 1+1: `r 1+1`.
- Does not work.
- Just shows verbatim inline code.
:::
However, please note that this new syntax is not supported for beamer output yet.
I have a book I'm generating with bookdown where I want to conditionally include a section of a chapter only when publishing to html as the section has animations in it.
I can't find documentation on this.
Can someone please point me towards relevant doc?
If the section is in a separate file, you can use _bookdown.yml file in the book directory to specify which files to use and which order to compile them depending on rendering format.
rmd_files:
html: ["index.Rmd", "abstract.Rmd", "intro.Rmd"]
latex: ["abstract.Rmd", "intro.Rmd"]
(from Chapter 1.3 Usage of the bookdown manual)
I want to divide my Rmarkdown document like in picture. One column for the first section then two columns in the other sections.
used \onecolumn and \twocolumn but each section is created in a single page. Is there a solution to fix it?
This article has been published in a journal of the AMS. Fortunately, the rticle package supports the AMS journals. I use the standard template as generated by RStudio, change layout in the YAML header and use fancyhdr to redefine the pagestyle:
layout: twocol
header-includes:
- \usepackage{fancyhdr}
- '`\fancypagestyle{plain}{\fancyhf{}\fancyfoot[C]{\thepage}\renewcommand{\headrulewidth}{0pt}}`{=latex}'
I then get the following result:
As an alternative, you could try to adapt the revtex LaTeX class as used by the APS.
Note: I am using a quite recent version of pandoc, which makes the quoting of LaTeX complicated. With older versions of pandoc you might get away without the quoting.
I got 2 files from my university for writing thesis using LaTeX. One is a .sty file and other one is .TeX file. In order to work in R studio I've decided to have separate .Rnw files for each chapter and one file for combining all the chapters. I think .TeX file is the one where I can combine all the chapters because it gives sample chapters in output. On R studio's website there is a page titled as 'Working with Multiple Rnw Files' which describes this process (I guess) but is not clear to me. It talks about 'child' files which I think are the chapters in my case. So my simple question is that if I create different .Rnw files, one for each chapter, how can I ask R to combine them in one TeX file which university provided me? Please bear my ignorance as I am new to reproducible research stuff.
Assuming you're using knitr (and I highly recommend knitr over sweave) the simple way to do this is with the child chunk option.
As an example, say you had 2 chapters, kept in files chap1.Rnw and chap2.Rnw and a master document thesis.Rnw (with university style file called thesisStyle). You can put these all together, inside thesis.Rnw -- assuming these are all in the same directory -- via:
\documentclass{article}
\usepackage{thesisStyle}
\begin{document}
% "include" chapter 1
<<chap1, child='chapt1.Rnw'>>=
#
% again with chapter 2
<<chap2, child='chap2.Rnw'>>=
#
\end{document}
Then just have RStudio compile thesis.Rnw and it'll spit out thesis.tex which will have everything bundled together properly.
That's not all, though! You can develop chap1.Rnw without having to give it its own preamble. That is, if the content of chap1.Rnw is
<<echo=FALSE, cache=FALSE>>=
set_parent('thesis.Rnw')
#
\chapter{In a world where...}
\section{Great voice actors in movie trailer history}
ANYTHING YOU'D NORMALLY PUT IN AN .Rnw FILE
then you can compile chap1.Rnw like any regular .Rnw file and it'll take the preamble from thesis.Rnw before running whatever TeX backend you're using (normally pdflatex or xelatex). In particular, knitr will slap the \documentclass{article} and \usepackage{thesisStyle} lines at the top of chapt1.tex.
One word of caution, I've found the child-parent model in knitr to be white-space sensitive. So, be sure to have no space above the block
<<echo=FALSE, cache=FALSE>>=
set_parent('thesis.Rnw')
#
You have a couple of options.
One option is to just process each of your chapters by hand. You will have a .Rnw file for each chapter, then in Rstudio (or R) you run the knit function from the knitr package (there may be an Rstudio button or menu to do this directly) to convert your .Rnw file to a .tex file. Then in the parent LaTeX document you just use \include to include the .tex files for each chapter. This does mean processing each chapter yourself and having to go back and redo it anytime you change anything.
The other option is to create a parent and child documents that knitr will understand and process automatically for you (Rstudio is using knitr to do the processing to .tex and eventually .pdf files). This page has demonstrations on creating the parent and child documents this way, just modify the .tex file given to you to include the important things in the demos (and probably change the name to .Rnw). Make sure that the document class matches the .sty file given to you and the important options from the .tex file remain, but include the child documents as shown in the knitr demo. This way you can process the document as a whole rather than each individual chapter.