编辑

编辑

我在 Mac 上使用 TexStudio 和 texlive 2016。对于我的 tikz 图形,我使用 ktikz 和 matlab2tikz。一些 matlab 图有相当多的数据点,因此我决定对所有 tikz 图形使用独立程序,并希望使用 externalize (不起作用)。

为了保持主文件夹整洁,我使用一个build文件夹并设置以下pdflatex命令(首选项->命令):

/Library/TeX/texbin/pdflatex -shell-escape -synctex=1 -interaction=nonstopmode -output-directory=./build %.tex

命令也BibTex必须调整:

/Library/TeX/texbin/bibtex build/%.aux

然后我不得不使用额外的搜索路径(首选项->构建->显示高级选项->日志文件和 PDF 文件):

Log File: ./build
Pdf File: ./build
Commands ($PATH): /usr/local/texlive/2016/bin/x86_64-darwin

每次使用时,尽管我在命令中添加了选项,\usetikzlibrary{external}\tikzexternalize仍然会出现以下错误。-shell-escapepdflatex

Package tikz Error: Sorry, the system call 'pdflatex -shell-escape -halt-on-e
rror -interaction=batchmode -jobname "./tikz_figures/main-figure0" "\def\tikzex
ternalrealjob{main}\input{main}"' did NOT result in a usable output file './tik
z_figures/main-figure0' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify 
that you have enabled system calls. For pdflatex, this is 'pdflatex -shell-esca
pe'. Sometimes it is also named 'write 18' or something like that. Or maybe the
 command simply failed? Error messages can be found in './tikz_figures/main-fig
ure0.log'. If you continue now, I'll try to typeset the picture.

我的路径设置或前缀选项是否存在问题\tikzexternalize

注释掉这两行\usetikzlibrary{external}\tikzexternalize它就起作用了。



编辑

平均能量损失

主文本(文件夹: 。/)

\documentclass{report}

% graphics
\usepackage{graphicx, color}
\graphicspath{
    {./figures/tikz/}{./figures/non_tikz/}
}
\usepackage{tikz}
\usetikzlibrary{external}
%\tikzexternalize[shell escape=-enable-write1 -shell-escape, prefix=./build/]
\tikzexternalize[prefix=./build/tikz_figures/]
%\tikzexternalize
\usepackage{standalone}
%\input{./figures/tikz/tikz_definitions}


\begin{document}

\begin{figure}
\centering
\includestandalone[width=\textwidth]{example}
\caption{example caption.}
\label{fig:example}
\end{figure}

\end{document}

例子.tikz(文件夹:./figures/tikz/)

\begin{tikzpicture}

% draw help lines
\draw[help lines] (0,0) grid (1\textwidth,5);

\end{tikzpicture}

例子.tex(文件夹:./figures/tikz/)

\documentclass{standalone}

\input{tikz_definitions}

\begin{document}
\input{example.tikz}
\end{document}

无论我使用哪个前缀或选项,\tikzexternalize我都会收到相同的错误消息。


附加信息:

这是我使用的文件夹结构:

