Skip to content

Implement the TeX Live engine with latexmk #5

Closed

Description

@nishide-dev

背景

texrun の最初の backend として TeX Live + latexmk を利用する。

互換性を最優先し、一般的な LaTeX 文書や学会テンプレートを既存 TeX 環境と同様にコンパイルできることを目指す。

スコープ

  • TeX Live / latexmk は外部依存として利用する
  • shell を介さず subprocess を起動する
  • 初期 MVP では local installation を前提としてよい
  • engine interface 経由で呼び出す

作業内容

  • latexmk executable の検出
  • workspace を working directory として起動
  • non-interactive な compile option を設定(候補は下記)
  • stdout / stderr を capture
  • exit status を CompileResult に変換
  • PDF artifact を収集
  • timeout 時に子プロセスを停止できるようにする
    • latexmk は pdflatex / bibtex 等を子プロセスとして起動するため、latexmk 単体ではなく process group 単位で kill する(Unix: CommandExt::process_group(0) + killpg)
    • stdout / stderr の読み取りでデッドロックしないよう、pipe は別スレッド等で読み続ける
  • executable が存在しない場合を明確な error にする
  • engine version / latexmk version を取得できる余地を設ける
  • 子プロセスの環境変数を制御する(TEXINPUTS 等の host 由来の変数に意図せず依存しない)

latexmk 引数の候補

latexmk -pdf -norc
        -interaction=nonstopmode -halt-on-error -file-line-error
        -no-shell-escape
        -outdir=<workspace output dir>
        <entrypoint>

pdflatex 以外(xelatex / lualatex)の選択は MVP では option として持たなくてよいが、CompileOptions に追加できる形にしておく。

セキュリティ

引数生成に shell command string を利用しない。

避ける:

sh -c "latexmk ..."

直接 executable と argument array を指定する。

完了条件

  • 最小の article 文書から PDF を生成できる
  • syntax error を含む文書で compile failure を返せる
  • latexmk が存在しない環境で明確なエラーになる
  • timeout が機能し、timeout 後に latexmk / TeX の子プロセスが残らない

依存

Activity

  1. added this to the MVP milestone on Sep 30, 2026
  2. added
    enhancement
    on Sep 30, 2026
  3. nishide-dev commented on Sep 30, 2026

    @nishide-dev
    OwnerAuthor

    PR #20(#3)からの申し送り: engine は compile(&self, ctx: &CompileContext<'_>, req) を実装。最初に req.validate() を呼ぶ契約、ctx.cancel.is_cancelled() を timeout の try_wait poll ループ内で確認し process group を kill、cancel 時は CompileOutcome::Cancelled。argv に path を渡すときは WorkspacePath::to_cli_arg()(先頭 - 対策)を使う。

  4. nishide-dev commented on Sep 30, 2026

    @nishide-dev
    OwnerAuthor

    PR #22(docs/security.md)再レビューからの #5 向け申し送り:

    • texrun 管理 rc の起動用 sub の戻り値仕様を決める(latexmk は internal sub の戻り値を終了コードとして扱う。exec 失敗・signal 終了時の値も定義)
    • internal の引数はダブルクォートを考慮して分割されるため、名前検査で " を拒否するのは引数受け渡しの正しさのためにも必要
    • §3.5 の表に無い latexmk のコマンド変数($xdvipdfmx, $hilatex, $dvips_landscape, $hnt_previewer, $*_update_command 等)もすべて NONE にする
    • Kpsewhich command needed but not set up は stderr に出る(bibtex 使用時のみ)
    • cwd が workspace root のとき、絶対パスで渡した -outdir を latexmk は pdflatex に相対パスで渡す(Normalize LaTeX diagnostics into structured errors and warnings #7 の path 正規化に影響)
    • output dir のサブディレクトリ事前作成時に .texrun 自身は写さない
    • rc 用一時ディレクトリの後始末は Implement the TeX Live engine with latexmk #5 の責務
    • docs/security.md §3.3 の除外リストを feat(workspace): add isolated compile workspaces #21 の実装(fmt/base/mem、.biber.conf、走査上限 40,000)に合わせる
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions