externalización de tikz usando lualatex en combinación con una importación automática de inkscape

externalización de tikz usando lualatex en combinación con una importación automática de inkscape

Tengo un documento enorme con muchas cifras. Para los gráficos, uso matlab y los convierto a tikz usando matlab2tikz (y luego hago algunas modificaciones), para la mayoría de las otras figuras, prefiero Inkscape y su exportación pdf_tex. Tanto para tikz como para Inkscape, me gusta que las figuras se regeneren automáticamente si algo cambia dentro de la figura. Tengo dos comandos personalizados para eso, \includetikz y \includesvg. Todo funcionó muy bien hasta que tuve que cambiar de pdflatex a lualatex para las figuras tikz. Tengo algunas parcelas en las que no puedo reducir más los datos y no logré componer estas figuras con pdflatex (también con configuraciones de memoria aumentadas). Con lualatex esto funcionó bastante bien. El problema ahora es que el comando \includetikz con lualatex de alguna manera interfiere con mi comando \includesvg.

Tengo el siguiente 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}

Desafortunadamente, el comando Inkscape contiene su ruta absoluta, por lo que es posible que desee cambiarla. el código para plot2.tikz es el siguiente:

\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}%

el archivo inkscape1.svg puede ser cualquier svg, por ejemplo:https://de.wikipedia.org/wiki/LaTeX#/media/File:LaTeX_logo.svg

Mi problema ahora: si ejecuto el código tal como está, todo funciona bien. El svg está comentado y el pdf resultante solo contiene el gráfico. Luego, eliminando nuevamente el comentario del comando \includesvg, todo funciona bien. Se genera el pdf_tex y en el pdf están ambas figuras. Sin embargo, si hago algunos cambios en el archivo tikz, como que la figura debe regenerarse, lualatex falla.

Los archivos de registro no me son de ninguna ayuda. En el archivo de registro del documento principal, la parte del error es la siguiente:

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.

en las últimas líneas del archivo de registro de plot2 están:

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!

Lo que encuentro interesante es que lualatex de alguna manera ve las cosas de Inkscape, lo cual no entiendo.

Subí los archivos de registro completos aquí, por si sirven de ayuda:http://www.uni-ulm.de/~pqa62/tex/

¿Alguien tiene una idea y sabe cómo solucionar este comportamiento? Realmente me gustó la forma en que hice la externalización y la reconstrucción automática, especialmente porque en la realización completa de mis comandos de inclusión se cubren algunas cosas más avanzadas y también porque todo funcionó hasta que tuve que cambiar a lualatex.

editar:

Hice algunas pruebas más y descubrí que el comando personalizado \executeiffileneweraparentemente es el problema y por qué ocurre el error. De alguna manera, lualatex (que se supone que solo escribe el diagrama tikz) también examina el siguiente \includesvgcomando e intenta ejecutarlo. Aquí, no conoce este comando personalizado porque no está definido en su llamada. Si modifico el \includesvgcomando así:

\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}%
}

Ya no recibo ningún error. El problema es que siempre ejecuta Inkscape. Y aún así, no entiendo por qué lualatex no se detiene una vez finalizada la trama de tikz.

Respuesta1

Si cambia y agrega algunos errores o comandos a su documento -interaction=batchmode, podrá ver que la ejecución de luatex compila todo el archivo tex. Y expande los comandos durante esto: puede encontrar la imagen dentro de \includetikz, por lo que, naturalmente, también tiene que buscar dentro de \includesvg. Esto significa que los comandos que luatex no conoce pueden causar problemas.-interaction=scrollmode\show

\pdfstrcmpno está definido en luatex. Puede cargar el paquete pdftexcmds para obtener una implementación.https://tex.stackexchange.com/a/158612/2388. Atención: no verifiqué si pdftexcmds se ha adaptado a luatex 0.95/1.0, pero en mi ejemplo simplificado parecía funcionar.

\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}

información relacionada