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)
Related
I have multiple chapters in their own Rmd files and _bookdown.yml and _output.yml files which builds a book as expected. I am writing a thesis and some of these chapters include YAML headers which should render them independently as articles for particular journals. However I can't find a way to make bookdown honour these header blocks while the book's _bookdown.yml and _output.yml files are around. gitbook::render_chapter() does not do this.
So, how can we tell bookdown to ignore the _bookdown.yml and _output.yml files and instead render a chapter using its own YAML header?
A solution is to create a _bookdown_mychapter.yml file particularly for each chapter that needs to be built as an article. In here include rmd_files: ["mychapter.Rmd"] to tell bookdown to include only the single chapter. Then use
bookdown::render_book("mychapter.Rmd", config_file = "_bookdown_mychapter.yml")
to specify that this YAML file should be used instead of the default _bookdown.yml.
I'm writing a document in rmarkdown with the thesisdown template.
Related to the issue thesisdown-41: how can I add a new language for highlighting which is currently not supported?
The project mentioned in the link is derived from bookdown
Under the hood bookdown uses pandoc for tranforming markdown to HTML/PDF/.... From pandoc's manual at http://pandoc.org/MANUAL.html#syntax-highlighting we get:
The library used for highlighting is skylighting.
The list of available languages can be retrieved with pandoc --list-highlight-languages
Slightly off topic, but I just worked out how to do this in RMarkdown rather than Bookdown. I suspect you'll need this and maybe a little more.
Passing extra arguments to Pandoc via the YAML front-matter:
output:
html_document:
highlight: haddock
pandoc_args: ["--syntax-definition", "cobol.xml"]
Obtain the XML syntax definition file from somewhere (or create it). I got my COBOL one from:
wget http://kde.6490.n7.nabble.com/attachment/1163657/0/cobol.xml.gz
The syntax of the highliting file is as used by the Kate project in KDE.
Obtain the pre-req language.dtd file, this is some deep dependency with pandoc.
wget https://raw.githubusercontent.com/jgm/highlighting-kate/master/xml/language.dtd
If've just added the two files to my git repo, plus the YAML lines to my RMarkdown, and everything then worked on other developers machines.
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.
I am trying to write my paper and using Elsevier document class as a Rnw document. I also tried to use rticle package which I find little difficult to customise. Is it possible to include Rmd file in my Rnw document so that I can use the Rnw frame and also use my Rmd chapters for other purposes like comple it to HTML.
As suggested by r2evans, I want to post what I have found as an answer to my own question. It is not a direct answer to my question but I will be following this for now. Instead of using Rnw file, Rmd file can use tex template. The process is described in this site.
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.