0

I use bookdown to render html books. How can render the same book using LaTeX enging xelatex instead of pdflatex?

This is the main code I use:

bookdown::render_book('index.Rmd', output_file='mybook.pdf','bookdown::pdf_book')

It keeps on saying ! Sorry, but C:\PROGRA~1\MIKTEX~1.9\miktex\bin\x64\pdflatex.exe did not succeed.. Because when rendering other kinds of pdf documents I use xelatex as an enging, I know it should be available in my system. How can I force bookdown to use xelatex?

Here this answer seemed to be asked before, but I have no idea how to use the mentioned solution: pandoc_options(args = c("--latex-engine", "xelatex")).

When I do something like this:

bookdown::render_book('index.Rmd', output_file='mybook.pdf','bookdown::pdf_book',pandoc_options(latex_engine = 'xelatex'))

There is an error: Error in pandoc_options(latex_engine = "xelatex") : argument "to" is missing, with no default

Does anyone know how to deal with this problem?

rdatasculptor
  • 8,112
  • 14
  • 56
  • 81
  • As detailed [here](https://www.rdocumentation.org/packages/rmarkdown/versions/2.1/topics/pandoc_options), `pandoc_options` has an argument called `to` (I guess it is the name of the output but I may be wrong). You didn't specify this argument, hence the error. You can also specify the `latex_engine` in the YAML, as explained [here](https://bookdown.org/yihui/rmarkdown-cookbook/latex-variables.html) – bretauv Jul 06 '20 at 13:12
  • thanks for your response. I already tried that, but bookdown keeps on wanting to use pdflatex. – rdatasculptor Jul 06 '20 at 13:29
  • Did you check that the indentation was good in YAML? I was recently surprised with some YAML options not taken into account because indentation was bad – bretauv Jul 06 '20 at 13:34

1 Answers1

4

You can try to insert this into _output.yml general configuration file (for bookdown, as seen in the documentation):

bookdown::pdf_book:
  latex_engine: xelatex

This usually worked in my cases.

If you want to use pandoc_options(), you'll probably have to pass to argument as well (I haven't tried this):

bookdown::render_book(
  'index.Rmd',
  output_file = 'mybook.pdf',
  'bookdown::pdf_book',
  pandoc_options(
    to = "pdf",
    latex_engine = "xelatex"
  )
)