Fail to create a pdf with chinese charactors in Rmarkdown

My code:

---
title: "中文/にほんご/韓國語"
author: "ME"
date: "2016年9月19日"
header-includes:
  - \usepackage{ctex}
output: 
  pdf_document:
    latex_engine: xelatex
---

中文

Error message I GOT:

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS a.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output a.tex --self-contained --highlight-style tango --pdf-engine xelatex --variable graphics --lua-filter "C:/R-4.0.1/library/rmarkdown/rmd/lua/pagebreak.lua" --lua-filter "C:/R-4.0.1/library/rmarkdown/rmd/lua/latex-div.lua" --include-in-header "C:\Users\CHINGC~1\AppData\Local\Temp\Rtmp8sfQ5G\rmarkdown-str376c2a7e1e35.html" --variable "geometry:margin=1in" 
output file: a.knit.md

! Undefined control sequence.
<argument> \__xeCJK_patch_microtype_get_slot: 

錯誤: LaTeX failed to compile a.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See a.log for more info.
停止執行

sessionInfo()
R version 4.0.1 (2020-06-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Traditional)_Taiwan.950 LC_CTYPE=Chinese (Traditional)_Taiwan.950
[3] LC_MONETARY=Chinese (Traditional)_Taiwan.950 LC_NUMERIC=C
[5] LC_TIME=Chinese (Traditional)_Taiwan.950
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.0.1 bookdown_0.20 htmltools_0.5.0 tools_4.0.1 yaml_2.2.1
[6] tinytex_0.24.1 remotes_2.1.1 rmarkdown_2.3 knitr_1.29 xfun_0.15
[11] digest_0.6.25 rlang_0.4.6 evaluate_0.14

Thanks for helping me!

I have also problems compiling your document.
Working with tinytex as you do some packages are installed but at last the compile fails with

! Package fontspec Error: The font "SimHei" cannot be found.
! kpathsea:make_tex: Invalid filename `KaiTi/OT:script=hani;language=dflt;', contains ':'
! kpathsea:make_tex: Invalid filename `KaiTi/B/OT:script=hani;language=dflt;', contains ':'
! kpathsea:make_tex: Invalid filename `SimHei/OT:script=hani;language=dflt;', contains ':'
! kpathsea:make_tex: Invalid filename `SimHei/I/OT:script=hani;language=dflt;', contains ':'
! kpathsea:make_tex: Invalid filename `SimHei/OT:script=hani;language=dflt;', contains ':'

Error: LaTeX failed to compile charliechen.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See charliechen.log for more info.
Execution halted

However skipping xelatex for the default engine pdflatex works for me:

output: 
  pdf_document: default

I do not know if you had a particular reason for chosing xelatex?

Update :

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

thanks! @HanOostdijk
I use xelatex since it could support the chinese charactors well.XeLaTeX and LuaTeX
I try to use pdf_document: default but it give me other error messages.

Error in eval(parse(text = name)) : 找不到物件(cannot found) 'default'
Calls: <Anonymous> ... create_output_format -> create_output_format_function -> eval -> eval
停止執行(stop)

However, I use other packages in tex which could work!

---
title: "test"
author: "ME"
date: "2020/5/5"
header-includes:
  - \usepackage{fontspec} # use fontspec package
  - \usepackage{xeCJK}    # use xeCJK package
  - \setCJKmainfont{標楷體} # font for windows
output: 
  pdf_document: 
    latex_engine: xelatex
---
中文
englsih

I am doubt that ctex is not match with tinytex well now :thinking:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.