yihui 我接触CentOS的时间也比较短,很多问题搞不清楚状况,比如如何安装 tlmgr,我甚至找不到 ctex 包 (如果不用 texlive 全家桶),中文字体更是个老大难的问题,写中文文档的初步探索结果见 rmd文件

BTW,我很看好rocker项目 <https://github.com/rocker-org/rocker/>,但是 eddelbuettel 对是否用 tlmgr 代替那一坨 texlive-*包不太感兴趣 #266 ,好像宁愿多花4个G,我总觉得Docker 太大不是件好事,可能外国人不用中文,关系不太大,我用VBox打包了一个虚拟机镜像放在百度云,分享链接: https://pan.baidu.com/s/1nv67anJ 密码: v3mr,用账户 cloud2016 密码 cloud登陆即可使用,功能上和rocker/tidyverse 差不多 <https://hub.docker.com/r/rocker/tidyverse/>

    yihui 我重试过几次,一样的报错,另外,忘记讲了,看了一下 Cloud2016 的问题我才记起来,我 fedora 虽然是前一段时间新安装的,没有主动安装过 texlive,但在安装某些东西的时候也安装了一些 texlive 的东西,具体是什么我也记不清了,不知有没有关系。

      Cloud2016 那为啥还用 CentOS 呢?

      eddelbuettel 大人很瞧不起我的工作,对 Debian 有强烈的信仰,认为无知的我在重造无谓的轮子,不过他理不理解这件事我懒得操心,能有一部分群众觉得好就好了。Docker 要是太大,对我来说就失去了它最大的优势之一(轻便)。

      lovebluesky 我也不确定。如我前面所说,我对 CentOS 不熟,无法帮你,不行你就只能继续仰仗你的系统提供的那一大坨 TeX Live 包了。我只能帮 Debian/Ubuntu 用户。

        yihui 觉得从 Ubuntu 过来,学起来应该不难。上面报告的错误只需安装 perl-Digest-MD5 即可

        yum install perl-Digest-MD5

        最新报告

        > tinytex::install_tinytex()
        
        试开URL’https://github.com/yihui/tinytex/raw/master/tools/install-unx.sh'
        Content type 'text/plain; charset=utf-8' length 758 bytes
        ==================================================
        downloaded 758 bytes
        
        Downloading install-tl-unx.tar.gz to /tmp ...
        --2017-12-19 10:20:16--  http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
        正在解析主机 mirror.ctan.org (mirror.ctan.org)... 176.28.54.184, 2a01:488:67:1000:b01c:36b8:0:1
        正在连接 mirror.ctan.org (mirror.ctan.org)|176.28.54.184|:80... 已连接。
        已发出 HTTP 请求,正在等待回应... 302 Found
        位置:http://10.101.10.10/files/21100000016597FC/mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz [跟随至新的 URL]
        --2017-12-19 10:20:16--  http://10.101.10.10/files/21100000016597FC/mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
        正在连接 10.101.10.10:80... 已连接。
        已发出 HTTP 请求,正在等待回应... 200 OK
        长度:4031443 (3.8M) [application/octet-stream]
        正在保存至: “install-tl-unx.tar.gz”
        
             0K .......... .......... .......... .......... ..........  1% 7.06M 1s
            50K .......... .......... .......... .......... ..........  2% 11.7M 0s
           100K .......... .......... .......... .......... ..........  3% 10.0M 0s
           150K .......... .......... .......... .......... ..........  5% 12.5M 0s
           200K .......... .......... .......... .......... ..........  6% 8.79M 0s
           250K .......... .......... .......... .......... ..........  7% 12.6M 0s
           300K .......... .......... .......... .......... ..........  8% 12.3M 0s
           350K .......... .......... .......... .......... .......... 10% 7.80M 0s
           400K .......... .......... .......... .......... .......... 11% 20.7M 0s
           450K .......... .......... .......... .......... .......... 12% 10.2M 0s
           500K .......... .......... .......... .......... .......... 13% 12.7M 0s
           550K .......... .......... .......... .......... .......... 15% 10.8M 0s
           600K .......... .......... .......... .......... .......... 16% 11.9M 0s
           650K .......... .......... .......... .......... .......... 17% 11.3M 0s
           700K .......... .......... .......... .......... .......... 19% 7.47M 0s
           750K .......... .......... .......... .......... .......... 20% 23.8M 0s
           800K .......... .......... .......... .......... .......... 21% 8.34M 0s
           850K .......... .......... .......... .......... .......... 22% 16.7M 0s
           900K .......... .......... .......... .......... .......... 24% 9.79M 0s
           950K .......... .......... .......... .......... .......... 25% 13.1M 0s
          1000K .......... .......... .......... .......... .......... 26% 11.2M 0s
          1050K .......... .......... .......... .......... .......... 27% 11.2M 0s
          1100K .......... .......... .......... .......... .......... 29% 11.3M 0s
          1150K .......... .......... .......... .......... .......... 30% 7.44M 0s
          1200K .......... .......... .......... .......... .......... 31% 22.3M 0s
          1250K .......... .......... .......... .......... .......... 33% 8.52M 0s
          1300K .......... .......... .......... .......... .......... 34% 16.4M 0s
          1350K .......... .......... .......... .......... .......... 35% 8.33M 0s
          1400K .......... .......... .......... .......... .......... 36% 11.5M 0s
          1450K .......... .......... .......... .......... .......... 38% 10.6M 0s
          1500K .......... .......... .......... .......... .......... 39% 10.6M 0s
          1550K .......... .......... .......... .......... .......... 40% 11.2M 0s
          1600K .......... .......... .......... .......... .......... 41% 7.56M 0s
          1650K .......... .......... .......... .......... .......... 43% 23.2M 0s
          1700K .......... .......... .......... .......... .......... 44% 8.41M 0s
          1750K .......... .......... .......... .......... .......... 45% 16.2M 0s
          1800K .......... .......... .......... .......... .......... 46% 10.1M 0s
          1850K .......... .......... .......... .......... .......... 48% 12.8M 0s
          1900K .......... .......... .......... .......... .......... 49% 11.2M 0s
          1950K .......... .......... .......... .......... .......... 50% 11.5M 0s
          2000K .......... .......... .......... .......... .......... 52% 11.2M 0s
          2050K .......... .......... .......... .......... .......... 53% 7.40M 0s
          2100K .......... .......... .......... .......... .......... 54% 24.9M 0s
          2150K .......... .......... .......... .......... .......... 55% 8.21M 0s
          2200K .......... .......... .......... .......... .......... 57% 18.5M 0s
          2250K .......... .......... .......... .......... .......... 58% 9.29M 0s
          2300K .......... .......... .......... .......... .......... 59% 13.3M 0s
          2350K .......... .......... .......... .......... .......... 60% 10.7M 0s
          2400K .......... .......... .......... .......... .......... 62% 11.8M 0s
          2450K .......... .......... .......... .......... .......... 63% 11.3M 0s
          2500K .......... .......... .......... .......... .......... 64% 7.42M 0s
          2550K .......... .......... .......... .......... .......... 66% 22.7M 0s
          2600K .......... .......... .......... .......... .......... 67% 8.47M 0s
          2650K .......... .......... .......... .......... .......... 68% 17.2M 0s
          2700K .......... .......... .......... .......... .......... 69% 9.71M 0s
          2750K .......... .......... .......... .......... .......... 71% 13.6M 0s
          2800K .......... .......... .......... .......... .......... 72% 11.2M 0s
          2850K .......... .......... .......... .......... .......... 73% 11.5M 0s
          2900K .......... .......... .......... .......... .......... 74% 11.1M 0s
          2950K .......... .......... .......... .......... .......... 76% 7.22M 0s
          3000K .......... .......... .......... .......... .......... 77% 27.1M 0s
          3050K .......... .......... .......... .......... .......... 78% 8.00M 0s
          3100K .......... .......... .......... .......... .......... 80% 19.4M 0s
          3150K .......... .......... .......... .......... .......... 81% 9.09M 0s
          3200K .......... .......... .......... .......... .......... 82% 14.7M 0s
          3250K .......... .......... .......... .......... .......... 83% 10.8M 0s
          3300K .......... .......... .......... .......... .......... 85% 11.9M 0s
          3350K .......... .......... .......... .......... .......... 86% 10.3M 0s
          3400K .......... .......... .......... .......... .......... 87% 12.6M 0s
          3450K .......... .......... .......... .......... .......... 88% 11.3M 0s
          3500K .......... .......... .......... .......... .......... 90% 11.4M 0s
          3550K .......... .......... .......... .......... .......... 91% 10.8M 0s
          3600K .......... .......... .......... .......... .......... 92% 7.62M 0s
          3650K .......... .......... .......... .......... .......... 93% 24.0M 0s
          3700K .......... .......... .......... .......... .......... 95% 8.54M 0s
          3750K .......... .......... .......... .......... .......... 96% 16.9M 0s
          3800K .......... .......... .......... .......... .......... 97% 9.55M 0s
          3850K .......... .......... .......... .......... .......... 99% 13.8M 0s
          3900K .......... .......... .......... ......               100% 8.77M=0.3s
        
        2017-12-19 10:20:16 (11.1 MB/s) - 已保存 “install-tl-unx.tar.gz” [4031443/4031443])
        
        Automated TeX Live installation using profile: ../texlive.profile
        Loading http://mirrors.ustc.edu.cn/CTAN/systems/texlive/tlnet/tlpkg/texlive.tlpdb
        Installing TeX Live 2017 from: http://mirrors.ustc.edu.cn/CTAN/systems/texlive/tlnet (verified)
        Platform: x86_64-linux => 'GNU/Linux on x86_64'
        Distribution: net  (downloading)
        Using URL: http://mirrors.ustc.edu.cn/CTAN/systems/texlive/tlnet
        Directory for temporary files: /tmp/74Fg2pfq89
        Installing to: ./
        Installing [1/7, time/total: ??:??/??:??]: hyphen-base [22k]
        Installing [2/7, time/total: 00:00/00:00]: kpathsea [31k]
        Installing [3/7, time/total: 00:00/00:00]: kpathsea.x86_64-linux [46k]
        Installing [4/7, time/total: 00:00/00:00]: tetex [70k]
        Installing [5/7, time/total: 00:01/00:02]: tetex.x86_64-linux [1k]
        Installing [6/7, time/total: 00:01/00:02]: texlive.infra [203k]
        Installing [7/7, time/total: 00:01/00:01]: texlive.infra.x86_64-linux [90k]
        Time used for installing the packages: 00:01
        running mktexlsr ./texmf-dist ...
        writing fmtutil.cnf to ./texmf-dist/web2c/fmtutil.cnf
        writing updmap.cfg to ./texmf-dist/web2c/updmap.cfg
        writing language.dat to ./texmf-var/tex/generic/config/language.dat
        writing language.def to ./texmf-var/tex/generic/config/language.def
        writing language.dat.lua to ./texmf-var/tex/generic/config/language.dat.lua
        running mktexlsr ./texmf-var ./texmf-config ./texmf-dist ...
        running updmap-sys --nohash ...done
        re-running mktexlsr ./texmf-var ./texmf-config ...
        pre-generating all format files, be patient...
        running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --no-strict --all ...done
        running package-specific postactions
        finished with package-specific postactions
        
        Logfile: ./install-tl.log
        tlmgr: package repository http://mirrors.ustc.edu.cn/CTAN/systems/texlive/tlnet (verified)
        [1/19, ??:??/??:??] install: babel [132k]
        [2/19, 00:03/04:33] install: cm [233k]
        [3/19, 00:03/01:38] install: etex [12k]
        [4/19, 00:03/01:35] install: knuth-lib [30k]
        [5/19, 00:04/01:58] install: latex [161k]
        [6/19, 00:04/01:24] install: latex-bin.x86_64-linux [1k]
        [7/19, 00:04/01:24] install: latex-bin [1k]
        [8/19, 00:04/01:24] install: latex-fonts [18k]
        [9/19, 00:04/01:22] install: latexconfig [5k]
        [10/19, 00:04/01:21] install: luatex.x86_64-linux [3442k]
        [11/19, 00:06/00:17] install: luatex [13k]
        [12/19, 00:07/00:20] install: pdftex.x86_64-linux [763k]
        [13/19, 00:08/00:19] install: pdftex [36k]
        [14/19, 00:08/00:19] install: plain [60k]
        [15/19, 00:08/00:19] install: tex-ini-files [4k]
        [16/19, 00:08/00:19] install: unicode-data [220k]
        [17/19, 00:08/00:18] install: xetex.x86_64-linux [6880k]
        [18/19, 00:12/00:12] install: xetex [7k]
        [19/19, 00:13/00:13] install: xetexconfig [1k]
        running mktexlsr ...
        done running mktexlsr.
        running updmap-sys ...
        done running updmap-sys.
        regenerating fmtutil.cnf in /tmp/texlive/texmf-dist
        running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --no-error-if-no-format --byengine xetex ...
        done running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --no-error-if-no-format --byengine xetex.
        running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --no-error-if-no-format --byengine luatex ...
        done running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --no-error-if-no-format --byengine luatex.
        running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --no-error-if-no-format --byengine pdftex ...
        done running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --no-error-if-no-format --byengine pdftex.
        running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --no-error-if-no-format --byengine luajittex ...
        done running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --no-error-if-no-format --byengine luajittex.
        tlmgr: package log updated: /tmp/texlive/texmf-var/web2c/tlmgr.log
        tlmgr: package repository http://mirrors.ustc.edu.cn/CTAN/systems/texlive/tlnet (verified)
        [1/49, ??:??/??:??] install: amscls [32k]
        [2/49, 00:00/00:00] install: amsfonts [3542k]
        [3/49, 00:03/00:16] install: amsmath [30k]
        [4/49, 00:03/00:16] install: bibtex.x86_64-linux [70k]
        [5/49, 00:04/00:21] install: bibtex [15k]
        [6/49, 00:04/00:21] install: booktabs [3k]
        [7/49, 00:04/00:21] install: caption [32k]
        [8/49, 00:04/00:21] install: dvipdfmx.x86_64-linux [2k]
        [9/49, 00:04/00:21] install: dvipdfmx [27k]
        [10/49, 00:04/00:21] install: ec [258k]
        [11/49, 00:05/00:25] install: etoolbox [8k]
        [12/49, 00:05/00:25] install: euenc [4k]
        [13/49, 00:05/00:25] install: fancyvrb [12k]
        [14/49, 00:05/00:24] install: fontspec [26k]
        [15/49, 00:05/00:24] install: framed [8k]
        [16/49, 00:06/00:29] install: geometry [9k]
        [17/49, 00:06/00:29] install: glyphlist [25k]
        [18/49, 00:08/00:39] install: graphics [15k]
        [19/49, 00:08/00:39] install: graphics-cfg [2k]
        [20/49, 00:08/00:39] install: graphics-def [10k]
        [21/49, 00:09/00:44] install: gsftopk.x86_64-linux [40k]
        [22/49, 00:09/00:43] install: gsftopk [4k]
        [23/49, 00:09/00:43] install: hyperref [106k]
        [24/49, 00:09/00:42] install: ifluatex [3k]
        [25/49, 00:09/00:42] install: iftex [2k]
        [26/49, 00:09/00:42] install: ifxetex [2k]
        [27/49, 00:09/00:42] install: l3kernel [125k]
        [28/49, 00:10/00:45] install: l3packages [19k]
        [29/49, 00:10/00:45] install: lm [11651k]
        [30/49, 00:16/00:20] install: lualibs [72k]
        [31/49, 00:16/00:19] install: luaotfload.x86_64-linux [1k]
        [32/49, 00:16/00:19] install: luaotfload [432k]
        [33/49, 00:18/00:21] install: makeindex.x86_64-linux [47k]
        [34/49, 00:18/00:21] install: makeindex [5k]
        [35/49, 00:18/00:21] install: mathspec [10k]
        [36/49, 00:18/00:21] install: metafont.x86_64-linux [186k]
        [37/49, 00:19/00:22] install: metafont [33k]
        [38/49, 00:19/00:22] install: mfware.x86_64-linux [118k]
        [39/49, 00:19/00:22] install: mfware [4k]
        [40/49, 00:19/00:22] install: natbib [17k]
        [41/49, 00:19/00:22] install: oberdiek [221k]
        [42/49, 00:20/00:23] install: tipa [2809k]
        [43/49, 00:21/00:21] install: titling [3k]
        [44/49, 00:21/00:21] install: tools [39k]
        [45/49, 00:22/00:22] install: upquote [2k]
        [46/49, 00:22/00:22] install: url [6k]
        [47/49, 00:22/00:22] install: xkeyval [13k]
        [48/49, 00:22/00:22] install: xunicode [26k]
        [49/49, 00:22/00:22] install: zapfding [46k]
        running mktexlsr ...
        done running mktexlsr.
        running updmap-sys ...
        done running updmap-sys.
        regenerating fmtutil.cnf in /home/rstudio/.TinyTeX/texmf-dist
        running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --byfmt mf ...
        done running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --byfmt mf.
        tlmgr: package log updated: /home/rstudio/.TinyTeX/texmf-var/web2c/tlmgr.log
        Warning message:
        In tinytex::install_tinytex() :
          TinyTeX was not successfully installed or configured.

        只剩最后一个警告

        > tinytex::tlmgr_install('ctex')
        
        tlmgr install ctex
        sh: tlmgr: 未找到命令
        tlmgr path add
        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/.
          
          
        > tlmgr --version
        
        tlmgr revision 46034 (2017-12-11 02:54:21 +0100)
        tlmgr using installation: /home/rstudio/.TinyTeX
        TeX Live (http://tug.org/texlive) version 2017
        
        > tex -v
        
        TeX 3.1415926 (TeX Live 2013)
        kpathsea version 6.1.1
        Copyright 2013 D.E. Knuth.
        There is NO warranty.  Redistribution of this software is
        covered by the terms of both the TeX copyright and
        the Lesser GNU General Public License.
        For more information about these matters, see the file
        named COPYING and the TeX source.
        Primary author of TeX: D.E. Knuth.

        综上,那个警告应该是没有配置新的 tex 替换旧的 tex,而要是先卸载旧的会连同R一块卸载,怎么办?

        附上环境变量

        echo $PATH
        /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:bin/msys-ssh-1000-18:/home/rstudio/.local/bin:/home/rstudio/bin:bin/msys-ssh-1000-18:/home/rstudio/.local/bin:/home/rstudio/bin:bin/msys-ssh-1000-18:/home/rstudio/.local/bin:/home/rstudio/bin:/home/rstudio/.TinyTeX/bin/x86_64-linux

          Cloud2016 哇,我都不知道我有这么聪明……我填不了的坑,就留给了用户自己?

          yihui "是不是我仍然没说清楚"……唉,我看明白你说的了,但是按你说的办法解决不了问题啊。"这个坑已经存在多年",可是我上半年开始用 bookdown 的时候就没有这个问题啊,一口气编译出来 pdf 、gitbook、word 格式的文档,妥妥的,参考文献没有任何问题。而现在……编译 pdf 时我就去掉 yaml 里的 .bib,编译别的就添上 .bib。后来我索性写个代码,根据编译的格式来自动修改 yaml ?

          我觉得好像我说不清了,还是及时止损,远程协助把我捞出来吧,QQ 还是 teamviewer 都行。

          这几天我去山里隐居,回来就重新拎起 tinytex,人世间好像出了什么事儿?瞧,又出现几个新问题:

          1. 分支 rstudio/rmarkdown@feature/tinytex 怎么不见了:
            devtools::install_github("rstudio/rmarkdown@feature/tinytex")
            ## Downloading GitHub repo rstudio/rmarkdown@feature/tinytex
            ## from URL https://api.github.com/repos/rstudio/rmarkdown/zipball/feature/tinytex
            ## Installation failed: 404: Not Found
            ##  (404)

          所以 devtools::install_github( c("yihui/tinytex", "rstudio/rmarkdown@feature/tinytex")) 也是同样的出错信息。

          我目前的 rmarkdown 版本是 rmarkdown 1.8.3 2017-12-12 Github (rstudio/rmarkdown@d6edecd),应该是已经安装了这个分支了.

          1. tinytex::pdflatex()tinytex::xelatex() 为嘛不好使了?但是 tinytex::latexmk(engine = 'pdflatex') 却好使。
          pdflatex('test.tex')
          ## Error: Failed to compile test.tex.
          ## In addition: Warning message:
          ## running command '"pdflatex" -halt-on-error -interaction=batchmode "test.tex"' had status 1 
          xelatex('test.tex')
          ## Error: Failed to compile test.tex.
          ## In addition: Warning message:
          ## running command '"xelatex" -halt-on-error -interaction=batchmode "test.tex"' had status 1 

            Cloud2016 目测 $HOME/bin 在 PATH 中的优先程度不够高(不够靠前),而且你应该检查 R 中的 Sys.getenv('PATH'),因为 R 读的环境变量跟 bash 读的环境变量未必一致(比如 R 不会读你的 ~/.bash_profile)。不过你这情况我估计提前了也不管用,你的问题混合着好几件麻烦事:

            1. 要么你保证 $HOME/bin 能提前出现(同时保证 Sys.getenv('PATH') 在 R 中也能得到 $HOME/bin,这需要你对 R 的配置文件有相当的了解,比如 ~/.Rprofile~/.Renviron),要么把系统自己安装的 texlive 系列包删掉,不要让它干扰到 TinyTeX;

            2. 因为 Linux 的依赖地狱,R 跟 LaTeX 被贵操作系统的打包者强行捆绑了(这特么到底有什么意义),我不知道在贵系统下如何拆开它们。我前面说了,我只能提供在 Debian/Ubuntu 下的逃避办法(FAQ 9),你需要自行找到在 CentOS 下对等的办法。

            如果 R 跟 LaTeX 无法拆开,用 TinyTeX 就没什么意义,因为你顶多就是装一坨 CentOS 提供的 texlive 包,然后另外安装 TinyTeX,然后让 TinyTeX 的 bin 路径在系统 PATH 中足够靠前。躲不开系统自带的 texlive。

            所以这问题不是没有解决办法,比如 ~/.RprofileSys.setenv(PATH = ...),但这只是把问题藏起来的办法。鉴于它是如此之麻烦,我实在忍不了这么不干净利索的解决办法,我建议你要么不要折腾 CentOS,要么不要折腾 TinyTeX,不值得浪费这个时间。

            dapengde 那个 rmarkdown 的分支我已经合并并删除了,你直接 devtools::install_github("rstudio/rmarkdown")

              yihui 1. 多谢提点,改了 .Rprofile 解决了。如果使用 CentOS 仓库自带的R是肯定捆绑的,我始终没有找到替代办法。
              2. 我用非常干净的 CentOS minimal 版本,先按照

              wget -qO- \
                "https://github.com/yihui/tinytex/raw/master/tools/install-unx.sh" | sh

              TinyTeX 装好,自己把依赖找齐,然后编译 R, 再设置 .Rprofiletinytex 包也可以继续用了

                今天根据我的日常使用情况测试了一下,中文出不来啊!

                占位,回家之后编辑?

                yihui 1. 折腾一次就够了 ? 我把它打包成虚拟机镜象了,一劳永逸

                1. 虚拟机放在百度云,分享链接: <https://pan.baidu.com/s/1nv67anJ> 密码: v3mr,用账户 cloud2016 密码 cloud登陆虚拟机即可使用,配置过程比较血腥,就不放了。

                2. 测试的 Rmd 文件,看这里1 ,编译出来的效果,看这里2

                PS: 虚拟机镜像 TinyTeX.ova 有1.55个G,是因为装了常用的一些R包,列表如下:

                > list.files(.libPaths())
                  [1] "assertthat"        "backports"         "base"
                  [4] "base64enc"         "BH"                "bibtex"
                  [7] "bitops"            "bookdown"          "boot"
                 [10] "caTools"           "citr"              "class"
                 [13] "cluster"           "codetools"         "colormap"
                 [16] "colorspace"        "compiler"          "curl"
                 [19] "datasets"          "devtools"          "dichromat"
                 [22] "digest"            "evaluate"          "foreign"
                 [25] "geoR"              "ggplot2"           "git2r"
                 [28] "graphics"          "grDevices"         "grid"
                 [31] "gridExtra"         "gtable"            "highr"
                 [34] "htmltools"         "htmlwidgets"       "httpuv"
                 [37] "httr"              "jsonlite"          "KernSmooth"
                 [40] "knitr"             "labeling"          "lattice"
                 [43] "lazyeval"          "lubridate"         "magrittr"
                 [46] "mapdata"           "mapproj"           "maps"
                 [49] "maptools"          "markdown"          "MASS"
                 [52] "Matrix"            "maxLik"            "memoise"
                 [55] "methods"           "mgcv"              "mime"
                 [58] "miniUI"            "miscTools"         "munsell"
                 [61] "nlme"              "nnet"              "numDeriv"
                 [64] "openssl"           "parallel"          "pdist"
                 [67] "plyr"              "PrevMap"           "R6"
                 [70] "RandomFields"      "RandomFieldsUtils" "raster"
                 [73] "RColorBrewer"      "Rcpp"              "RefManageR"
                 [76] "reshape2"          "rgl"               "rlang"
                 [79] "rmarkdown"         "rpart"             "rprojroot"
                 [82] "rstudioapi"        "rticles"           "sandwich"
                 [85] "scales"            "shiny"             "showtext"
                 [88] "showtextdb"        "sourcetools"       "sp"
                 [91] "spatial"           "splancs"           "splines"
                 [94] "stats"             "stats4"            "stringi"
                 [97] "stringr"           "survival"          "sysfonts"
                [100] "tcltk"             "tibble"            "tinytex"
                [103] "tools"             "translations"      "truncnorm"
                [106] "utils"             "V8"                "viridisLite"
                [109] "whisker"           "withr"             "xml2"
                [112] "xtable"            "yaml"              "zoo"

                本来想把 rocker/geospatial 这个 docker 镜像有的都装上,但是 sf 包装不上,那一堆依赖全部需要手动从官网下载编译,因为仓库自带的版本太低,不能用,我滴肾!

                出于好奇尝试了一下,这里面有深坑。。。

                Debian sid,R 3.4.3。在 RStudio 里装的,安装过程没啥,提示:

                TinyTeX installed to /home/xxx/.TinyTeX
                Warning message:
                In tinytex::install_tinytex() :
                  TinyTeX was not successfully installed or configured.Your PATH variable is /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games. See https://yihui.name/tinytex/faq/ for more information.

                发现这个路径不对啊,进一步,Sys.getenv('PATH')确认了问题,路径是系统默认的,并不是~/.zshrc或者~/.bashrc之类的文件自定义的。改了~/.profile问题依旧,开始怀疑了。

                果断终端开个 R 看看,结果终端 R console 打开没有问题,Sys.getenv('PATH')显示正确,但是:

                > tinytex::is_tinytext()
                FALSE

                再开 RStudio,PATH还是系统默认,自定义的又没了,到这里基本确实肯定哪里有问题。强行在 RStudio 里测试:

                R>library(tinytex)
                R>Sys.getenv('PATH')
                [1] "/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
                R>tinytex:::is_tinytex()
                [1] FALSE

                好吧,只能 Google 了,结果:system() call from RStudio does not find path; same command from commandline R works fine 。目测发现了 RStudio 的万年 bug。

                好了,知道了,终端打开 RStudio 呢,果然,终端开 RStudio 之后Sys.getenv('PATH')终于 RStudio 读到了正确的路径,但是,但是,

                R>tinytex:::is_tinytex()
                [1] FALSE

                依旧。

                  JackieMe
                  Never mind.
                  测试了一个简单文件,可以编译出 PDF。中文貌似有问题,趟下一个坑去了。

                  yihui 好的!新版 rmarkdown 已安装。我用 RStudio 新建 bookdown 项目得到了 'A Minimal Book Example',build 出了一个 test.tex 文件,里面的参考文献声明如下:

                  \bibliography{book.bib,packages.bib}

                  下面是用 tinytex + CTeX 对 test.tex 文件的编译信息。貌似找到 .bib 文件了:Found bibliography file(s) [book.bib packages.bib],但 .bbl 文件里的条目是空的。

                  > tinytex::pdflatex('test.tex')
                  Error: Failed to compile test.tex.
                  In addition: Warning message:
                  running command '"pdflatex" -halt-on-error -interaction=batchmode "test.tex"' had status 1 
                  
                  > tinytex::latexmk('test.tex', 'pdflatex')
                  Latexmk: This is Latexmk, John Collins, 20 Nov. 2017, version: 4.54.
                  Rule 'pdflatex': File changes, etc:
                     Changed files, or newly in use since previous run(s):
                        'test.aux'
                  ------------
                  Run number 1 of rule 'pdflatex'
                  ------------
                  ------------
                  Running 'pdflatex  -halt-on-error -interaction=batchmode -recorder  "test.tex"'
                  ------------
                  Latexmk: applying rule 'pdflatex'...
                  This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6500)
                  entering extended mode
                  Latexmk: Found input bbl file 'test.bbl'
                  Latexmk: Log file says output to 'test.pdf'
                  Latexmk: List of undefined refs and citations:
                    Citation `R-bookdown' on page 7 undefined on input line 249
                    Citation `xie2015' on page 7 undefined on input line 250
                  === TeX engine is 'pdfTeX'
                  Latexmk: Found bibliography file(s) [book.bib packages.bib]
                  Latexmk: Summary of warnings:
                    Latex failed to resolve 2 citation(s)
                  Rule 'pdflatex': File changes, etc:
                     Changed files, or newly in use since previous run(s):
                        'test.toc'
                  ------------
                  Run number 2 of rule 'pdflatex'
                  ------------
                  ------------
                  Running 'pdflatex  -halt-on-error -interaction=batchmode -recorder  "test.tex"'
                  ------------
                  Latexmk: applying rule 'pdflatex'...
                  This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6500)
                  entering extended mode
                  Latexmk: Found input bbl file 'test.bbl'
                  Latexmk: Log file says output to 'test.pdf'
                  Latexmk: List of undefined refs and citations:
                    Citation `R-bookdown' on page 7 undefined on input line 249
                    Citation `xie2015' on page 7 undefined on input line 250
                  === TeX engine is 'pdfTeX'
                  Latexmk: Found bibliography file(s) [book.bib packages.bib]
                  Latexmk: Summary of warnings:
                    Latex failed to resolve 2 citation(s)
                  Latexmk: All targets (test.pdf) are up-to-date
                  Warning message:
                  running command '"latexmk" -pdf -latexoption=-halt-on-error -interaction=batchmode -pdflatex=pdflatex "test.tex"' had status 12 
                  > devtools::session_info()
                  Session info -------------------------------------------------------------------------------
                   setting  value                                              
                   version  R version 3.4.3 (2017-11-30)                       
                   system   x86_64, mingw32                                    
                   ui       RStudio (1.1.383)                                  
                   language (EN)                                               
                   collate  Chinese (Simplified)_People's Republic of China.936
                   tz       Europe/Berlin                                      
                   date     2017-12-20                                         
                  
                  Packages -----------------------------------------------------------------------------------
                   package   * version date       source                        
                   base      * 3.4.3   2017-11-30 local                         
                   compiler    3.4.3   2017-11-30 local                         
                   curl        3.0     2017-10-06 CRAN (R 3.4.2)                
                   datasets  * 3.4.3   2017-11-30 local                         
                   devtools    1.13.4  2017-11-09 CRAN (R 3.4.3)                
                   digest      0.6.12  2017-01-27 CRAN (R 3.3.2)                
                   git2r       0.19.0  2017-07-19 CRAN (R 3.4.1)                
                   graphics  * 3.4.3   2017-11-30 local                         
                   grDevices * 3.4.3   2017-11-30 local                         
                   httr        1.3.1   2017-08-20 CRAN (R 3.4.1)                
                   memoise     1.1.0   2017-04-21 CRAN (R 3.3.3)                
                   methods   * 3.4.3   2017-11-30 local                         
                   R6          2.2.2   2017-06-17 CRAN (R 3.3.3)                
                   stats     * 3.4.3   2017-11-30 local                         
                   tinytex     0.1.6   2017-12-19 Github (yihui/tinytex@acbc9db)
                   tools       3.4.3   2017-11-30 local                         
                   utils     * 3.4.3   2017-11-30 local                         
                   withr       2.1.0   2017-11-01 CRAN (R 3.4.3)                
                   yaml        2.1.16  2017-12-12 CRAN (R 3.4.3)  

                    Cloud2016 谢谢。真是跟不上节奏。已升级,但仍然不行。这个不是 tinytex 的问题,是 MiKTeX 或者 BiBTeX 的问题。我放弃了,就带病生存吧,也挺好。

                    tinytex     0.2     2017-12-20 Github (yihui/tinytex@dbb4900) 

                    JackieMe 这个 PATH 问题不能算 RStudio 的问题,所有图形界面工具都会存在这个问题。核心问题就是只有你的命令行终端会读那些 ~/.bash_profile 之类的文件,图形界面工具不会读那些文件,所以你在那里面修改 PATH 是无效的。

                    dapengde 你直接在命令行窗口中跑 "pdflatex" -halt-on-error -interaction=batchmode "test.tex" 是什么结果?有没有日志文件 test.log?

                      yihui 你咋就不让我放弃呢? 在cmd 窗口运行 pdflatex,有 log 文件,里面关于参考文献的信息是:

                      Package natbib Warning: Citation `R-bookdown' on page 7 undefined on input line
                       249.
                      Package natbib Warning: Citation `xie2015' on page 7 undefined on input line 25
                      0.

                      这是运行第一遍 pdflatex 的记录。关键是下一步运行 bibtex,就成了 book.bib.bib 了,所以后面第二遍第三遍运行的 pdflatex 就没啥意义了:

                      Microsoft Windows [Version 6.1.7601]
                      Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
                      
                      D:\temp\newpkg\test>"pdflatex" -halt-on-error -interaction=batchmode "test.tex"
                      
                      This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6500)
                      entering extended mode
                      
                      D:\temp\newpkg\test>bibtex test
                      This is BibTeX, Version 0.99d (MiKTeX 2.9.6500)
                      The top-level auxiliary file: test.aux
                      The style file: apalike.bst
                      I couldn't open database file book.bib.bib
                      ---line 50 of file test.aux
                       : \bibdata{book.bib
                       :                  ,packages.bib}
                      I'm skipping whatever remains of this command
                      I found no database files---while reading file test.aux
                      Warning--I didn't find a database entry for "R-bookdown"
                      Warning--I didn't find a database entry for "xie2015"
                      (There were 2 error messages)

                        dapengde 嗯,我只想知道第一遍 pdflatex 为什么会失败,后面不需要跑 bibtex(它肯定会失败,这个我明白)。你得先把那些 .aux / .bbl / .blg 之类的辅助文件删掉再跑 pdflatex,我想看的是 .log 文件里面说什么。

                        因为你这个问题实在是太匪夷所思了,我想不明白为什么鱼儿会漏网。

                          yihui .log 太长,来这里看看。你现在搞得我非常讳疾忌医。

                          我在 .tex 里把 .bib 文件的扩展名去掉编译,得到的 .log 文件跟没去掉扩展名得到的 .log 文件比较了一下,两个 .log 文件一模一样。但是第二步 运行 bibtex test 就不同了,一个找到了 .bib 文件,一个没找到 .bib.bib 文件。