作者:Yihui Xie
译者:郑宝童
日期:2021.05.14
1.5 Some tips
Typesetting under the paging constraint (e.g., for LaTeX/PDF output) can be an extremely tedious and time-consuming job. I’d recommend you not to look at your PDF output frequently, since most of the time you are very unlikely to be satisfied: text may overflow into the page margin, figures may float too far away, and so on. Do not try to make things look right immediately, because you may be disappointed over and over again as you keep on revising the book, and things may be messed up again even if you only made some minor changes (see http://bit.ly/tbrLtx for a nice illustration).
在分页约束下的排版(例如,LaTeX/PDF输出)可能是一项极其繁琐和耗时的工作。我建议您不要经常查看您的PDF输出,因为大多数时候您不太可能满意:文本可能溢出到页边距,数字可能浮动得太远,等等。不要试图让事情马上看起来正确,因为当你不断的修改书时你可能会一次又一次地失望,即使你只做了一些小的改变,事情可能再次混乱(见http://bit.ly/tbrLtx的一个很好的illustration)。
If you want to preview the book, preview the HTML output. Work on the PDF version after you have finished the content of the book, and are very sure no major revisions will be required.
如果您想预览这本书,请预览HTML输出。当你完成了书的内容后,你就可以完成PDF版本的工作了,并且你非常确定不需要进行重大的修改。
If certain code chunks in your R Markdown documents are time-consuming to run, you may cache them by adding the chunk option
cache = TRUE
in the chunk header, and you are recommended to label such code chunks as well, e.g.,
如果R Markdown文档中的某些代码块运行起来很耗时,你可以通过在块头中添加块选项cache = TRUE
来缓存它们,建议你为这些代码块添加标签,例如:
```{r important-computing, cache=TRUE}
In Chapter 5, we will talk about how to quickly preview a book as you edit . In short, you can use the preview_chapter()
function to render a single chapter instead of the whole book. The function serve_book()
makes it easy to live-preview HTML book pages: whenever you modify an Rmd file, the book can be recompiled and the browser can be automatically refreshed accordingly.
在第 5章中,我们将讨论如何在编辑时快速预览一本书。简而言之,您可以使用preview_chapter()
函数来呈现单个章节,而不是直接呈现整本书。 serve_book()
函数使得实时预览HTML图书页面变得很容易:每当您修改Rmd文件时,图书就会重新编译,浏览器也会相应地自动刷新。