latexmk 指定输出目录

latexmk 指定输出目录

latexmk版本是Latexmk, John Collins, 17 Jan. 2018. Version 4.55,操作系统是WindowsMiKTeX2.9我使用的控制台模拟器康德,其中包括 perl。perl 版本是perl5 (revision 5 version 24 subversion 1)

这是我的文件夹结构:

top_dir
|-main.tex
|-charpter1
  |-chap1.tex
|-charpter2
  |-chap2.tex
|-reference
  |-ref.tex
  |-ref_db.bib

我的main.tex样子是:

\documentclass[oneside,a4paper]{book}

\begin{document}

\include{chapter1/chap1}
\include{chapter2/chap2}
\include{reference/ref}

\end{document}

与此同时,在ref.tex

\clearpage
\bibliographystyle{unsrt}
\bibliography{reference/ref_db}

其他文件为空。

我可以使用以下命令获得所有正确的信息:

latexmk -pdf -bibtex --interaction=nonstopmode -pdflatex="pdflatex %O %S"

但是,我想将所有输出更改为output dir,然后将构建命令更改为:

latexmk -pdf -bibtex --interaction=nonstopmode -outdir=build -pdflatex="pdflatex -output-directory=build %O %S"

它确实可以生成输出目录build,但是在生成引用时会失败,它说:

latexmk -pdf -bibtex -outdir=build --interaction=nonstopmode -pdflatex="pdflatex %O %S"
Latexmk: This is Latexmk, John Collins, 17 Jan. 2018, version: 4.55.
Latexmk: making output directory 'build'
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': Rules & subrules not known to be previously run:
   pdflatex
Rule 'pdflatex': The following rules & subrules became out-of-date:
      'pdflatex'
------------
Run number 1 of rule 'pdflatex'
------------
Latexmk: I am working around an offset relative to my system time by
   -167 secs for file times in directory 'build/'.
