자동 잉크스케이프 가져오기와 함께 lualatex를 사용한 tikz 외부화

자동 잉크스케이프 가져오기와 함께 lualatex를 사용한 tikz 외부화

많은 숫자가 포함된 거대한 문서가 있습니다. 플롯의 경우 matlab을 사용하고 matlab2tikz를 사용하여 플롯을 tikz로 변환합니다(나중에 일부 수정 작업 수행). 대부분의 다른 그림의 경우 Inkscape와 pdf_tex 내보내기를 선호합니다. tikz와 Inkscape 둘 다에서 나는 그림 내에서 무언가 변경된 경우 그림이 자동으로 재생성되도록 하는 것을 좋아합니다. 여기에는 \includetikz와 \includesvg라는 두 가지 사용자 정의 명령이 있습니다. tikz-Figures를 위해 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-command의 주석을 다시 제거하면 모든 것이 잘 작동합니다. 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.

플롯2에 대한 로그 파일의 마지막 줄은 다음과 같습니다.

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-stuff를 본다는 것입니다.

도움이 필요하면 여기에 전체 로그 파일을 업로드했습니다.http://www.uni-ulm.de/~pqa62/tex/

누구든지 아이디어가 있고 이 동작을 수정하는 방법을 알고 있나요? 나는 외부화 및 자동 재구축을 수행하는 방식이 정말 마음에 들었습니다. 특히 포함 명령을 완전히 실현할 때 일부 고급 내용이 다루어지고 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일부 오류나 명령을 추가하면 luatex 실행이 전체 tex 파일을 컴파일하는 것을 볼 수 있습니다. \show그리고 이 동안 명령을 확장합니다. \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}

관련 정보