TIKZ ファイル名とパス変数を使用して外部化

TIKZ ファイル名とパス変数を使用して外部化

次のような問題があります。いくつかの章がある大きなLaTeXプロジェクトproject.tex。これらの章ごとに、tikz_pdfフォルダーに外部化したいtikz画像がいくつかあります。ファイル構造はそれに応じて

home/chapter/chapter1/img/example_1.tikz
home/chapter/chapter1/img/example_2.tikz
home/project.tex
home/tikz_pdf

大きなプロジェクトなので、マクロを使用して外部化を自動化したいと考えています。

\includetikz{chapter/chapter1/img/example_1.tikz}

の代わりに

\input{chapter/chapter1/img/example_1.tikz}

/tikz_pdf に作成された pdf で同じ tikz ファイル名を取得するためです。したがって、「chapter/chapter1/img/example1.tikz」の外部化された pdf は「home/tikz_pdf/example1.pdf」になります。この目的のために、次のように適用できるマクロを使用したいと思います。

    \documentclass[12pt,lot, lof]{puthesis}
    \usepackage{filemod}
    \usepackage{pgfplots}    
    \pgfplotsset{compat=newest}
    \pgfplotsset{plot coordinates/math parser=false}
    \usepackage{tikz}
    \usetikzlibrary{external}
    \tikzexternalize[prefix=tikz/]

    % THIS IS THE MACRO
    \makeatletter
    \DeclareRobustCommand{\includetikz}[1]{%
     \begingroup
      \def\textendash{-}%
      \includetikz@parse{#1}%
      \edef\includetikz@base{\detokenize\expandafter{\includetikz@base}}%
      \tikzsetnextfilename{\filename@base}%
      \input{#1}%
     \endgroup
    }
    \makeatother

    \begin{document}
      \begin{figure}
        \includetikz{chapter/chapter1/img/example_1.tikz}
      \end{figure}
      \begin{figure}
        \includetikz{chapter/chapter1/img/example_2.tikz}
      \end{figure}
    \end{document}

しかし、これまでのところ、ファイル名にアンダースコアが含まれているため、\input{#1} では $ が抜けているというエラーしか発生しません。\input{\detokanize{#1}} の使用をすでに試みましたが、結果は改善されませんでした。この問題を解決する方法をご存知ですか? どうもありがとうございます。

関連情報