ulyngs / oxforddown

Template for writing an Oxford University thesis in R Markdown; uses the OxThesis LaTeX template and was inspired by thesisdown.
https://ulyngs.github.io/oxforddown/
MIT License
221 stars 81 forks source link

`header-includes` works but `includes: in_header` does not #17

Closed shirdekel closed 3 years ago

shirdekel commented 3 years ago

I have a preamble.tex file with the following:

\usepackage{pdflscape}
\newcommand{\blandscape}{\begin{landscape}}
\newcommand{\elandscape}{\end{landscape}}

It gives me the ability to add landscape pages ad hoc in the document. However, running bookdown::render_book(output_format = "bookdown::pdf_book") in an oxforddown fork using the following doesn't work:

output:
  bookdown::pdf_book:
    includes:
      in_header: "preamble.tex"

I get the following error, which suggests that preamble.tex isn't being read.

! Undefined control sequence.
l.363 \blandscape

On the other hand, using the following works:

header-includes:
  - \usepackage{pdflscape}
  - \newcommand{\blandscape}{\begin{landscape}}
  - \newcommand{\elandscape}{\end{landscape}}

I'm guessing that the issue might have to do with something in template.tex because using includes: in_header works fine in bookdown-demo.

Do you have any idea what might be causing this before I do more digging?

Session info ``` r xfun::session_info("bookdown") R version 4.0.2 (2020-06-22) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Mojave 10.14.6 Locale: en_AU.UTF-8 / en_AU.UTF-8 / en_AU.UTF-8 / C / en_AU.UTF-8 / en_AU.UTF-8 Package version: base64enc_0.1.3 bookdown_0.21.7 digest_0.6.27 evaluate_0.14 glue_1.4.2 graphics_4.0.2 grDevices_4.0.2 highr_0.8 htmltools_0.5.1.1 jsonlite_1.7.2 knitr_1.31 magrittr_2.0.1 markdown_1.1 methods_4.0.2 mime_0.10 rlang_0.4.10 rmarkdown_2.7.4 stats_4.0.2 stringi_1.5.3 stringr_1.4.0 tinytex_0.30.2 tools_4.0.2 utils_4.0.2 xfun_0.22 yaml_2.2.1 ```
ulyngs commented 3 years ago

I think you're right that this is a templating thing - are you able to dig out the latex template that's used by bookdown-demo and see how

output:
  bookdown::pdf_book:
    includes:
      in_header: "preamble.tex"

gets included?

ulyngs commented 3 years ago

Solved - I just needed to added this to the templates

$for(header-includes)$
$header-includes$
$endfor$

This should have solved both use cases, i.e. header-includes and in_header. Can you check if it's working for you now if you fork the latest version?

shirdekel commented 3 years ago

Thanks for looking into it!

When running the current version, I get ! LaTeX Error: Unknown float option 'H'.

This is fixed when adding \usepackage{float}, which it looks like you removed with the other kableExtra packages.

Note also that I had to update kableExtra to 1.3.4.9000 in order for the tables to render properly (I forgot to check what version I had previously).

However, once those things are fixed, in_header now works for my preamble.tex 👍.

ulyngs commented 3 years ago

Thanks for this, I just added the float package back in!

For now, I still assume that there is no need to explicitly include the other kableExtra packages in the template anymore because they are automatically added to the preamble when using library(kableExtra) given the change in the templates (we'll see if this turns out to be a poor decision :zany_face: )