召集壮士帮忙测试 TinyTeX
- 已编辑
yihui 经过了多种努力,终于从这个安装失败的坑里爬出来了!
解决方法很简单: windows 操作系统的环境变量里添加 PATH:c:\Windows\System32
?
操作系统是 windows 7。
故障原因,我猜可能是某次折腾时某个软件把这个路径环境变量里覆盖了。
网上提供的多个解决办法,例如安装 strawberryperl,例如查看防火墙或杀毒软件是不是在作祟……这些都不是我这次故障的原因。
现在,TinyTex 成功安装了。不过,新问题来了:
我参加 bookdown 大赛制作的两个中文模板(北京大学学位论文,中科院大学学位论文),都无法编译成 pdf。后者说是 \CJKunderlinecolor undefined.
。前者比较诡异,没有任何故障信息,貌似成功编译了,但就是没有生成 pdf 文件。
此外,我在编译一个英文的 bookdown 项目时,通过点击 RStudio 的 build 按钮,第一次生成的 pdf 里的参考文献都显示的是问号。后来重新编译一次就好了。
为了对比,我卸载了 TinyTeX,安装 MikTeX,升级到最新,安装 xetex 宏包和 pkuthss 包,然后编译 上面说的两个中文 bookdown 项目,都成功了。这是不是因为 MikTeX 里有些包在 TeX Live 里不存在?
- 已编辑
dapengde 我暂时没空检查这个问题。先看别的壮士(如 @Cloud2016 @yufree @tctcab 等)是否可以重现你的问题吧,如果问题在别人那里也可以重现,我再研究一下。
还有,你这 c:\Windows\System32
坑太深了。
- 已编辑
tctcab 我原本也是想不要拷贝 Windows 下的字体,可是发现 Linux 下的替代字体竟然差别还比较明显(仔细看的话),当然了这发生在我的 bookdown 论文模板里 ,这个环境对字体格式要求比较高,不敢擅自做主替换字体。https://github.com/XiangyunHuang/Thesis-Template-Bookdown/tree/master/fonts
dapengde 别人的 LaTeX 模板维护起来很麻烦,我是不会 LaTeX 编程的,这个字体设置文件看起来懂了,其实似懂非懂, ctex-fontset-pkuthss.def ,早些时候我基于 bookdown 的论文模板,其 LaTeX 模板是学院代代相传的 CCT 中文处理系统, CTeX 除了从师兄师姐那拷贝,别无它法,你可以想象模板得有多老,现在他们还是十年如一届地继续用老模板,我是第一个推倒重来制作 LaTeX 模板,但是包裹了 bookdown,我不会 LaTeX 编程,所以 Thesis-Template-Bookdown 项目的 LaTeX 文件组织起来没有 LaTeX 项目那样标准。此外,我的经历告诉我,对于像论文、书籍模板这种复杂的应用,不建议同时维护那么多格式,我觉得 gitbook 和 pdf 两种格式够用,但是内容应该足够丰富以应对各式各样的图、表排版要求,往往这个才是阻碍推广的地方,因为比较难学,通常的 demo 不会覆盖到这里,初学者拿到模板是希望填公式和图表,而不是去学如何填公式和图表,不然他们又该回去用 Word 或者 LaTeX 了。
扯了这么多,回到问题,我试了 北京大学学位论文 除了几个警告没什么问题。
首先更新 tlmgr 和安装 pkuthss 宏包
tlmgr update --self
tlmgr install pkuthss
附环境信息
xfun::session_info(packages = c("bookdown","rmarkdown"))
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200), RStudio 1.1.456
Locale:
LC_COLLATE=Chinese (Simplified)_China.936
LC_CTYPE=Chinese (Simplified)_China.936
LC_MONETARY=Chinese (Simplified)_China.936
LC_NUMERIC=C
LC_TIME=Chinese (Simplified)_China.936
Package version:
base64enc_0.1.3 bookdown_0.7.18 digest_0.6.16 evaluate_0.11
glue_1.3.0 graphics_3.5.1 grDevices_3.5.1 highr_0.7
htmldeps_0.1.1 htmltools_0.3.6 jsonlite_1.5 knitr_1.20
magrittr_1.5 markdown_0.8 methods_3.5.1 mime_0.5
Rcpp_0.12.18 rmarkdown_1.10.12 stats_3.5.1 stringi_1.2.4
stringr_1.3.1 tinytex_0.8 tools_3.5.1 utils_3.5.1
xfun_0.3.8 yaml_2.2.0
Pandoc version: 2.2.3.2
附警告信息
==> rmarkdown::render_site(encoding = 'UTF-8')
|....... | 11%
inline R code fragments
|.............. | 22%
label: set-options (with options)
List of 2
$ echo : logi FALSE
$ cache: logi FALSE
|...................... | 33%
inline R code fragments
|............................. | 44%
label: co2 (with options)
List of 4
$ echo : logi FALSE
$ out.width: chr "80%"
$ fig.cap : chr "�� R ���Ի���ͼ����"
$ fig.align: chr "center"
|.................................... | 56%
ordinary text without R code
|........................................... | 67%
label: tabair
|................................................... | 78%
ordinary text without R code
|.......................................................... | 89%
label: unnamed-chunk-1 (with options)
List of 1
$ eval: logi FALSE
|.................................................................| 100%
ordinary text without R code
processing file: pku.Rmd
output file: pku.knit.md
"D:/Program Files (x86)/Pandoc/pandoc" +RTS -K512m -RTS pku.utf8.md --to docx --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash+smart --output pku.docx --highlight-style tango --filter pandoc-citeproc
|....... | 11%
inline R code fragments
|.............. | 22%
label: set-options (with options)
List of 2
$ echo : logi FALSE
$ cache: logi FALSE
|...................... | 33%
inline R code fragments
|............................. | 44%
label: co2 (with options)
List of 4
$ echo : logi FALSE
$ out.width: chr "80%"
$ fig.cap : chr "�� R ���Ի���ͼ����"
$ fig.align: chr "center"
|.................................... | 56%
ordinary text without R code
|........................................... | 67%
label: tabair
|................................................... | 78%
ordinary text without R code
|.......................................................... | 89%
label: unnamed-chunk-1 (with options)
List of 1
$ eval: logi FALSE
|.................................................................| 100%
ordinary text without R code
Output created: _book/pku.docx
processing file: pku.Rmd
output file: pku.knit.md
"D:/Program Files (x86)/Pandoc/pandoc" +RTS -K512m -RTS pku.utf8.md --to epub3 --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pku.epub --number-sections --filter pandoc-citeproc
|....... | 11%
inline R code fragments
|.............. | 22%
label: set-options (with options)
List of 2
$ echo : logi FALSE
$ cache: logi FALSE
|...................... | 33%
inline R code fragments
|............................. | 44%
label: co2 (with options)
List of 4
$ echo : logi FALSE
$ out.width: chr "80%"
$ fig.cap : chr "�� R ���Ի���ͼ����"
$ fig.align: chr "center"
|.................................... | 56%
ordinary text without R code
|........................................... | 67%
label: tabair
|................................................... | 78%
ordinary text without R code
|.......................................................... | 89%
label: unnamed-chunk-1 (with options)
List of 1
$ eval: logi FALSE
|.................................................................| 100%
ordinary text without R code
Output created: _book/pku.epub
processing file: pku.Rmd
output file: pku.knit.md
"D:/Program Files (x86)/Pandoc/pandoc" +RTS -K512m -RTS pku.utf8.md --to html4 --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash+smart --output pku.html --email-obfuscation none --wrap preserve --standalone --section-divs --table-of-contents --toc-depth 3 --template "D:\site-library\bookdown\templates\gitbook.html" --highlight-style pygments --number-sections --css "style\gitbook.css" --include-in-header "C:\Users\xy-huang\AppData\Local\Temp\Rtmpqq6C5l\rmarkdown-str20e86aac3cc9.html" --mathjax --filter pandoc-citeproc
|....... | 11%
inline R code fragments
|.............. | 22%
label: set-options (with options)
List of 2
$ echo : logi FALSE
$ cache: logi FALSE
|...................... | 33%
inline R code fragments
|............................. | 44%
label: co2 (with options)
List of 4
$ echo : logi FALSE
$ out.width: chr "80%"
$ fig.cap : chr "�� R ���Ի���ͼ����"
$ fig.align: chr "center"
|.................................... | 56%
ordinary text without R code
|........................................... | 67%
label: tabair
|................................................... | 78%
ordinary text without R code
|.......................................................... | 89%
label: unnamed-chunk-1 (with options)
List of 1
$ eval: logi FALSE
|.................................................................| 100%
ordinary text without R code
"D:/Program Files (x86)/Pandoc/pandoc" +RTS -K512m -RTS pku.utf8.md --to html4 --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash+smart --output pku.html --email-obfuscation none --self-contained --wrap preserve --standalone --section-divs --template "D:\site-library\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --number-sections --variable "theme:bootstrap" --include-in-header "C:\Users\xy-huang\AppData\Local\Temp\Rtmpqq6C5l\rmarkdown-str20e83bd67914.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --filter pandoc-citeproc
Output created: _book/preface.html
processing file: pku.Rmd
output file: pku.knit.md
|....... | 11%
inline R code fragments
|.............. | 22%
label: set-options (with options)
List of 2
$ echo : logi FALSE
$ cache: logi FALSE
|...................... | 33%
inline R code fragments
|............................. | 44%
label: co2 (with options)
List of 4
$ echo : logi FALSE
$ out.width: chr "80%"
$ fig.cap : chr "�� R ���Ի���ͼ����"
$ fig.align: chr "center"
Output created: pku.html
processing file: pku.Rmd
|.................................... | 56%
ordinary text without R code
|........................................... | 67%
label: tabair
|................................................... | 78%
ordinary text without R code
|.......................................................... | 89%
label: unnamed-chunk-1 (with options)
List of 1
$ eval: logi FALSE
|.................................................................| 100%
ordinary text without R code
"D:/Program Files (x86)/Pandoc/pandoc" +RTS -K512m -RTS pku.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pku.tex --table-of-contents --toc-depth 2 --template "tex\template_pku.tex" --number-sections --highlight-style tango --pdf-engine xelatex --natbib --top-level-division=chapter --variable tables=yes --standalone
output file: pku.knit.md
Output created: _book/pku.pdf
Warning messages:
1: In (knit_hooks$get("plot"))(file, reduce_plot_opts(options)) :
Chunk options fig.align, out.width, out.height, out.extra are not supported for Word output
2: In xfun::prose_index(content) : Code fences are not balanced
3: In xfun::prose_index(content) : Code fences are not balanced
附 LaTeX 信息
XeTeX 3.14159265-2.6-0.99999 (TeX Live 2018/W32TeX)
kpathsea version 6.3.0
Copyright 2018 SIL International, Jonathan Kew and Khaled Hosny.
There is NO warranty. Redistribution of this software is
covered by the terms of both the XeTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the XeTeX source.
Primary author of XeTeX: Jonathan Kew.
Compiled with ICU version 61.1; using 61.1
Compiled with zlib version 1.2.11; using 1.2.11
Compiled with FreeType2 version 2.9.1; using 2.9.1
Compiled with Graphite2 version 1.3.11; using 1.3.11
Compiled with HarfBuzz version 1.7.6; using 1.7.6
Compiled with libpng version 1.6.34; using 1.6.34
Compiled with poppler version 0.64.0
Compiled with fontconfig version 2.13.0; using 2.13.0
字体问题 ctex 包应该早已经可以根据操作系统自动选择了,瘟到死和苹果都有自带中文字体,Linux 下也有保底的 Fandol 字体,所以现在完全没必要写死为宋体。当然这问题如 @Cloud2016 所说,历史的惯性太大了。LaTeX 这种东西大家都不敢随便动(问你惊喜不惊喜、敢动不敢动?不敢动不敢动),宁愿用十年前的模板和软件吊死在 Windows 上,也不敢轻易尝试新版本,因为一旦搞砸,这会是一个吸收时间的黑洞,代价太大。
所以我已经开始启程走 CSS 排版之路,直接从浏览器生成高质量 PDF。
- 已编辑
@Cloud2016 @tctcab 我把 tlmgr, rmakrdown, bookdown 全都升级了,故障依旧:
bookdown-ucas 不能成功编译,显示
! LaTeX Error: \CJKunderlinecolor undefined.
(log 文件)。bookdown-pku 貌似编译完了,但没有生成 pdf 文件(log 文件)。我留意到出现了个 missfont.log 文件,不明白是不是缺少了什么字体。
看大家用的系统比较新,怀疑是不是我的 windows 7 的问题?
> devtools::session_info()
Session info ------------------------------------------------------------------------------------
setting value
version R version 3.5.1 (2018-07-02)
system x86_64, mingw32
ui RStudio (1.1.456)
language (EN)
collate Chinese (Simplified)_People's Republic of China.936
tz Europe/Berlin
date 2018-09-15
Packages ----------------------------------------------------------------------------------------
package * version date source
backports 1.1.2 2017-12-13 CRAN (R 3.5.0)
base * 3.5.1 2018-07-02 local
bookdown * 0.7.18 2018-09-15 Github (rstudio/bookdown@b657ab3)
compiler 3.5.1 2018-07-02 local
curl 3.2 2018-03-28 CRAN (R 3.5.1)
datasets * 3.5.1 2018-07-02 local
devtools 1.13.6 2018-06-27 CRAN (R 3.5.1)
digest 0.6.17 2018-09-12 CRAN (R 3.5.1)
evaluate 0.11 2018-07-17 CRAN (R 3.5.1)
git2r 0.23.0 2018-07-17 CRAN (R 3.5.1)
graphics * 3.5.1 2018-07-02 local
grDevices * 3.5.1 2018-07-02 local
htmltools 0.3.6 2017-04-28 CRAN (R 3.5.1)
httr 1.3.1 2017-08-20 CRAN (R 3.5.1)
knitr 1.20 2018-02-20 CRAN (R 3.5.1)
magrittr 1.5 2014-11-22 CRAN (R 3.5.1)
memoise 1.1.0 2017-04-21 CRAN (R 3.5.1)
methods * 3.5.1 2018-07-02 local
R6 2.2.2 2017-06-17 CRAN (R 3.5.1)
Rcpp 0.12.18 2018-07-23 CRAN (R 3.5.1)
rmarkdown 1.10.13 2018-09-15 Github (rstudio/rmarkdown@df4ec91)
rprojroot 1.3-2 2018-01-03 CRAN (R 3.5.1)
rstudioapi 0.7 2017-09-07 CRAN (R 3.5.1)
stats * 3.5.1 2018-07-02 local
stringi 1.2.4 2018-07-20 CRAN (R 3.5.1)
stringr 1.3.1 2018-05-10 CRAN (R 3.5.1)
tools 3.5.1 2018-07-02 local
utils * 3.5.1 2018-07-02 local
withr 2.1.2 2018-03-15 CRAN (R 3.5.1)
xfun 0.3 2018-07-06 CRAN (R 3.5.1)
yaml 2.2.0 2018-07-25 CRAN (R 3.5.1)
- 已编辑
ucas的模板试了一下,跟你的报错一样,注释掉
https://github.com/pzhaonet/bookdown-ucas/blob/master/Style/ucasthesis.cls#L122
这一行之后可以编译成功。
看代码猜测是把下划线设为黑色不过看pdf里下划线都正常嘛?
Session info --------------------------------------------------------------------------------
setting value
version R version 3.5.1 (2018-07-02)
system x86_64, mingw32
ui RStudio (1.1.419)
language (EN)
collate English_United States.1252
tz Australia/Brisbane
date 2018-09-16
Packages -----------------------------------------------------------------------------------
package * version date source
base * 3.5.1 2018-07-02 local
bookdown 0.7 2018-02-18 CRAN (R 3.5.1)
compiler 3.5.1 2018-07-02 local
datasets * 3.5.1 2018-07-02 local
devtools 1.13.6 2018-06-27 CRAN (R 3.5.1)
digest 0.6.16 2018-08-22 CRAN (R 3.5.1)
evaluate 0.11 2018-07-17 CRAN (R 3.5.1)
graphics * 3.5.1 2018-07-02 local
grDevices * 3.5.1 2018-07-02 local
htmldeps 0.1.1 2018-09-15 Github (rstudio/htmldeps@c1023e0)
htmltools 0.3.6 2017-04-28 CRAN (R 3.5.1)
knitr 1.20 2018-02-20 CRAN (R 3.5.1)
magrittr 1.5 2014-11-22 CRAN (R 3.5.1)
memoise 1.1.0 2017-04-21 CRAN (R 3.5.1)
methods * 3.5.1 2018-07-02 local
Rcpp 0.12.18 2018-07-23 CRAN (R 3.5.1)
rmarkdown 1.10.13 2018-09-15 Github (rstudio/rmarkdown@df4ec91)
stats * 3.5.1 2018-07-02 local
stringi 1.1.7 2018-03-12 CRAN (R 3.5.0)
stringr 1.3.1 2018-05-10 CRAN (R 3.5.1)
tools 3.5.1 2018-07-02 local
utils * 3.5.1 2018-07-02 local
withr 2.1.2 2018-03-15 CRAN (R 3.5.1)
xfun 0.3 2018-07-06 CRAN (R 3.5.1)
yaml 2.2.0 2018-07-25 CRAN (R 3.5.1)
可以这样查看缺失字体
tlmgr search --file --global "qtmb.pfb"
tlmgr.pl: package repository https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/tlnet (verified)
tex-gyre:
texmf-dist/fonts/type1/public/tex-gyre/qtmb.pfb
把 tex-gyre 安装再试试
Cloud2016 tex-gyre 安装了,仍然编译不成功。看起来仍然是字体缺失的问题。
tctcab 哈哈,对,注释掉这一行确实可以跳过这一步了,然而又遇见了跟 bookdown-pku 同样的问题(见log 文件):字体。
这两个模板都表现为:.tex 文件已经顺利生成了,并被 bookdown 移至默认的 _book/文件夹,但 pdf 文件没生成,而 bookdown 误以为生成了,想打开却打不开:
Output created: _book/pku.pdf
Error in tools::file_path_as_absolute(output_file) :
file '_book/pku.pdf' does not exist
@yihui 我觉得 bookdown 在这里给的上述信息提示不大对头。
对于上述字体问题,我在 TeXStudio 下面编译了一下 bookdown 生成的 .tex文件,得到的错误提示是:
xdvipdfmx:fatal: Could not find encoding file "8r.enc". Output file removed.
fwrite: Broken pipe xelatex.exe:
Process exited with error(s)
于是就下载了个"8r.enc"文件,再编译,得到新的错误提示:
name = utmri8a, rootname = utmri8a, pointsize = mktexmf: empty or non-existent rootfile!
kpathsea: Running mktexmf utmri8a.mf The command name is C:\Users\PengZhao\AppData\Roaming\TinyTeX\bin\win32\mktexmf Cannot find utmri8a.mf . I try ps2pk --> gsftopk --> ttf2pk --> hbf2gf. Cannot find utmri8a.tfm .
kpathsea: Running mktexpk --mfmode / --bdpi 600 --mag 1+0/600 --dpi 600 utmri8a.pfb The command name is C:\Users\PengZhao\AppData\Roaming\TinyTeX\bin\win32\mktexpk kpathsea: Appending font creation commands to missfont.log. xdvipdfmx:fatal: Cannot proceed without .vf or "physical" font for PDF output... Output file removed.
fwrite: Broken pipe
xelatex.exe:
Process exited with error(s)
里面稀里糊涂的东西太多,我目前止步于此了。
- 已编辑
dapengde 应该稍稍再坚持一下就好了,还是之前的思路,凡是字体问题都可以这样搜,然后把相应的包装上,至少可以解决 99% 的字体缺失问题
tlmgr search --file --global "utmri8a.pfb"
tlmgr.pl: package repository https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/tlnet (verified)
times:
texmf-dist/fonts/type1/urw/times/utmri8a.pfb
tlgs.win32:
tlpkg/tlgs/fonts/utmri8a.pfb
tlmgr search --file --global "8r.enc"
tlmgr.pl: package repository https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/tlnet (verified)
context:
texmf-dist/fonts/enc/dvips/context/q-8r.enc
dvips:
texmf-dist/fonts/enc/dvips/base/8r.enc
txfonts:
texmf-dist/fonts/enc/dvips/txfonts/tx8r.enc
此外,我这整理了一个比较小功能又比较全的支持中文的 LaTeX 包的列表 TeXLive.pkgs 你可以都装上试一下,我想里面大多数包你都已经装好了
Cloud2016 这个列表不错!于是我都装了:
link <- 'https://raw.githubusercontent.com/XiangyunHuang/Thesis-Template-Bookdown/master/latex/TeXLive.pkgs'
pkgs <- readLines(link)
for(pkg in pkgs) tinytex::tlmgr_install(pkg)
上面那两个缺失文件是装上了,现在的新问题是找不到 'utmri8a.mf':
name = utmri8a, rootname = utmri8a, pointsize = mktexmf: empty or non-existent rootfile!
kpathsea: Running mktexmf utmri8a.mf The command name is C:\Users\PengZhao\AppData\Roaming\TinyTeX\bin\win32\mktexmf Cannot find utmri8a.mf . I try ps2pk --> gsftopk --> ttf2pk --> hbf2gf. Cannot find utmri8a.tfm .
kpathsea: Running mktexpk --mfmode / --bdpi 600 --mag 1+0/600 --dpi 600 utmri8a.pfb The command name is C:\Users\PengZhao\AppData\Roaming\TinyTeX\bin\win32\mktexpk kpathsea: Appending font creation commands to missfont.log. xdvipdfmx:fatal: Cannot proceed without .vf or "physical" font for PDF output... Output file removed.
fwrite: Broken pipe xelatex.exe:
Process exited with error(s)
搜一下:
> tinytex::tlmgr_search('utmri8a.tfm')
tlmgr search --file --global "utmri8a.tfm"
tlmgr.pl: package repository http://mirror.informatik.hs-fulda.de/tex-archive/systems/texlive/tlnet (not verified: gpg unavailable)
没找到……