------------
Running 'pdflatex  --interaction=nonstopmode -recorder -output-directory="build"  "main.tex"'
------------
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6500 64-bit)
entering extended mode
(main.tex
LaTeX2e <2017-04-15>
Babel <3.15> and hyphenation patterns for 75 language(s) loaded.
("C:\Program Files\MiKTeX 2.9\tex\latex\base\book.cls"
Document Class: book 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex\latex\base\bk10.clo"))
(Y:\Latex\latexmk_test\build\main.aux) (chapter1/chap1.tex) (chapter2/chap2.tex
) (reference/ref.tex
No file main.bbl.
) (Y:\Latex\latexmk_test\build\main.aux
(Y:\Latex\latexmk_test\build\chapter1/chap1.aux)
(Y:\Latex\latexmk_test\build\chapter2/chap2.aux)
(Y:\Latex\latexmk_test\build\reference/ref.aux)) )
No pages of output.
Transcript written on Y:\Latex\latexmk_test\build\main.log.
=== TeX engine is 'pdfTeX'
Latexmk: Non-existent bbl file 'build/main.bbl'
 No file main.bbl.
Latexmk: Log file says no output from latex
Latexmk: For rule 'pdflatex', no output was made
Latexmk: Found bibliography file(s) [reference/ref_db.bib]
Latexmk: applying rule 'bibtex build/main'...
Rule 'bibtex build/main': File changes, etc:
   Changed files, or newly in use since previous run(s):
      'build/main.aux'
   Non-existent destination files:
      'build/main.bbl'
------------
Run number 1 of rule 'bibtex build/main'
------------
For rule 'bibtex build/main', running '&run_bibtex(  )' ...
------------
Running 'bibtex  "main"'
------------
This is BibTeX, Version 0.99d (MiKTeX 2.9.6500 64-bit)
The top-level auxiliary file: main.aux
A level-1 auxiliary file: chapter1/chap1.aux
A level-1 auxiliary file: chapter2/chap2.aux
A level-1 auxiliary file: reference/ref.aux
The style file: unsrt.bst
I couldn't open database file reference/ref_db.bib
---line 3 of file reference/ref.aux
 : \bibdata{reference/ref_db
 :                          }
I'm skipping whatever remains of this command
I found no \citation commands---while reading file main.aux
I found no database files---while reading file main.aux
(There were 3 error messages)
Latexmk: Errors, so I did not complete making targets
Collected error summary (may duplicate other messages):
  bibtex build/main: Bibtex errors: See file 'build/main.blg'
  pdflatex: failed to create output file
Latexmk: Use the -f option to force complete processing,
 unless error was exceeding maximum runs of latex/pdflatex.

这是没有“build”输出文件夹的编译结果

 latexmk -pdf -bibtex --interaction=nonstopmode -pdflatex="pdflatex %O %S"
Latexmk: This is Latexmk, John Collins, 17 Jan. 2018, version: 4.55.
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': Rules & subrules not known to be previously run:
   pdflatex
Rule 'pdflatex': The following rules & subrules became out-of-date:
      'pdflatex'
------------
Run number 1 of rule 'pdflatex'
------------
Latexmk: I am working around an offset relative to my system time by
   -166 secs for file times in directory ''.
------------
Running 'pdflatex  --interaction=nonstopmode -recorder  "main.tex"'
------------
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6500 64-bit)
entering extended mode
(main.tex
LaTeX2e <2017-04-15>
Babel <3.15> and hyphenation patterns for 75 language(s) loaded.
("C:\Program Files\MiKTeX 2.9\tex\latex\base\book.cls"
Document Class: book 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex\latex\base\bk10.clo")) (main.aux)
(chapter1/chap1.tex) (chapter2/chap2.tex) (reference/ref.tex
No file main.bbl.
) (main.aux (chapter1/chap1.aux) (chapter2/chap2.aux) (reference/ref.aux)) )
No pages of output.
Transcript written on main.log.
=== TeX engine is 'pdfTeX'
Latexmk: Non-existent bbl file 'main.bbl'
 No file main.bbl.
Latexmk: Log file says no output from latex
Latexmk: For rule 'pdflatex', no output was made
Latexmk: Found bibliography file(s) [reference/ref_db.bib]
Latexmk: applying rule 'bibtex main'...
Rule 'bibtex main': File changes, etc:
   Changed files, or newly in use since previous run(s):
      'main.aux'
   Non-existent destination files:
      'main.bbl'
------------
Run number 1 of rule 'bibtex main'
------------
For rule 'bibtex main', running '&run_bibtex(  )' ...
------------
Running 'bibtex  "main"'
------------
This is BibTeX, Version 0.99d (MiKTeX 2.9.6500 64-bit)
The top-level auxiliary file: main.aux
A level-1 auxiliary file: chapter1/chap1.aux
A level-1 auxiliary file: chapter2/chap2.aux
A level-1 auxiliary file: reference/ref.aux
The style file: unsrt.bst
I found no \citation commands---while reading file main.aux
Database file #1: reference/ref_db.bib
(There was 1 error message)
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': File changes, etc:
   Changed files, or newly in use since previous run(s):
      'chapter1/chap1.aux'
      'chapter2/chap2.aux'
      'main.aux'
      'main.bbl'
      'reference/ref.aux'
------------
Run number 2 of rule 'pdflatex'
------------
------------
Running 'pdflatex  --interaction=nonstopmode -recorder  "main.tex"'
------------
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6500 64-bit)
entering extended mode
(main.tex
LaTeX2e <2017-04-15>
Babel <3.15> and hyphenation patterns for 75 language(s) loaded.
("C:\Program Files\MiKTeX 2.9\tex\latex\base\book.cls"
Document Class: book 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex\latex\base\bk10.clo")) (main.aux
(chapter1/chap1.aux) (chapter2/chap2.aux) (reference/ref.aux))
(chapter1/chap1.tex) (chapter2/chap2.tex) (reference/ref.tex (main.bbl

LaTeX Warning: Empty `thebibliography' environment on input line 3.

)) [1{C:/Users/haochen/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}]
(main.aux (chapter1/chap1.aux) (chapter2/chap2.aux) (reference/ref.aux)) )<C:/P
rogram Files/MiKTeX 2.9/fonts/type1/public/amsfonts/cm/cmbx12.pfb><C:/Program F
iles/MiKTeX 2.9/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on main.pdf (1 page, 17996 bytes).
Transcript written on main.log.
=== TeX engine is 'pdfTeX'
Latexmk: Found input bbl file 'main.bbl'
Latexmk: Log file says output to 'main.pdf'
Latexmk: Found bibliography file(s) [reference/ref_db.bib]
Latexmk: applying rule 'bibtex main'...
Rule 'bibtex main': File changes, etc:
   Changed files, or newly in use since previous run(s):
      'reference/ref.aux'
------------
Run number 2 of rule 'bibtex main'
------------
For rule 'bibtex main', running '&run_bibtex(  )' ...
------------
Running 'bibtex  "main"'
------------
This is BibTeX, Version 0.99d (MiKTeX 2.9.6500 64-bit)
The top-level auxiliary file: main.aux
A level-1 auxiliary file: chapter1/chap1.aux
A level-1 auxiliary file: chapter2/chap2.aux
A level-1 auxiliary file: reference/ref.aux
The style file: unsrt.bst
I found no \citation commands---while reading file main.aux
Database file #1: reference/ref_db.bib
(There was 1 error message)
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': File changes, etc:
   Changed files, or newly in use since previous run(s):
      'reference/ref.aux'
------------
Run number 3 of rule 'pdflatex'
------------
------------
Running 'pdflatex  --interaction=nonstopmode -recorder  "main.tex"'
------------
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6500 64-bit)
entering extended mode
(main.tex
LaTeX2e <2017-04-15>
Babel <3.15> and hyphenation patterns for 75 language(s) loaded.
("C:\Program Files\MiKTeX 2.9\tex\latex\base\book.cls"
Document Class: book 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex\latex\base\bk10.clo")) (main.aux
(chapter1/chap1.aux) (chapter2/chap2.aux) (reference/ref.aux))
(chapter1/chap1.tex) (chapter2/chap2.tex) (reference/ref.tex (main.bbl

LaTeX Warning: Empty `thebibliography' environment on input line 3.

)) [1{C:/Users/haochen/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}]
(main.aux (chapter1/chap1.aux) (chapter2/chap2.aux) (reference/ref.aux)) )<C:/P
rogram Files/MiKTeX 2.9/fonts/type1/public/amsfonts/cm/cmbx12.pfb><C:/Program F
iles/MiKTeX 2.9/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on main.pdf (1 page, 17996 bytes).
Transcript written on main.log.
=== TeX engine is 'pdfTeX'
Latexmk: Found input bbl file 'main.bbl'
Latexmk: Log file says output to 'main.pdf'
Latexmk: Found bibliography file(s) [reference/ref_db.bib]
Latexmk: All targets (main.pdf) are up-to-date

