我原本以为三天能解决的问题,最终花了两整周时间,这就是理想和现实的差距。其实这里面花的暗时间更多,这两周用了好多我以前积攒的经验,要是没有这些年踩坑的经验,恐怕两个月都搞不定。

dapengde 投向 Linux 要慎重。建议还是先用虚拟机玩一年再说,看适不适应。Linux 对 R 用户来说最大的不便就是有些包需要从源码编译,得寻找相应的头文件包(什么 libcurl4-dev 之类的),这个有点烦。对普通用户来说,Linux 娱乐功能可能差一点。我已经退出这个江湖四年,但就 R 包开发者而言,Linux 应该比 Windows 还是方便更多,macOS 本质是 Unix,所以对开发者来说也不错,就是贵,而且被苹果的屏幕惯坏眼睛之后,看别的电脑屏幕总觉得线条不够清晰。

    fedora 27,今天测试报错

    错误: Functions that produce HTML output found in document targeting latex output.
    Please change the output type of this document to HTML. Alternatively, you can allow
    HTML output in non-HTML formats by adding this option to the YAML front-matter of
    your rmarkdown file:
    always_allow_html: yes
    Note however that the HTML output will not be visible in non-HTML formats.
    
    停止执行

    但我的头文件是这样的

    output:
      pdf_document:
        latex_engine: xelatex
    documentclass: ctexart

    所以这个
    always_allow_html: yes 怎么换成 no

      lovebluesky 错误消息说你的 R Markdown 文档中包含 HTML 元素。在 PDF 输出中是不能有 HTML 元素的。

        yihui 明白了,大概因为我这两天正在弄 leaflet吧,但是还有报错:

         !LaTeX Error: File `ctexart.cls' not found.
        
        Type X to quit or <RETURN> to proceed,
        or enter new name. (Default extension: cls)
        
        Enter file name: 
        ! Emergency stop.
        <read *> 
                 
        l.2 \usepackage
        
        pandoc: Error producing PDF
        错误: pandoc document conversion failed with error 43
        停止执行
        
        > library(tinytex)
        > tlmgr_search('ctexart.cls')
        tlmgr search --file --global 'ctexart.cls'
        sh: tlmgr: 未找到命令
        Warning message:
        In tlmgr(c("search", if (file) "--file", if (all) "--all", if (global) "--global",  :
          TeX Live does not seem to be installed. See https://yihui.name/tinytex/.
        > tlmgr_install('ctex')
        tlmgr install ctex
        sh: tlmgr: 未找到命令
        tlmgr path add
        sh: tlmgr: 未找到命令
        Warning messages:
        1: In tlmgr(c("install", pkgs), usermode) :
          TeX Live does not seem to be installed. See https://yihui.name/tinytex/.
        2: In tlmgr(c("path", match.arg(action))) :
          TeX Live does not seem to be installed. See https://yihui.name/tinytex/.

          yihui 我已经按照你中文文档安装过了,并且没报错,所以很奇怪为什么没有安装,而且我 'library(tinytex)' 并没有报错,是不是说明我已经安装好了tinytex了?回家再重新安装一下看看吧。

            lovebluesky 你有没有运行过 tinytex::install_tinytex() 来安装 TinyTex? tinytex 的 r 包是安装 TinyTex 这个 tex 发行版的必要不充分条件

              yufree 这个印象里是直接从谢老大的中文文档里复制运行过了,但既然你的回复谢老大都点赞了,那基本可以确定是我漏掉了,sorry,我只是比较喜欢 Rmarkdown 编辑文档的方式,但很多东西都不太懂,给大家添麻烦了,感谢回复。

                lovebluesky
                还是命名的问题造成误解,全小写的tinytex是你装的r package, TinyTeX这种坑坑洼洼佶屈聱牙一波未平一波又起的名字指的是latex库。

                话说是不是可以把这个库塞进r包里,就像rstudio自带pandoc一样。

                  tctcab 我之所以不想打包,就是因为 LaTeX 世界的许可证实在是很奇葩,我没见过哪个别的社区的开源许可证如此模糊。参见 FAQ 2:https://yihui.name/tinytex/faq/ TeX Live 自己的许可证说不清,CTAN 上的包也不能保证全部免费开源,加上 LaTeX 社区还有自己独特的 LPPL:https://www.latex-project.org/lppl/ 所以我只敢提供安装脚本。

                  在安装 TeX 包的过程中,运行很久(如下),我估计主要是网速问题,以前使用 TeXlive 或 MikTeX 时候,都自己先设定就近的仓库,如 <https://mirrors.tuna.tsinghua.edu.cn/CTAN/>,再安装都是很快的,在 tinytex 包中是否实现了这个?

                  library(tinytex)
                  tlmgr_search('/framed.sty')  # search for framed.sty
                  tlmgr_install('framed')

                    Cloud2016 暂时没有实现,不过这是个好想法。安装 TinyTeX 之前应该让用户能自己选择一个镜像。

                    既然你已经安装完了,你可以事后设定 CTAN 镜像,比如:

                    tinytex::tlmgr(
                      c('option', 'repository', 'https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/tlnet')
                    )

                    在这之后再安装包就会快很多了。

                      yihui 那就先玩虚拟机。我眼睛不知是有啥毛病,盯苹果的显示屏反而受不了。

                      参考文献问题,我装了 devtools::install_github(('rstudio/rmarkdown@feature/tinytex')),但只要在index.Rmd 的 yaml 声明里带扩展名如bibliography: [book.bib],就会出问题:用 bookdown + CTeX 编译出来的pdf里参考文献是问号。只要改成 bibliography: [book] 就好了。

                      不过,既然没有别人反馈这个问题,那说不定是我电脑有啥毛病。我懒得理了,反正快换电脑了。

                        dapengde CTeX 和 TinyTeX 二者如果都安装了,那么只能有一者在 PATH 环境变量上。你可以检查一下 Sys.getenv('PATH')。如果你只安装了 CTeX 而没装 TinyTeX 而跑不出参考文献来,那么这问题就诡异了,因为我无法重现,你只能自己排错(例如 debug(tinytex::: tweak_aux) 然后在交互式环境下跑 tinytex::latexmk()),相关的扩展名自动处理在这一行:

                        https://github.com/yihui/tinytex/blob/ad2e0fa6b/R/latex.R#L161

                        Cloud2016 注意我上面用的是 HTTP 链接,如果要用 HTTPS,需要有 gpg 支持,参见 FAQ 12

                          yihui 移动 TinyTeX 位置,找不到字体了

                          • 将 TinyTeX 默认存放位置 %APPDATA%\TinyTeX 移动到D盘,即 D:\TinyTeX,然后执行
                            "D:\TinyTeX\bin\win32\tlmgr" path add

                          • 安装几个常用字体 tinytex::tlmgr_install(c('sourcesanspro','sourcecodepro','sourceserifpro'))

                          • fc-cache -f -v 刷新字体缓存,问题是缓存不到 D:\TinyTeX\texmf-dist\fonts 目录下的字体,以前使用 TeXLive 没这问题,我知道有个笨办法,挨个找到字体文件,手动安装到 C:\Windows\Fonts,有没有好点的办法?

                          PS: 将目录 D:\TinyTeX\texmf-dist\fonts 添加到当前用户的 Path 路径上也不管用

                          fc-cache -f -v
                          Note that it needs some time to create caches,
                          especially if there are many large font files.
                          Wait with patience.
                          
                          C:/Windows/fonts: caching, new cache contents: 850 fonts, 0 dirs
                          C:/Users/XiangYun/AppData/Local/Temp/RtmpkNFfPn/install-tl-20171205/TinyTeX/texmf-dist/fonts/opentype: skipping, no such directory
                          C:/Users/XiangYun/AppData/Local/Temp/RtmpkNFfPn/install-tl-20171205/TinyTeX/texmf-dist/fonts/truetype: skipping, no such directory
                          D:/TinyTeX/texmf-var/fonts/cache: cleaning cache directory
                          fc-cache: succeeded

                            yihui 没有起作用,还是扫的 C:/Users/XiangYun/AppData/Local/ 目录,如上

                              yihui 1. 但是 fc-list :lang=en-us | sort > D:/en.txt 保存的 txt 文件里还是找不到我安装的字体,也就没法在文中调用\setmainfont{Source Sans Pro}

                              1. 关于参考文献的引用,我发现tinytex::latexmk('manual.tex', engine = 'xelatex', bib_engine = 'bibtex')并未达到下面依次执行的效果
                              • xelatex manual.tex
                              • bibtex manual 注意不是 bibtex manual.tex
                              • xelatex manual.tex
                              • xelatex manual.tex

                              manual.tex 文件 下载