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.
Related
I'm using RBookdown with multiple chapters such as this minimal example.
After successfully implementing the custom block instructions here everything looks great. The boxes appear in both html and pdf formats, as intended.
However, I am using color fonts across the document, and upon inclusion of the latex custom block preamble items.
\usepackage{tcolorbox}
\newtcolorbox{blackbox}{
colback=black,
colframe=orange,
coltext=white,
boxsep=5pt,
arc=4pt}
now the compile error appears as
Warning: Package xcolor Warning: Incompatible color definition on input line 215.
I see no problems with the colors, they are all working as intended. Similar for the custom blocks, they all appear fine. Unless anyone has a better suggestion, I will just ignore the xcolor warnings.
I found similar discussions here and here and here but I still haven't found any fix to the error messages.
Note: Color is implemented using the solution in previous post
UPDATE: To create MWE, use this minimal example
and edit the index.Rmd file to look as follows
---
title: "A Minimal Book Example"
author: "Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output:
bookdown::html_book
documentclass: book
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
github-repo: rstudio/bookdown-demo
description: "This is a minimal example of using the bookdown package to write a book. The output format for this example is bookdown::gitbook."
---
```{r echo=FALSE}
colorize <- function(x, color) {
if (knitr::is_latex_output()) {
sprintf("\\textcolor{%s}{%s}", color, x)
} else if (knitr::is_html_output()) {
sprintf("<span style='color: %s;'>%s</span>",
color,
x)
} else x
}
```
# Prerequisites
This is a _sample_ book written in **Markdown**. You can use anything that Pandoc's Markdown supports, e.g., a math equation $a^2 + b^2 = c^2$. This is a _sample_ book written in **Markdown** with `r colorize("desired brown text", "brown")` which appears as intended.
Then also edit the preamble.tex file to include the line below.
\usepackage{tcolorbox}
Then use R command
bookdown::render_book("index.Rmd", "bookdown::pdf_book")
to compile into pdf, and the described errors will appear.
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 :)
I'm confused as to why my R package's vignette is in HTML on CRAN and not a pdf.
I followed the advice at Enforce PDF package vignette with knitr and used
%\VignetteEngine{knitr::rmarkdown}
to generate the vignette, but there it is, a pdf. The full header of one of the files is
---
title: "wCorr Formulas"
author: "Paul Bailey, Ahmad Emad, Ting Zhang, Qingshu Xie"
date: '`r Sys.Date()`'
output:
pdf_document: default
vignette: |
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{wCorr Formulas}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
---
you can see the whole package at https://github.com/cran/wCorr or, before it gets built at https://github.com/ahmademad/wCorr
You are including copies of the HTML output (presumably from an earlier version) in inst/doc.
This might not have been intentional; I believe devtools::build_vignettes might do it to work around a bug in R: https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17416. But there are better workarounds, e.g. described here: https://github.com/yihui/knitr/issues/1540 .
I'm trying to build a book with R/bookdown and I'm facing a problem when producing a html version using tufte_html_book or html_book:
Error in split_chapters(output, page_builder, number_sections, split_by, :
The document must start with a first (#) or second level (##) heading
The book is correctly produced in gitbook or tufte_book2 output.
The document has four files index.Rmd, 01-Chap1.Rmd, 02-Chap2.Rmd, 03-Chap3.Rmd. I like to keep things clear, so index.Rmd only contains the YAML headers, plus some R code but no heading, which is probably what yields the error. Is there a way to make the html outputs of bookdown behave similarly to gitbook or pdf output?
Here is a small reproducible example:
Index.Rmd:
---
title: "Tufte Handout"
subtitle: "An implementation in R Markdown"
author: "JJ Allaire and Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output:
bookdown::tufte_html_book:
toc: yes
bookdown::tufte_book2:
toc: yes
---
```{r setup1, include=FALSE}
library(tufte)
# invalidate cache when the tufte version changes
knitr::opts_chunk$set(tidy = FALSE, cache.extra =
packageVersion('tufte'))
options(htmltools.dir.version = FALSE)
```
01-Chap1.Rmd
# Introduction
The Tufte handout style is a style that Edward Tufte uses in his books and handouts. Tufte's style is known for its extensive use of sidenotes, tight integration of graphics with text, and well-set typography. This style has been implemented in LaTeX and HTML/CSS^[See Github repositories [tufte-latex](https://github.com/tufte-latex/tufte-latex) and [tufte-css](https://github.com/edwardtufte/tufte-css)], respectively. We have ported both implementations into the [**tufte** package](https://github.com/rstudio/tufte). If you want LaTeX/PDF output, you may use the `tufte_handout` format for handouts, and `tufte_book` for books.
For HTML output, use `tufte_html`. These formats can be either specified in the YAML metadata at the beginning of an R Markdown document (see an example below), or passed to the `rmarkdown::render()` function. See #R-rmarkdown more information about **rmarkdown**.
I'm answering my own question.
The difference in behaviour between gitbook and (tufte_)html_book is in the split_by argument, which is split_by="chapter" in gitbook and split_by="section" in (tufte_)html_book. Adding split_by: chapter to the bookdown::tufte_html_book: yaml section allows to build the html without error.
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.