How to: A scenebreak in bookdown

Viewed 154

I'm trying to write a novel using bookdown: HTML, EPUB, as well as PDF (pdfLaTeX). I'm using the indent mode, so paragraphs begin with an indent. I have the following custom LaTeX command, called \scenebreak, which:

  1. Leaves an empty line between paragraphs when the scene changes within a chapter.
  2. Introduces a ding, if the scene break is at the end of a page, or the beginning of a page.
  3. Resets indent for the paragraph that follows the break (the paragraph that follows the break starts flush left).

Here's the LaTeX:

% scene breaks
\renewcommand{\pfbreakdisplay}{%
\scriptsize\ding{86}}
\newcommand{\scenebreak}{\pfbreak*\noindent}
\newcommand{\forceindent}{\leavevmode{\indent}}

When introducing the scenebreak in LaTeX, I call it so

Text here

\scenebreak

New scene begins here.

In HTML, this is how I've done it:

<div style='text-align:center;'>&#8226;</div>

I'm aware that a block in bookdown is like a LaTeX environment.

Is a similar setup possible with commands/macros?

1 Answers

I don't really understand your question, but if you are trying to write out different content depending on the different output format, here is what you could do:

```{r echo=FALSE}
knitr::asis_output(if (knitr:::is_latex_output()) {
  "\\scenebreak"
} else {
  "<div style='text-align:center;'>&#8226;</div>"
})
```

If you have to do this multiple times, create a function and call the function instead, e.g., insert this code chunk in the beginning of your book:

```{r, include=FALSE}
scenebreak = function() {
  knitr::asis_output(if (knitr:::is_latex_output()) {
    "\\scenebreak"
  } else {
    "<div style='text-align:center;'>&#8226;</div>"
  })
}
```

Then use the function scenebreak() where a break is needed:

```{r echo=FALSE}
scenebreak()
```
Related