Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bookdown converting chapters to sections

Tags:

r

latex

bookdown

I have a book that compiles fine to html but the pdf version has no chapters. For example, the command

# Introduction {#intro-intro}

is translated to

\hypertarget{intro-intro}{%
\section{Introduction}\label{intro-intro}}

(No such issues with the gitbook format)

<EDIT>

I have # Preface {-} at the top of Index.Rmd and \mainmatter at the end. Perhaps it is not getting out of the preface? Roman numerals change back to non-roman at # Introduction.

</EDIT>

My Index.Rmd has

---
documentclass: krantz
classoption: numberinsequence
bibliography: [book.bib]
biblio-style: apalike
link-citations: yes
colorlinks: yes
graphics: yes
---

_bookdown.yml is

new_session: yes    
output_dir: working_files
clean: [bookdown.bbl]
language:
  label:
    fig: "Fig. "
    tab: "Table "

and _output.yml is

  bookdown::gitbook:
    css: css/style.css
    dev: svglite

  bookdown::pdf_book:
    includes:
      in_header: latex_extras/preamble.tex
      before_body: latex_extras/before_body.tex
      after_body: latex_extras/after_body.tex
    keep_tex: yes
    dev: "cairo_pdf"
    latex_engine: pdflatex
    citation_package: natbib
    template: null
    toc_unnumbered: no
    toc_appendix: yes
    quote_footer: ["\\VA{", "}{}"]

and finally

  > session_info()
  ─ Session info ───────────────────────────────────────────────────────────────
  setting  value                       
  version  R version 3.4.3 (2017-11-30)
  os       macOS High Sierra 10.13.3   
  system   x86_64, darwin15.6.0        
  ui       X11                         
  language (EN)                        
  collate  en_US.UTF-8                 
  tz       America/New_York            
  date     2018-03-09                  

  ─ Packages ───────────────────────────────────────────────────────────────────
  package     * version date       source         
  backports     1.1.2   2017-12-13 CRAN (R 3.4.3) 
  bookdown    * 0.7     2018-02-18 CRAN (R 3.4.3) 
  clisymbols    1.2.0   2017-05-21 CRAN (R 3.4.0) 
  digest        0.6.15  2018-01-28 cran (@0.6.15) 
  evaluate      0.10.1  2017-06-24 CRAN (R 3.4.1) 
  htmltools     0.3.6   2017-04-28 CRAN (R 3.4.0) 
  knitr         1.20    2018-02-20 CRAN (R 3.4.3) 
  magrittr      1.5     2014-11-22 CRAN (R 3.4.0) 
  Rcpp          0.12.15 2018-01-20 cran (@0.12.15)
  rmarkdown   * 1.8     2017-11-17 CRAN (R 3.4.2) 
  rprojroot     1.3-2   2018-01-03 cran (@1.3-2)  
  sessioninfo * 1.0.0   2017-06-21 CRAN (R 3.4.1) 
  stringi       1.1.6   2017-11-17 CRAN (R 3.4.2) 
  stringr       1.3.0   2018-02-19 CRAN (R 3.4.3) 
  withr         2.1.1   2017-12-19 CRAN (R 3.4.3) 
  xfun          0.1     2018-01-22 cran (@0.1)    
like image 827
topepo Avatar asked Nov 07 '22 09:11

topepo


1 Answers

Pandoc converts # to \section{} by default (not strictly true, but see Pandoc's manual for details). To let it know that you want chapters, you have to use the argument --top-level-division (example here).

like image 165
Yihui Xie Avatar answered Nov 15 '22 07:11

Yihui Xie