你好呀
目前正在尝试实现外部库,但似乎无法使其工作
\documentclass{article}
% pgfplots
\usepackage{pgfplots}
% % Uncommenting generates error
% \usetikzlibrary{external}
% % External lib
% \tikzexternalize % turn externalization on/off
% \tikzsetfigurename{./figures/figure_\arabic{part}.} % set names
\pgfplotsset{
compat = newest,
width = 10cm, % width
height = 7cm, % height
samples = 10,
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[hide axis]
\addplot3 [
% Aparence
surf,
opacity=0.5,
fill opacity= 1,
faceted color = white,
shader=faceted interp,
% Scope
data cs = cart, % cart/polar/polarrad
% Variable
domain = -1:1,
domain y = -1:1,
]{
x^2-y^2
};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[hide axis]
\addplot3 [
% Aparence
surf,
opacity=0.5,
fill opacity= 1,
faceted color = white,
shader=faceted interp,
% Scope
data cs = cart, % cart/polar/polarrad
% Variable
variable = u,
variable y = v,
domain = 0:360,
domain y = -180:0,
]
(
{cos(u)*sin(v)},
{sin(u)*sin(v)},
{cos(v)}
);
\end{axis}
\end{tikzpicture}
\end{document}
取消注释external
库代码会产生以下错误:
Package tikz Error: Sorry, the system call 'lualatex -shell-escape -halt-on-error -interaction=batchmode -jobname "./figures/figure_0.1" "\def\tikzexternalrealjob{"stack q"}\input{"stack q"}"' did NOT result in a usable output file './figures/figure_0.1' (expected one of .pdf:.jpg:.jpeg:.png:). Please 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 './figures/figure_0.1.log'. If you continue now, I'll try to typeset the picture.
笔记:
./figures/figure_0.1.log
从未写入,可能看起来写入某些文件存在问题,但事实并非如此,因为已经.md5
创建了文件。- 编译调用是:
lualatex --synctex=1 --shell-escape --output-dir=.build --interaction=nonstopmode --file-line-error %DOC%
更新 1
变化:
- 修复目录以包含
.build/
- 添加的
tikzset
external/system call
命令
\documentclass{article}
% pgfplots
\usepackage{pgfplots}
% uncommenting generates error
\usetikzlibrary{external}
% External lib
\tikzexternalize[
up to date check={simple},
prefix=./.build/figures/
] % turn externalization on/off
\tikzsetfigurename{figure_\arabic{part}.} % set names
% Using tikzset returns error
\tikzset{%
external/system call={%
lualatex \tikzexternalcheckshellescape
--halt-on-error
--shell-escape
--interaction=batchmode
--jobname "\image" "\texsource"
}
}
\pgfplotsset{
compat = newest,
width = 10cm, % width
height = 7cm, % height
samples = 10,
}
\begin{document}
% \tikzsetfigurename{figure_\arabic{part}.} % set names
\begin{tikzpicture}
\begin{axis}[hide axis]
\addplot3 [
% Aparence
surf,
opacity=0.5,
fill opacity= 1,
faceted color = white,
shader=faceted interp,
% Scope
data cs = cart, % cart/polar/polarrad
% Variable
domain = -1:1,
domain y = -1:1,
]{
x^2-y^2
};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[hide axis]
\addplot3 [
% Aparence
surf,
opacity=0.5,
fill opacity= 1,
faceted color = white,
shader=faceted interp,
% Scope
data cs = cart, % cart/polar/polarrad
% Variable
variable = u,
variable y = v,
domain = 0:360,
domain y = -180:0,
]
(
{cos(u)*sin(v)},
{sin(u)*sin(v)},
{cos(v)}
);
\end{axis}
\end{tikzpicture}
\end{document}
笔记:
- 现在可以看到
.log
生成的文件。它们都否认了相同的消息
...
! LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.13 \tikzsetfigurename
{figure_\arabic{part}.} % set names
...
移至\tikzsetfigurename
之后\begin{document}
没有效果。
--output-directory
从编译调用中删除选项并将external
相关命令替换为:
% uncommenting generates error
\usetikzlibrary{external}
% External lib
\tikzexternalize[
up to date check={simple},
prefix=./figures/
] % turn externalization on/off
\tikzsetfigurename{figure_\arabic{part}.} % set figure names
% Using tikzset returns error
\tikzset{%
external/system call={%
lualatex \tikzexternalcheckshellescape
--halt-on-error
--shell-escape
--interaction=batchmode
--jobname "\image" "\texsource"
}
}
仍然会产生与以前相同的错误。
结论
问题出在主文件的名称中有空格,因此产生了一个新问题来解决这个问题这里。
这是当前正在工作的 MWE,已重命名为stackq.tex
:
\documentclass{article}
% pgfplots
\usepackage{pgfplots}
% uncommenting generates error
\usetikzlibrary{external}
% External lib
\tikzexternalize[
up to date check={simple},
prefix=./.build/figures/
] % turn externalization on/off
\tikzsetfigurename{figure_\arabic{part}.} % set figure names
% Using tikzset generates error
\tikzset{%
external/system call={%
lualatex \tikzexternalcheckshellescape
--halt-on-error
--shell-escape
--interaction=batchmode
--jobname "\image" "\texsource"
}
}
\pgfplotsset{
compat = newest,
width = 10cm, % width
height = 7cm, % height
samples = 10,
}
\begin{document}
% \tikzsetfigurename{figure_\arabic{part}.} % set figure names
\begin{tikzpicture}
\begin{axis}[hide axis]
\addplot3 [
% Aparence
surf,
opacity=0.5,
fill opacity= 1,
faceted color = white,
shader=faceted interp,
% Scope
data cs = cart, % cart/polar/polarrad
% Variable
domain = -1:1,
domain y = -1:1,
]{
x^2-y^2
};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[hide axis]
\addplot3 [
% Aparence
surf,
opacity=0.5,
fill opacity= 1,
faceted color = white,
shader=faceted interp,
% Scope
data cs = cart, % cart/polar/polarrad
% Variable
variable = u,
variable y = v,
domain = 0:360,
domain y = -180:0,
]
(
{cos(u)*sin(v)},
{sin(u)*sin(v)},
{cos(v)}
);
\end{axis}
\end{tikzpicture}
\end{document}
答案1
我将分享我的设置。(Windows、TeXstudio、MiKTeX)
(0)文件名中没有空格!使用stackq.tex
(1)使用lualatex.exe -synctex=1 -interaction=nonstopmode -shell-escape %.tex
(2)TestExternalize.tex
在工作目录中EXTERNALIZE
有一个子目录FIGURES
%%% File TestExternalize.tex
\documentclass{article}
% pgfplots
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
% % Uncommenting does not generates error
\usetikzlibrary{external}
\tikzexternalize[% added <<<<<<<<<<<
up to date check={simple},
prefix=./FIGURES/]% Folder needs to be created before compiling
\tikzset{external/system call={% added <<<<<<<<<<<<<<
lualatex \tikzexternalcheckshellescape
-halt-on-error -shell-escape -interaction=batchmode
-jobname "\image" "\texsource"}}
\pgfplotsset{
compat = newest,
width = 10cm, % width
height = 7cm, % height
samples = 10,
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[hide axis]
\addplot3 [
% Aparence
surf,
opacity=0.5,
fill opacity= 1,
faceted color = white,
shader=faceted interp,
% Scope
data cs = cart, % cart/polar/polarrad
% Variable
domain = -1:1,
domain y = -1:1,
]{
x^2-y^2
};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[hide axis]
\addplot3 [
% Aparence
surf,
opacity=0.5,
fill opacity= 1,
faceted color = white,
shader=faceted interp,
% Scope
data cs = cart, % cart/polar/polarrad
% Variable
variable = u,
variable y = v,
domain = 0:360,
domain y = -180:0,
]
(
{cos(u)*sin(v)},
{sin(u)*sin(v)},
{cos(v)}
);
\end{axis}
\end{tikzpicture}
\end{document}
(3)编译后的目录结构。
(4)输出TestExternalize.pdf
(5)第二次编译(更快)时出现以下消息
===== Image './FIGURES/TestExternalize-figure0' is up-to-date. ======
===== Image './FIGURES/TestExternalize-figure1' is up-to-date. ======