pzhaonet / bookdownplus

The easiest way to use R package bookdown for writing varied types of books and documents
MIT License
255 stars 32 forks source link

Template 5 官方中文模板 not working #38

Closed caimiao0714 closed 5 years ago

caimiao0714 commented 5 years ago

Hi Peng,

I tried generating a bookdownplus project using template 5 官方中文模板, but it seems not to work on my computer.

Here are my session information, my codes and the error messages:

> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] bookdownplus_1.5.5

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0        compiler_3.5.2    prettyunits_1.0.2 remotes_2.0.2    
 [5] tools_3.5.2       testthat_2.0.1    digest_0.6.18     packrat_0.5.0    
 [9] pkgbuild_1.0.2    pkgload_1.0.2     evaluate_0.12     memoise_1.1.0    
[13] rlang_0.3.0.1     cli_1.0.1         rstudioapi_0.8    curl_3.2         
[17] yaml_2.2.0        xfun_0.4          withr_2.1.2       stringr_1.3.1    
[21] knitr_1.21        desc_1.2.0        fs_1.2.6          devtools_2.0.1   
[25] rprojroot_1.3-2   glue_1.3.0        R6_2.3.0          processx_3.2.1   
[29] rmarkdown_1.11.3  bookdown_0.9      sessioninfo_1.1.1 callr_3.1.1      
[33] magrittr_1.5      backports_1.1.3   ps_1.3.0          htmltools_0.3.6  
[37] usethis_1.4.0     assertthat_0.2.0  stringi_1.2.4     crayon_1.3.4  
> devtools::install_github("pzhaonet/bookdownplus")
> require(bookdownplus)
> bookdownplus(template = template()[5])
template() is to be deprecated. Please use get_template().

processing file: demo_zh.Rmd
  |.......                                                          |  11%
   inline R code fragments

  |..............                                                   |  22%
label: unnamed-chunk-1
Quitting from lines 45-46 (demo_zh.Rmd) 
Error in dev.control(displaylist = if (record) "enable" else "inhibit") : 
  dev.control() called without an open graphics device
In addition: Warning message:
In (function (filename = if (onefile) "Rplots.pdf" else "Rplot%03d.pdf",  :
  failed to load cairo DLL

Please delete demo_zh.Rmd after you finish debugging the error.

Any thoughts?

pzhaonet commented 5 years ago

Thanks for your feedback. It seems a plotting function does not work lines 45-46 in demo_zh.Rmd. If you remove these lines from body.Rmd, maybe this error could be removed.

However, it cannot clear the problem. Maybe you could try other templates. I have no mac and I am unable to test.

caimiao0714 commented 5 years ago

Thanks Peng. That works for me!

caimiao0714 commented 5 years ago

Hi Peng,

Here is another problem I have tried for a few days but could not solve, but I think it should be fairly simple for you.

While using the Chinese template 5, the figure caption cannot correctly show up it includes Chinese characters (for example fig.cap='中文标题'). Here is what I get:

image image

I check the LaTeX source file and it is not coded correctly either: \textless{}U+4E2D\textgreater{}\textless{}U+6587\textgreater{}\textless{}U+6807\textgreater{}\textless{}U+9898\textgreater{}. My guess is that pandoc cannot recognize Chinese characters in RMarkdown chunk.

Is there any suggestions on getting round this problem?

Thank you!

pzhaonet commented 5 years ago

Try this in .Rmd:

(ref:fig-cn) 中文标题
```{r, fig.cap='(ref:fig-cn)'}
plot(cars)

See [Chapter 2.2.4 in the bookdown manual](https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#text-references).
caimiao0714 commented 5 years ago

Try this in .Rmd:

(ref:fig-cn) 中文标题
```{r, fig.cap='(ref:fig-cn)'}
plot(cars)

See [Chapter 2.2.4 in the bookdown manual](https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#text-references).

That works great! Thank you so much Peng!

image image