答案1

出现该问题的原因是 OP 将 msys 及其 Perl 与 bibtex 的本机 MS-Windows 实现(在 MiKTeX 中)一起使用。

有两种解决方案

  1. 更新至 latexmk 4.56(文件传播到镜像站点后,它将出现在 CTAN 上,然后会出现在标准发行版 TeXLive 和 MiKTeX 中)。它也可以在此处获取http://personal.psu.edu/jcc8/latexmk/

  2. 安装原生 MS-Windows Perl,并确保它能够运行 latexmk。

引擎盖下的细节(这可能对有相关问题的用户有用):Msys 和 MinGW 在 MS-Windows 之上提供了一个 Unix 模拟层;从 latexmk 的角度来看,实际上存在操作系统的混合,MS-Windows 和 Unix,特别是在文件名方面。latexmk 会使用一些技巧来使 bibtex 在以下情况下工作:(a) 输出目录、(b) 源文档中包含的文件以及 (c) .bib 文件位于文档目录或子目录中。技巧涉及使用 BIBINPUTS 和 BSTINPUTS 设置临时更改目录。Msys 的 Perl 以 Unix 格式提供当前目录的名称,但需要将其(非常简单地)转换为 MS-Windows 格式才能用于 bibtex。事实证明 latexmk 已经为 cygwin 提供了相同问题的解决方案,因此一旦诊断(离线),修复就很容易了。

相关内容