Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF 编译错误 #81

Open
qiushiyan opened this issue Oct 26, 2022 · 2 comments
Open

PDF 编译错误 #81

qiushiyan opened this issue Oct 26, 2022 · 2 comments

Comments

@qiushiyan
Copy link
Collaborator

qiushiyan commented Oct 26, 2022

我对 latex 排错能力有限,先把我碰到过的错误贴上来。

第一个错误是 bookdown.post.latex 里面的这一行

x = x[-unlist(mapply(seq, i1, i2, SIMPLIFY = FALSE))]

报错信息是

 Error in seq.default(dots[[1L]][[5L]], dots[[2L]][[5L]]) : 
  'to' must be a finite number 
10.
stop("'to' must be a finite number") 
9.
seq.default(dots[[1L]][[5L]], dots[[2L]][[5L]]) 
8.
(function (...) 
UseMethod("seq"))(dots[[1L]][[5L]], dots[[2L]][[5L]]) 
7.
mapply(seq, i1, i2, SIMPLIFY = FALSE) at <text>#29
6.
unlist(mapply(seq, i1, i2, SIMPLIFY = FALSE)) at <text>#29
5.
post(x) 
4.
output_format$post_processor(front_matter, input, output_file, 
    clean, !quiet) 
3.
rmarkdown::render(main, output_format, ..., clean = clean, envir = envir) 
2.
render_cur_session(files, main, config, output_format, clean, 
    envir, ...) 
1.
bookdown::render_book("index.Rmd", "bookdown::pdf_book") 

估计这里是前面的 i1 和 i2 出现了 Inf,这一行注释掉后可以消除错误。

第二错误是两张图片

https://github.com/cosname/rmarkdown-guide/blob/master/01-intro.Rmd#L139-L143

https://github.com/cosname/rmarkdown-guide/blob/master/03-document.Rmd#L170-L174

这两个图的 fig.cap 都是用了 (ref:label) 语法,错误是一样的,例如第二个图生成的 tex

\begin{figure}

{\centering \includegraphics{examples/first-rmd-theme-darkly} 

}

\caption{应用 \href{https://bootswatch.com/3/darkly}{darkly} 主题后的文档样式}\label{fig:first-rmd-theme-darkly}
\end{figure}

报错 log 是

! Argument of \@tempf has an extra }.
<inserted text> 
                \par 

把它们都改成行内 fig.cap 可以解决这个问题

第三个错误我没有找到具体的报错位置,错误信息是

! Undefined control sequence.
<argument> @{} >{\raggedright \arraybackslash 
                                              }p{(\columnwidth - 2\tabcolsep...
l.967 ...width - 2\tabcolsep) * \real{0.7639}}@{}}

log 文件是

https://gist.github.com/qiushiyan/2956afa6c2cbd2892c955d962ccfbfe1

此外 #80 还会带来一个新错误

Error running filter /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua:
.../Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua:52: attempt to index a nil value (field 'integer index')
stack traceback:
Error: pandoc document conversion failed with error 83

可能有关 https://community.rstudio.com/t/pandoc-document-conversion-failed-with-error-83/138962

@rucwyf
Copy link
Collaborator

rucwyf commented Dec 19, 2022

我暂时修好了pdf这个问题,具体而言:

  • 对于第一个错误,我先给注释掉了

  • 对于第二个错误,我改了一下叙述方式

  • 第三个错误我这里没有报错

  • 关于 #80 带来的错误:第2章和第6章有一些下面这样的代码,删去即可解决这个错误,输出也没有变化(可以检查一下)。

::: {.col data-latex="{0.05\textwidth}"}

:::
  • 我还发现没法编译第二章的![R logo](https://www.r-project.org/Rlogo.png),我把它换成了
```{r echo = FALSE, fig.cap="Rlogo"}
knitr::include_graphics("images/Rlogo.png", dpi = NA)
```
  • 对于pdf无法输出动图,我把第二章动画部分的代码改成了
```{r, animation.hook="gifski", echo = FALSE}
if (knitr::is_html_output()){
  for (i in 1:2) {
    pie(c(i %% 2, 6), col = c("red", "yellow"), labels = NA)
  }
}
```
  • 另外,第二章表格部分的代码在pdf里会报错
| 元素   | Markdown        |
|--------|-----------------|
| 块引用 | `> some quotes` |
| 代码块 | `some code`     |
\toprule ->\noalign 
                    {\ifnum 0=`}\fi \@aboverulesep =\abovetopsep \global \@b...
l.1468 \toprule
               () 

好像 bookdown 输出pdf时只能用 knitr::kable() 来输出,我就调整了一下,顺便改了一些这里的例子,不然还要处理“```"会变成中文引号的问题。第三章也有两个地方有相应的问题,我都改了。

  • Asymptote 部分的图像输出有问题,我看 R Markdown Cookbook 也有这个问题,我先把这部分删去了,如果后续有需要还可以从old文件夹里复制。

@icejean
Copy link

icejean commented Dec 23, 2022

如果出版社要求PDF排版就要PDF编译通过,如果出版社要求Word排版那就可以只是Word编译通过。8-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants