zoukankan      html  css  js  c++  java
  • [CentOS 7] TexLive2017中kpsewhich Bug的修复

    使用TexLive有一段时间了,从2015到2017,一直运行如常。

    最近,想把以前的文档重新编译,却发现不能正常运行,费了好大一番工夫,才终于修复了这个bug,记录如下。

     问题描述:编译一个简单的 *.tex 文件时,经常报告系统文件找不到的错误,无论是 pdflatex,latex,xelatex 命令都有类似的错误。

    test.tex 全文:

    % test.tex
    documentclass{article}
    egin{document}
    hello LaTeX!
    end{document}

    用 pdflatex 命令编译报错:

    [...]$ pdflatex test.tex
    This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017) (preloaded format=pdflatex)
     restricted write18 enabled.
    
    kpathsea: Running mktexfmt pdflatex.fmt
    mktexfmt: mktexfmt is using the following fmtutil.cnf files (in precedence order):
    mktexfmt:   /usr/local/texlive/2017/texmf-dist/web2c/fmtutil.cnf
    mktexfmt: mktexfmt is using the following fmtutil.cnf file for writing changes:
    mktexfmt:   /home/She/.texlive2017/texmf-config/web2c/fmtutil.cnf
    mktexfmt [INFO]: writing formats under /home/She/.texlive2017/texmf-var/web2c
    mktexfmt [INFO]: --- remaking pdflatex with pdftex
    mktexfmt: running `pdftex -ini   -jobname=pdflatex -progname=pdflatex -translate-file=cp227.tcx *pdflatex.ini' ...
    This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017) (INITEX)
     restricted write18 enabled.
     (/usr/local/texlive/2017/texmf-dist/web2c/cp227.tcx)
    entering extended mode
    (/usr/local/texlive/2017/texmf-dist/tex/latex/latexconfig/pdflatex.ini
    ! I can't find file `pdftexconfig.tex'.
    l.2 input pdftexconfig.tex
                              
    (Press Enter to retry, or Control-D to exit)
    Please type another input file name:
    ! Emergency stop.
    l.2 input pdftexconfig.tex
                              
    No pages of output.
    Transcript written on pdflatex.log.
    mktexfmt [ERROR]: running `pdftex -ini   -jobname=pdflatex -progname=pdflatex -translate-file=cp227.tcx *pdflatex.ini >&2 </dev/null' return status 1
    mktexfmt [ERROR]: return error due to options --strict
    mktexfmt [INFO]: Disabled formats: 6
    mktexfmt [INFO]: Not selected formats: 43
    mktexfmt [INFO]: Failed to build: 1 (pdftex/pdflatex)
    mktexfmt [INFO]: Total formats: 50
    mktexfmt [INFO]: exiting with status 1
    I can't find the format file `pdflatex.fmt'!

    实际上,上述文件  pdftexconfig.tex  和  pdflatex.fmt  是存在的,它们分别位于  /usr/local/texlive/2017/texmf-dist/tex/generic/tex-ini-files/pdftexconfig.tex  和  /usr/local/texlive/2017/texmf-var/web2c/pdftex/pdflatex.fmt  。

    推断这是由于该文件并不在搜索路径内,以致于无法找到它们。接下来就是修复搜索路径的问题。

    此时,TexLive 2017 的系统环境变量为

    [...]$ cat /etc/profile.d/texlive2017.sh
    #!/bin/bash
    # setting for TexLive 2017 environment variables, edit by She
    export TEXMF=/usr/local/texlive/2017/texmf-dist
    export PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/texlive/2017/bin/x86_64-linux
    export MANPATH=/usr/local/texlive/2017/texmf-dist/doc/man:$MANPATH
    export INFOPATH=/usr/local/texlive/2017/texmf-dist/doc/info:$INFOPATH
    export TEXINPUTS=/usr/local/texlive/2017/texmf-dist/tex/latex/latexconfig
    

    相应地,可以看到 kpsewhich 命令并不能搜索到相应的系统文件(这里以 minted.sty 文件为例),而且 TexLive 2017 下 tlmgr 工具的参数设置如下,红色带下划线的文字是我添加的注释:

    
    
    [...]$ kpsewhich pdflatex.ini
    /usr/local/texlive/2017/texmf-dist/tex/latex/latexconfig/pdflatex.ini
    [...]$ kpsewhich --show-path=.sty
    /usr/local/texlive/2017/texmf-dist/tex/latex/latexconfig
    [...]$ kpsewhich minted.sty    # 这个命令没有返回结果,说明 kpsewhich 的搜索路径设置不当
    [...]$

    [...]$ tlmgr conf =========================== version information ========================== tlmgr revision 44836 (2017-07-18 01:59:48 +0200) tlmgr using installation: /usr/local/texlive/2017 TeX Live (http://tug.org/texlive) version 2017 ==================== executables found by searching PATH ================= PATH: /usr/local/texlive/2017/bin/x86_64-linux:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/opt/pgi/linux86-64/17.4/bin:/home/She/.local/bin:/home/She/bin:/usr/local/texlive/2017/bin/x86_64-linux:/opt/pgi/linux86-64/17.4/bin:/home/She/.local/bin:/home/She/bin:/usr/local/texlive/2017/bin/x86_64-linux kpsewhich: /usr/local/texlive/2017/bin/x86_64-linux/kpsewhich updmap: /usr/local/texlive/2017/bin/x86_64-linux/updmap fmtutil: /usr/local/texlive/2017/bin/x86_64-linux/fmtutil tlmgr: /usr/local/texlive/2017/bin/x86_64-linux/tlmgr tex: /usr/local/texlive/2017/bin/x86_64-linux/tex pdftex: /usr/local/texlive/2017/bin/x86_64-linux/pdftex mktexpk: /usr/local/texlive/2017/bin/x86_64-linux/mktexpk dvips: /usr/local/texlive/2017/bin/x86_64-linux/dvips dvipdfmx: /usr/local/texlive/2017/bin/x86_64-linux/dvipdfmx =========================== active config files ========================== texmf.cnf: /usr/local/texlive/2017/texmf.cnf texmf.cnf: /usr/local/texlive/2017/texmf-dist/web2c/texmf.cnf updmap.cfg: /usr/local/texlive/2017/texmf-dist/web2c/updmap.cfg fmtutil.cnf: /usr/local/texlive/2017/texmf-dist/web2c/fmtutil.cnf config.ps: /usr/local/texlive/2017/texmf-dist/dvips/config/config.ps mktex.cnf: /usr/local/texlive/2017/texmf-dist/web2c/mktex.cnf pdftexconfig.tex: ============================= font map files ============================= psfonts.map: /usr/local/texlive/2017/texmf-dist/fonts/map/dvips/updmap/psfonts.map pdftex.map: /usr/local/texlive/2017/texmf-dist/fonts/map/pdftex/updmap/pdftex.map ps2pk.map: /usr/local/texlive/2017/texmf-dist/fonts/map/dvips/updmap/ps2pk.map kanjix.map: /usr/local/texlive/2017/texmf-dist/fonts/map/dvipdfmx/updmap/kanjix.map =========================== kpathsea variables =========================== TEXMFMAIN=/usr/local/texlive/2017/texmf-dist TEXMFDIST=/usr/local/texlive/2017/texmf-dist TEXMFLOCAL=/usr/local/texlive/texmf-local TEXMFSYSVAR=/usr/local/texlive/2017/texmf-var TEXMFSYSCONFIG=/usr/local/texlive/2017/texmf-config TEXMFVAR=/home/She/.texlive2017/texmf-var TEXMFCONFIG=/home/She/.texlive2017/texmf-config TEXMFHOME=/home/She/texmf VARTEXFONTS=/home/She/.texlive2017/texmf-var/fonts TEXMF=/usr/local/texlive/2017/texmf-dist SYSTEXMF=/usr/local/texlive/2017/texmf-var:/usr/local/texlive/texmf-local:/usr/local/texlive/2017/texmf-dist TEXMFDBS={!!/usr/local/texlive/texmf-local,!!/usr/local/texlive/2017/texmf-config,!!/usr/local/texlive/2017/texmf-var,!!/usr/local/texlive/2017/texmf-dist} WEB2C=/usr/local/texlive/2017/texmf-dist/web2c TEXPSHEADERS=.:/usr/local/texlive/2017/texmf-dist/{dvips,fonts/{enc,type1,type42,type3}}// TEXCONFIG=/usr/local/texlive/2017/texmf-dist/dvips// ENCFONTS=.:/usr/local/texlive/2017/texmf-dist/fonts/enc// TEXFONTMAPS=.:/usr/local/texlive/2017/texmf-dist/fonts/map/{kpsewhich,pdftex,dvips,}// ==== kpathsea variables from environment only (ok if no output here) ==== TEXINPUTS=/usr/local/texlive/2017/texmf-dist/tex/latex/latexconfig
    [...]$ echo $TEXINPUTS /usr/local/texlive/2017/texmf-dist/tex/latex/latexconfig
    [...]$

    注意到,minted.sty 文件的默认路径为 /usr/local/texlive/2017/texmf-dist/tex/latex/minted/minted.sty,而 kpsewhich 命令并不能搜索到它,这是因为 kpsewhich 的搜索目录设置不当;tlmgr 命令返回的参数中有两处错误(红色背景所示),一是 pdftexconfig.tex 的位置未指定,二是 $TEXINPUTS 的内容仅由系统的环境变量所指定,而不会使用 TexLive 默认的目录设置(TexLive 专用的树形目录结构 TDS)。特别指出,tlmgr 命令的第二个错误写道:“==== kpathsea variables from environment only (ok if no output here) ====”,以后可以利用这里的输出字段来查询是否定义了冲突的系统变量。

    接下来,修改 TexLive 2017 环境变量的设置文件,并且更新 TexLive 的设置。

    [...]$ vi ~/Documents/texlive2017.sh
    #!/bin/bash
    # setting for TexLive 2017 environment variables, edit by She
    export PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/texlive/2017/bin/x86_64-linux
    export MANPATH=/usr/local/texlive/2017/texmf-dist/doc/man:$MANPATH
    export INFOPATH=/usr/local/texlive/2017/texmf-dist/doc/info:$INFOPATH
    
    [...]$ sudo cp ~/Documents/texlive2017.sh /etc/profile.d/texlive2017.sh
    [...]$ source /etc/profile.d/texlive2017.sh
    [...]$ sudo texhash

    注销,再重新登录。

    此时,查询这个变量 $TEXINPUTS 是否有值,再重复之前的 pdflatex 编译工作,可以看到 pdflatex 命令运行正常,可以生成相应的 test.pdf 文件:

    [...]$ echo $TEXINPUTS
    
    [...]$ pdflatex test.tex
    This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017) (preloaded format=pdflatex)
     restricted write18 enabled.
    entering extended mode
    (./test.tex
    LaTeX2e <2017-04-15>
    Babel <3.12> and hyphenation patterns for 84 language(s) loaded.
    (/usr/local/texlive/2017/texmf-dist/tex/latex/base/article.cls
    Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
    (/usr/local/texlive/2017/texmf-dist/tex/latex/base/size10.clo)) (./test.aux)
    [1{/usr/local/texlive/2017/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
    (./test.aux) )</usr/local/texlive/2017/texmf-dist/fonts/type1/public/amsfonts/c
    m/cmr10.pfb></usr/local/texlive/2017/texmf-dist/fonts/type1/public/amsfonts/cm/
    cmr7.pfb>
    Output written on test.pdf (1 page, 19263 bytes).
    Transcript written on test.log.

    而且,tlmgr 工具的参数以及 kpsewhich 查询测试均正常,结果如下:

    [...]$ kpsewhich --show-path=.sty
    .:/home/She/.texlive2017/texmf-config/tex/kpsewhich//:/home/She/.texlive2017/texmf-var/tex/kpsewhich//:/home/She/texmf/tex/kpsewhich//:!!/usr/local/texlive/texmf-local/tex/kpsewhich//:!!/usr/local/texlive/2017/texmf-config/tex/kpsewhich//:!!/usr/local/texlive/2017/texmf-var/tex/kpsewhich//:!!/usr/local/texlive/2017/texmf-dist/tex/kpsewhich//:/home/She/.texlive2017/texmf-config/tex/generic//:/home/She/.texlive2017/texmf-var/tex/generic//:/home/She/texmf/tex/generic//:!!/usr/local/texlive/texmf-local/tex/generic//:!!/usr/local/texlive/2017/texmf-config/tex/generic//:!!/usr/local/texlive/2017/texmf-var/tex/generic//:!!/usr/local/texlive/2017/texmf-dist/tex/generic//:/home/She/.texlive2017/texmf-config/tex///:/home/She/.texlive2017/texmf-var/tex///:/home/She/texmf/tex///:!!/usr/local/texlive/texmf-local/tex///:!!/usr/local/texlive/2017/texmf-config/tex///:!!/usr/local/texlive/2017/texmf-var/tex///:!!/usr/local/texlive/2017/texmf-dist/tex///
    [...]$ kpsewhich --show-path=.fmt
    .:/home/She/.texlive2017/texmf-config/web2c/unsetengine:/home/She/.texlive2017/texmf-var/web2c/unsetengine:/home/She/texmf/web2c/unsetengine:!!/usr/local/texlive/texmf-local/web2c/unsetengine:!!/usr/local/texlive/2017/texmf-config/web2c/unsetengine:!!/usr/local/texlive/2017/texmf-var/web2c/unsetengine:!!/usr/local/texlive/2017/texmf-dist/web2c/unsetengine:/home/She/.texlive2017/texmf-config/web2c:/home/She/.texlive2017/texmf-var/web2c:/home/She/texmf/web2c:!!/usr/local/texlive/texmf-local/web2c:!!/usr/local/texlive/2017/texmf-config/web2c:!!/usr/local/texlive/2017/texmf-var/web2c:!!/usr/local/texlive/2017/texmf-dist/web2c
    [...]$ which kpsewhich
    /usr/local/texlive/2017/bin/x86_64-linux/kpsewhich
    [...]$ kpsewhich minted.sty
    /usr/local/texlive/2017/texmf-dist/tex/latex/minted/minted.sty
    [...]$ kpsewhich pdflatex.fmt
    [...]$ kpsewhich pdflatex.ini
    /usr/local/texlive/2017/texmf-dist/tex/latex/latexconfig/pdflatex.in
    [...]$ tlmgr conf =========================== version information ========================== tlmgr revision 44836 (2017-07-18 01:59:48 +0200) tlmgr using installation: /usr/local/texlive/2017 TeX Live (http://tug.org/texlive) version 2017 ==================== executables found by searching PATH ================= PATH: /usr/local/texlive/2017/bin/x86_64-linux:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/opt/pgi/linux86-64/17.4/bin:/home/She/.local/bin:/home/She/bin:/usr/local/texlive/2017/bin/x86_64-linux:/opt/pgi/linux86-64/17.4/bin:/home/She/.local/bin:/home/She/bin:/usr/local/texlive/2017/bin/x86_64-linux kpsewhich: /usr/local/texlive/2017/bin/x86_64-linux/kpsewhich updmap: /usr/local/texlive/2017/bin/x86_64-linux/updmap fmtutil: /usr/local/texlive/2017/bin/x86_64-linux/fmtutil tlmgr: /usr/local/texlive/2017/bin/x86_64-linux/tlmgr tex: /usr/local/texlive/2017/bin/x86_64-linux/tex pdftex: /usr/local/texlive/2017/bin/x86_64-linux/pdftex mktexpk: /usr/local/texlive/2017/bin/x86_64-linux/mktexpk dvips: /usr/local/texlive/2017/bin/x86_64-linux/dvips dvipdfmx: /usr/local/texlive/2017/bin/x86_64-linux/dvipdfmx =========================== active config files ========================== texmf.cnf: /usr/local/texlive/2017/texmf.cnf texmf.cnf: /usr/local/texlive/2017/texmf-dist/web2c/texmf.cnf updmap.cfg: /usr/local/texlive/2017/texmf-dist/web2c/updmap.cfg fmtutil.cnf: /usr/local/texlive/2017/texmf-dist/web2c/fmtutil.cnf config.ps: /usr/local/texlive/2017/texmf-dist/dvips/config/config.ps mktex.cnf: /usr/local/texlive/2017/texmf-dist/web2c/mktex.cnf pdftexconfig.tex: /usr/local/texlive/2017/texmf-dist/tex/generic/tex-ini-files/pdftexconfig.tex ============================= font map files ============================= psfonts.map: /usr/local/texlive/2017/texmf-var/fonts/map/dvips/updmap/psfonts.map pdftex.map: /usr/local/texlive/2017/texmf-var/fonts/map/pdftex/updmap/pdftex.map ps2pk.map: /usr/local/texlive/2017/texmf-var/fonts/map/dvips/updmap/ps2pk.map kanjix.map: /usr/local/texlive/2017/texmf-var/fonts/map/dvipdfmx/updmap/kanjix.map =========================== kpathsea variables =========================== TEXMFMAIN=/usr/local/texlive/2017/texmf-dist TEXMFDIST=/usr/local/texlive/2017/texmf-dist TEXMFLOCAL=/usr/local/texlive/texmf-local TEXMFSYSVAR=/usr/local/texlive/2017/texmf-var TEXMFSYSCONFIG=/usr/local/texlive/2017/texmf-config TEXMFVAR=/home/She/.texlive2017/texmf-var TEXMFCONFIG=/home/She/.texlive2017/texmf-config TEXMFHOME=/home/She/texmf VARTEXFONTS=/home/She/.texlive2017/texmf-var/fonts TEXMF={{}/home/She/.texlive2017/texmf-config,/home/She/.texlive2017/texmf-var,/home/She/texmf,!!/usr/local/texlive/texmf-local,!!/usr/local/texlive/2017/texmf-config,!!/usr/local/texlive/2017/texmf-var,!!/usr/local/texlive/2017/texmf-dist} SYSTEXMF=/usr/local/texlive/2017/texmf-var:/usr/local/texlive/texmf-local:/usr/local/texlive/2017/texmf-dist TEXMFDBS={!!/usr/local/texlive/texmf-local,!!/usr/local/texlive/2017/texmf-config,!!/usr/local/texlive/2017/texmf-var,!!/usr/local/texlive/2017/texmf-dist} WEB2C={{}/home/She/.texlive2017/texmf-config,/home/She/.texlive2017/texmf-var,/home/She/texmf,!!/usr/local/texlive/texmf-local,!!/usr/local/texlive/2017/texmf-config,!!/usr/local/texlive/2017/texmf-var,!!/usr/local/texlive/2017/texmf-dist}/web2c TEXPSHEADERS=.:{{}/home/She/.texlive2017/texmf-config,/home/She/.texlive2017/texmf-var,/home/She/texmf,!!/usr/local/texlive/texmf-local,!!/usr/local/texlive/2017/texmf-config,!!/usr/local/texlive/2017/texmf-var,!!/usr/local/texlive/2017/texmf-dist}/{dvips,fonts/{enc,type1,type42,type3}}// TEXCONFIG={{}/home/She/.texlive2017/texmf-config,/home/She/.texlive2017/texmf-var,/home/She/texmf,!!/usr/local/texlive/texmf-local,!!/usr/local/texlive/2017/texmf-config,!!/usr/local/texlive/2017/texmf-var,!!/usr/local/texlive/2017/texmf-dist}/dvips// ENCFONTS=.:{{}/home/She/.texlive2017/texmf-config,/home/She/.texlive2017/texmf-var,/home/She/texmf,!!/usr/local/texlive/texmf-local,!!/usr/local/texlive/2017/texmf-config,!!/usr/local/texlive/2017/texmf-var,!!/usr/local/texlive/2017/texmf-dist}/fonts/enc// TEXFONTMAPS=.:{{}/home/She/.texlive2017/texmf-config,/home/She/.texlive2017/texmf-var,/home/She/texmf,!!/usr/local/texlive/texmf-local,!!/usr/local/texlive/2017/texmf-config,!!/usr/local/texlive/2017/texmf-var,!!/usr/local/texlive/2017/texmf-dist}/fonts/map/{kpsewhich,pdftex,dvips,}// ==== kpathsea variables from environment only (ok if no output here) ====
    [...]$

    小结:通过以上对比,起码有以下两种方法来查看 TexLive 的搜索路径是否正常:

    (1)通过查看  kpsewhich --show-path=.sty  命令的返回结果来判断系统路径是否正常

    # 错误的返回结果
    [...]$ kpsewhich --show-path=.sty
    /usr/local/texlive/2017/texmf-dist/tex/latex/latexconfig
    [...]$ kpsewhich minted.sty
    [...]$
    
    # 正确的返回结果
    [...]$ kpsewhich --show-path=.sty
    .:/home/She/.texlive2017/texmf-config/tex/kpsewhich//:/home/She/.texlive2017/texmf-var/tex/kpsewhich//:/home/She/texmf/tex/kpsewhich//:!!/usr/local/texlive/texmf-local/tex/kpsewhich//:!!/usr/local/texlive/2017/texmf-config/tex/kpsewhich//:!!/usr/local/texlive/2017/texmf-var/tex/kpsewhich//:!!/usr/local/texlive/2017/texmf-dist/tex/kpsewhich//:/home/She/.texlive2017/texmf-config/tex/generic//:/home/She/.texlive2017/texmf-var/tex/generic//:/home/She/texmf/tex/generic//:!!/usr/local/texlive/texmf-local/tex/generic//:!!/usr/local/texlive/2017/texmf-config/tex/generic//:!!/usr/local/texlive/2017/texmf-var/tex/generic//:!!/usr/local/texlive/2017/texmf-dist/tex/generic//:/home/She/.texlive2017/texmf-config/tex///:/home/She/.texlive2017/texmf-var/tex///:/home/She/texmf/tex///:!!/usr/local/texlive/texmf-local/tex///:!!/usr/local/texlive/2017/texmf-config/tex///:!!/usr/local/texlive/2017/texmf-var/tex///:!!/usr/local/texlive/2017/texmf-dist/tex///
    [...]$ kpsewhich minted.sty
    /usr/local/texlive/2017/texmf-dist/tex/latex/minted/minted.sty
    [...]$

    (2)通过查看  命令的返回结果来准确判断,各个变量的值必须要准确赋值,而且在最后一行的内容不能为空

    [...]$ tlmgr conf
    ...
    =========================== active config files ==========================
    ...
    pdftexconfig.tex: /usr/local/texlive/2017/texmf-dist/tex/generic/tex-ini-files/pdftexconfig.tex # pdftexconfig.tex的路径必须查询到,否则会出错
    ============================= font map files =============================
    ...
    =========================== kpathsea variables ===========================
    ...
    ==== kpathsea variables from environment only (ok if no output here) ==== # 这一行之后列出的是冲突的系统变量名,如无,则一切正常;如有,则找到并注释掉它
    TEXINPUTS=/usr/local/texlive/2017/texmf-dist/tex/latex/latexconfig # 这里不能有冲突的系统变量,如有,则需要找到该变量的设置部分,并注释掉它或者删去它

    更详细的 Kpathsea 有关的参数设置,可以查看TexLive 的官方说明文档:https://www.tug.org/texlive/doc/texlive-zh-cn/texlive-zh-cn.pdf。

  • 相关阅读:
    JavaAndroid项目结构
    Python 常用系统模块整理
    Python 部分系统类的常用方法整理
    xpath语法笔记
    xml笔记
    Python 内置函数笔记
    剑指Offer-二叉搜索树的第k个结点
    Java中Set集合是如何实现添加元素保证不重复的?
    剑指Offer-链表中倒数第k个结点
    Leetcode#1.Two Sum(两数之和)
  • 原文地址:https://www.cnblogs.com/snake553/p/7234545.html
Copyright © 2011-2022 走看看