为什么使用 latexmk 指定输出目录编译失败

为什么使用 latexmk 指定输出目录编译失败

我使用以下命令在 MacOS 中编译 latex 文件:

/Library/TeX/texbin/latexmk -pdfxe -pvc -xelatex -interaction=nonstopmode -output-directory="/Users/dolphin/output"

但输出的内容是:

$ /Library/TeX/texbin/latexmk -pdfxe -pvc -xelatex -interaction=nonstopmode -output-directory="/Users/dolphin/output"
Latexmk: This is Latexmk, John Collins, 26 Dec. 2019, version: 4.67.
======= Need to update make_preview_continuous for target files
Viewing pdf
Latexmk: applying rule 'makeindex /Users/dolphin/output/dolphin-book-2020.idx'...
Rule 'makeindex /Users/dolphin/output/dolphin-book-2020.idx': The following rules & subrules became out-of-date:
      'makeindex /Users/dolphin/output/dolphin-book-2020.idx'
------------
Run number 1 of rule 'makeindex /Users/dolphin/output/dolphin-book-2020.idx'
------------
------------
Running 'makeindex  -o "/Users/dolphin/output/dolphin-book-2020.ind" "/Users/dolphin/output/dolphin-book-2020.idx"'
------------

makeindex: Not writing to /Users/dolphin/output/dolphin-book-2020.ind (openout_any = p).
Can't create output index file /Users/dolphin/output/dolphin-book-2020.ind.
Usage: makeindex [-ilqrcgLT] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]
Latexmk: Errors, so I did not complete making targets
Latexmk: Failure to make the files correctly
    ==> You will need to change a source file before I do another run <==
Collected error summary (may duplicate other messages):
  makeindex /Users/dolphin/output/dolphin-book-2020.idx: Command for 'makeindex /Users/dolphin/output/dolphin-book-2020.idx' gave return code 1
      Refer to '/Users/dolphin/output/dolphin-book-2020.ilg' for details

=== Watching for updated files. Use ctrl/C to stop ...

我该怎么做才能让它工作?

答案1

这是一个已知问题,我计划在 latexmk 的下一个版本中纠正它。

同时,您可以将以下内容放入 latexmkrc 文件中:

$makeindex = 'internal run_makeindex %S %D %O';

sub run_makeindex {
  my $return = 999;
  my $source = shift;
  my $dest = shift;
  my @opts = @_;
  my ( $source_base, $source_path ) = fileparse( $source );
  my ( $dest_base, $dest_path ) = fileparse( $dest );
  # Paths for source and dest should have been made the same.
  # That's the way latexmk works.

  pushd( $source_path );
  if (!$silent) {
      print "$My_name: Changing directory to '$path'\n",
            "    before running makeindex.\n";
  }
  my @cmd_line = ('makeindex', @options, '-o', $dest_base, $source_base );
  print "$My_name: Running external command '@cmd_line'\n";
  $return = system( @cmd_line );
  popd();
  if (!$silent) {
    print "$My_name: changed directory back to '", cwd(), "'\n";
  }

  return $return;
}

这只是在运行 makeindex 之前将目录更改为输出目录,然后调用 makeindex,文件中没有任何路径组件。事实上,这是 latexmk 在运行 bibtex 时已经做/可以做的事情。

相关内容