lualatex と自動 inkscape インポートを組み合わせた tikz 外部化

lualatex と自動 inkscape インポートを組み合わせた tikz 外部化

たくさんの図を含む巨大なドキュメントがあります。プロットについては、matlab を使用し、matlab2tikz を使用してプロットを tikz に変換します (その後、いくつかの変更を行います)。他のほとんどの図については、Inkscape とその pdf_tex エクスポートを好みます。tikz と Inkscape の両方で、図内で何かが変更された場合は、図が自動的に再生成されるようにしたいと思います。そのために、\includetikz と \includesvg という 2 つのカスタム コマンドがあります。tikz 図のために pdflatex から lualatex に変更するまでは、すべて非常にうまく機能していました。データをこれ以上削減できないプロットがいくつかあり、pdflatex ではこれらの図をタイプセットできませんでした (メモリ設定も増加しました)。lualatex では、これは非常にうまく機能しました。現在の問題は、lualatex の \includetikz コマンドが何らかの理由で \includesvg コマンドに干渉することです。

私の MWE は次のとおりです:

\documentclass[11pt,a4paper,english]{scrbook}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\RequirePackage{luatex85}

% inkscape
\usepackage{import}
\newcommand{\executeiffilenewer}[3]{%
    \ifnum\pdfstrcmp{\pdffilemoddate{#1}}%
    {\pdffilemoddate{#2}}>0%
    {#3}\fi%
}
\newcommand{\includesvg}[2]{%
    \immediate\write18{if not exist #1.svg_external/ (mkdir "#1.svg_external/")}%
    \executeiffilenewer{#1#2.svg}{#1.svg_external/#2.pdf}{%
        \immediate\write18{"C:/Program Files (x86)/Inkscape/inkscape.exe" -z -C --file=#1#2.svg --export-pdf=#1.svg_external/#2.pdf --export-latex}}%
    \import{#1.svg_external/}{#2.pdf_tex}%
}

\usepackage{filemod}
\newlength{\figheight}
\newlength{\figwidth}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\pgfplotsset{compat=1.14}
\tikzexternalize % activate externalization
\tikzset{external/system call={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}
\tikzset{external/figure list=true}
\tikzset{external/up to date check=simple}
\newcommand{\tikzcustomremake}[2]{\tikzset{external/remake next}}
\newcommand{\includetikz}[2]{%
    \tikzsetnextfilename{#1.tikz_external/#2}%
    \filemodCmp{#1#2.tikz}{#1.tikz_external/#2.pdf}%
    {\tikzcustomremake{#1}{#2}}{}%
    \input{#1#2.tikz}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\begin{document}

\figwidth=5cm
\figheight=5cm
\includetikz{fig/ch1/}{plot2}

%\footnotesize\includesvg{fig/ch1/}{inkscape1}

\end{document}

残念ながら、Inkscape コマンドには絶対パスが含まれているため、変更する必要があるかもしれません。plot2.tikz のコードは次のとおりです。

\begin{tikzpicture}
\begin{axis}[%
width=\figwidth,
height=\figheight,
xmin=0,xmax=10,
xlabel=\pgfactualjobname,
ymin=-1,ymax=5,
axis background/.style={fill=white}
]
\addplot [color=red,solid,forget plot]
  table[row sep=crcr]{%
0   0\\
10  1\\
};
\end{axis}
\end{tikzpicture}%

inkscape1.svg ファイルは任意の SVG にすることができます。例:https://de.wikipedia.org/wiki/LaTeX#/media/File:LaTeX_logo.svg

私の現在の問題: コードをそのまま実行すると、すべて正常に動作します。 svg はコメント アウトされ、結果の pdf にはプロットのみが含まれます。 その後、\includesvg コマンドのコメントを削除すると、すべて正常に動作します。 pdf_tex が生成され、pdf には両方の図が含まれます。 ただし、tikz ファイルにいくつかの変更を加えて図を再生成する必要がある場合、lualatex は失敗します。

ログファイルは私にとって何の役にも立ちません。メイン ドキュメントのログファイルでは、エラー部分は次のとおりです。

Writing 'fig/ch1/.tikz_external/plot2' to 'diss01lua.figlist'.
\openout3 = `diss01lua.auxlock'.

===== 'mode=convert with system call': Invoking 'lualatex -shell-escape -halt-o
n-error -interaction=batchmode -jobname "fig/ch1/.tikz_external/plot2" "\def\ti
kzexternalrealjob{diss01lua}\input{diss01lua}"' ========
runsystem(lualatex -shell-escape -halt-on-error -interaction=batchmode -jobname
 "fig/ch1/.tikz_external/plot2" "\def\tikzexternalrealjob{diss01lua}\input{diss
01lua}")...executed.

\openout3 = `diss01lua.auxlock'.


! Package tikz Error: Sorry, the system call 'lualatex -shell-escape -halt-on-e
rror -interaction=batchmode -jobname "fig/ch1/.tikz_external/plot2" "\def\tikze
xternalrealjob{diss01lua}\input{diss01lua}"' did NOT result in a usable output 
file 'fig/ch1/.tikz_external/plot2' (expected one of .pdf:.jpg:.jpeg:.png:). Pl
ease verify that you have enabled system calls. For pdflatex, this is 'pdflatex
 -shell-escape'. Sometimes it is also named 'write 18' or something like that. 
Or maybe the command simply failed? Error messages can be found in 'fig/ch1/.ti
kz_external/plot2.log'. If you continue now, I'll try to typeset the picture.

See the tikz package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.16 \end{tikzpicture}
                      %
This error message was generated by an \errmessage
command, so I can't give any explicit help.
Pretend that you're Hercule Poirot: Examine all clues,
and deduce the truth by order and method.

plot2 のログファイルの最後の行は次のとおりです。

LaTeX Font Info:    External font `lmex10' loaded for size
(Font)              <10.95> on input line 15.
LaTeX Font Info:    External font `lmex10' loaded for size
(Font)              <8> on input line 15.
LaTeX Font Info:    External font `lmex10' loaded for size
(Font)              <6> on input line 15.
[1

{C:/ProgramData/MiKTeX/2.9/pdftex/config/pdftex.map}])
if not exist fig/ch1/.svg_external/ (mkdir "fig/ch1/.svg_external/")
! Undefined control sequence.
\executeiffilenewer #1#2#3->\ifnum \pdfstrcmp 
                                              {\pdffilemoddate {#1}}{\pdffil...
l.51 \footnotesize\includesvg{fig/ch1/}{inkscape1}


Here is how much of LuaTeX's memory you used:
 25909 strings out of 494568
 100000,953878 words of node,token memory allocated
 1158 words of node memory still in use:
   4 hlist, 1 rule, 7 disc, 1 local_par, 1 dir, 23 glue, 4 kern, 2 penalty, 85 g
lyph, 7 attribute, 47 glue_spec, 7 attribute_list, 1 if_stack nodes
   avail lists: 2:739,3:212,4:5,5:13,7:182,8:2,9:78,10:1
 29028 multiletter control sequences out of 65536+200000
 27 fonts using 1573183 bytes
 65i,11n,111p,8876b,1869s stack positions out of 5000i,500n,10000p,200000b,50000s
!  ==> Fatal error occurred, no output PDF file produced!

興味深いのは、lualatex が何らかの形で inkscape のものを認識しているということですが、これは理解できません。

完全なログファイルをここにアップロードしましたので、ご参考になれば幸いです。http://www.uni-ulm.de/~pqa62/tex/

この動作を修正する方法を知っている人はいますか? 外部化と自動再構築を行った方法がとても気に入りました。特に、include コマンドを完全に実現することで、より高度な機能がカバーされ、lualatex に切り替えるまではすべて機能していたためです。

編集:

さらにいくつかテストを行った結果、カスタム コマンドが\executeiffilenewer問題で、エラーが発生する原因になっていることがわかりました。どういうわけか、lualatex (tikz-plot のみをタイプセットするはず) は次の\includesvgコマンドも調べて実行しようとします。ここでは、このカスタム コマンドは呼び出し内で定義されていないため、認識されません。コマンドを\includesvg次のように変更します。

\newcommand{\includesvg}[2]{%
    \immediate\write18{"C:/Program Files (x86)/Inkscape/inkscape.exe" -z -C --file=#1#2.svg --export-pdf=#1.svg_external/#2.pdf --export-latex}%
    \import{#1.svg_external/}{#2.pdf_tex}%
}

もうエラーは発生しません。問題は、常に Inkscape が実行されることにあります。それでも、tikz-plot が完了した後も lualatex が停止しない理由がわかりません。

答え1

-interaction=batchmodeに変更して-interaction=scrollmode、ドキュメントにエラーや\showコマンドを追加すると、luatex の実行によって tex ファイル全体がコンパイルされることがわかります。また、この間にコマンドが展開されます。\includetikz 内で画像を見つけることができるため、当然 \includesvg 内も調べる必要があります。つまり、luatex に認識されないコマンドによって問題が発生する可能性があります。

\pdfstrcmpluatexでは定義されていません。pdftexcmdsパッケージをロードして実装を取得できます。https://tex.stackexchange.com/a/158612/2388注意: pdftexcmds が luatex 0.95/1.0 に適合しているかどうかは確認していませんが、私の簡略化された例では動作しているようです。

\documentclass[11pt,a4paper,english]{scrbook}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{ifluatex}
\ifluatex
\RequirePackage{luatex85}
\usepackage{pdftexcmds}
  \makeatletter
  \let\pdfstrcmp\pdf@strcmp
  \let\pdffilemoddate\pdf@filemoddate
  \makeatother
\fi

\newcommand{\includesvg}{\pdfstrcmp{1}{2}}

\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize % activate externalization
\tikzset{external/system call={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}
\tikzset{external/force remake}

\newcommand{\includetikz}{%
 \begin{tikzpicture}
  \draw[red](0,0)--(1,1);
 \end{tikzpicture}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\begin{document}

blub 

\includesvg

\includetikz

\end{document}

関連情報