main folder
    main.tex (main tex file)
    references.bib
    build (folder)
        epstopdf (folder)
        tikz_figures (folder
        *.aux, *.log, *.pdf, *.toc, (output files)
    chapters (folder)
        *.tex (tex files)
    figures (folder)
        non_tikz (folder)
            *.png, *.jpg, (all non tikz figures)
        tikz (folder)
            blocks (folder containing figures for tikz figures)
            *.tex (multiple standalone tex files)
            *.tikz (multiple tikz files editable with ktiz)
            tikz_definitions.tex (one tikz definition file)

----------

更多信息

非 MWE

我的序言主文本文件如下所示:

\documentclass[a4paper,twoside, openright,12pt]{report}

\graphicspath{
    {./figures/tikz/}{./figures/non_tikz/}
}
\usepackage{graphicx, color}
\usepackage{tikz}
\usetikzlibrary{external}
%\tikzexternalize[shell escape=-enable-write1 -shell-escape, prefix=./build/]
\tikzexternalize[prefix=./tikz_figures/]
%\tikzexternalize
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
%% the following commands are needed for some matlab2tikz features
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{patchplots}
\usepackage{grffile}
\usepackage{amsmath}

\usetikzlibrary{arrows.meta}
\usepackage{standalone}
\input{./figures/tikz/tikz_definitions}


\begin{document}

\begin{figure}[H]
\centering
\includestandalone[width=\textwidth]{example}
\caption{example caption.}
\label{fig:example}
\end{figure}


\addcontentsline{toc}{chapter}{Bibliography}
\bibliography{references}
\bibliographystyle{alphaurl}

\end{document}

由于ktikz无法处理标准 latex 包,我为所有 tikz 图形使用一个模板。这样,每个绘制的 ktikz 图形都会有一个tikz_definitions.tex(模板) 和*.tikz一个*.tex(独立)。

tikz_定义.tex

\usepackage{tikz}

\usetikzlibrary{arrows}

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\definecolor{oneColor}{RGB}{47,128,0}
\definecolor{secondColor}{RGB}{242,30,0}
\definecolor{thirdColor}{RGB}{106,178,248}

\tikzstyle{line} = [dash pattern=on 15pt off 25pt]

%% define reusable figure 
\newcommand{\reusablefigure}[4]{
    % a figure
    \begin{pgfonlayer}{foreground}
    \node[anchor=center, rotate=#4, opacity=0.6, inner sep=0] 
        (#1) at (#2,#3) {\includegraphics[scale=0.8]{blocks/a_figure.pdf}};
    \end{pgfonlayer}

    % white background rectangle
    \begin{pgfonlayer}{main}
    \begin{scope}[shift=(#1.center), rotate=#4]
        \fill [white, rounded corners=10pt] (-1.35,-0.53) rectangle (1.35,0.53);
    \end{scope}
    \end{pgfonlayer}

    % coordinate frame
    \begin{pgfonlayer}{foreground}
    \begin{scope}[shift=(#1.center), rotate=#4]
        \draw [<->, thick, color=#1Color] 
            (-0.8,1.1) node [left] (y) {$y_{#1}$} -- 
            (-0.8,0) -- 
            (2,0) node [below right] (x) {$x_{#1}$};
    \end{scope}
    \end{pgfonlayer}
}

%% define another reusable figure
\newcommand{\anotherfigure}[2]{
    \begin{pgfonlayer}{foreground}
        \draw [fill=red] (#1,#2) circle (0.07cm);
    \end{pgfonlayer}
}

这是一个图形的示例(由 *.tikz 和 *.tex 文件组成)

*示例.tikz

\begin{tikzpicture}[
    scale=0.8, 
    axis/.style={very thick, ->, >=stealth'},
]

    % draw lines
    \draw[line, ultra thick] (0.2\textwidth, 4) -- (0.95\textwidth, 4);
    \draw[line, ultra thick] (0.2\textwidth, 2) -- (0.95\textwidth, 2);

    % a figure
    \reusablefigure{name1}{0}{0}{45}

    % the same figure
    \reusablefigure{name2}{10}{3}{0}


    % measurements
    \anotherfigure{1}{1}
    \anotherfigure{2}{2}
    \anotherfigure{4}{3}

\end{tikzpicture}

*示例.tex

\documentclass{standalone}

\input{tikz_definitions}

\begin{document}
\input{overview.tikz}
\end{document}

答案1

更新: 下面是一个简单文件夹结构的最小工作示例,如下所示。您必须使用 编译main.texpdflatex -shell-escape -output-directory=build %.tex\tikzsetnextfilename{<...>}可以使用 设置输出名称。您必须build在编译之前手动创建文件夹(首先)。

主文本

InputTikz(文件夹)

---exampletikz.tex (tikz)

建立(文件夹)

MWE 生成一个新文件夹(OutputTikz),其中包含 pdf 文件(独立图形)并 main.aux,main.auxlock,main.txt,main.pdf保存在build目录中。

主文本

InputTikz(文件夹)

---exampletikz.tex(tikz)

OutputTikz(文件夹)

---testname.pdf(独立pdf)

---B_name.pdf(独立pdf)

建立(文件夹)

---主要.aux

---main.auxlock

---主要.txt

---主要.pdf

汇编:

  1. 首先创建文件夹build!
  2. 请编译: pdflatex -shell-escape -output-directory=build %.tex

主文本

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[prefix=./OutputTikz/]    
\begin{document}
\tikzsetnextfilename{testname}
\input{InputTikz/exampleTikz}

\tikzsetnextfilename{B_name}
\input{InputTikz/exampleTikz}
\end{document}

示例tikz.tex

\begin{tikzpicture}
\draw (0,0) -- (0,1) -- (1,1) -- (2,1) -- (2,0);
\end{tikzpicture}

相关内容