0

.texSwift を使用してファイルをコンパイルしたかったのです。次のコードがあります。

class FileManager {
    class func compileLatex(#file: String) {
        let task = NSTask()
        task.launchPath = "/usr/texbin/latexmk"
        task.currentDirectoryPath = (NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String).stringByAppendingString("/roster")
        task.arguments = ["-xelatex", file]
        task.launch()
    }
}

ただし、呼び出すFileManager.compileLatex(file: "latex.tex")と、「起動パスにアクセスできません」というエラーが表示されます。どうやら、起動パスが間違っているようですが、それが実際にどれであるかを見つける方法がわかりませんか? どうすれば見つけることができますか、または一般的なパスはありますか? 助けてくれてありがとう

編集:

更新されたコードとこのエラーが発生しました:

Latexmk: This is Latexmk, John Collins, 10 January 2015, version: 4.42.
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'
------------
------------
Running 'xelatex  -recorder  "Praktikumsbericht.tex"'
------------
sh: xelatex: command not found
Latexmk: Errors, so I did not complete making targets
Collected error summary (may duplicate other messages):
  pdflatex: (Pdf)LaTeX failed to generate the expected log file 'Praktikumsbericht.log'
Latexmk: Did not finish processing file 'Praktikumsbericht.tex':
   (Pdf)LaTeX failed to generate the expected log file 'Praktikumsbericht.log'
Latexmk: Use the -f option to force complete processing,
 unless error was exceeding maximum runs of latex/pdflatex.
4

1 に答える 1

1

は、実行可能ファイルのパスに設定する必要があります。launchPathたとえば、

task.launchPath = "/usr/texbin/latexmk"

オプションで、指定したcurrentDirectoryPathディレクトリでタスクを実行するように設定できます。「Documents」ディレクトリは通常、次のように決定されます。

task.currentDirectoryPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString

最後に、arguments実行可能ファイルのコマンド ライン引数です。たとえば、

task.arguments = ["-xelatex", file]

または、次のようなシェルを使用して実行可能ファイルを開始できます。

task.launchPath = "/bin/sh"
task.currentDirectoryPath = ...
task.arguments = ["-c", "latexmk -xelatex \"\(file)\""]

利点は、シェルが PATH 環境変数を使用して実行可能ファイルを見つけることです。欠点の 1 つは、引数を正しく引用することがより困難になることです。

更新: "/usr/texbin" が LaTeX プロセスの PATH に含まれている必要があるようです。これは次のように行うことができます。

// Get current environment:
var env = NSProcessInfo.processInfo().environment
// Get PATH:
var path = env["PATH"] as String
// Prepend "/usr/texbin":
path = "/usr/texbin:" + path
// Put back to environment:
env["PATH"] = path
// And use this as environment for the task:
task.environment = env
于 2015-03-10T18:34:30.337 に答える