没有使用独立包为 Tikz 图片生成单独的 PDF

没有使用独立包为 Tikz 图片生成单独的 PDF

我目前正在编写一个包含许多 Tikz 图形的大型文档,为了加快编译速度,我想使用独立包将它们生成为单独的 PDF。尽管运行良好且没有错误,但我的代码似乎在编译时没有输出任何单独的 PDF。我浏览了独立包的文档,但没有找到任何可以解决我的问题的东西。因此,我根据项目中的工作方式创建了这个最小文档,希望你们中的一些人可能知道解决这个问题的方法。

仅供参考,我正在运行启用了 shell ecape 的 PDFLaTeX,如下所示:

pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex

请注意,您必须包括3dplot.sty与 Main.tex 文件位于同一存储库中,才能成功运行编译。

主要文件档案:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
    \usetikzlibrary{decorations.pathreplacing,decorations.pathmorphing,calc}
\usepackage{amsmath}
\usepackage{3dplot}
\usepackage{standalone}

\newlength\figureheight
\newlength\figurewidth

\title{Test}
\author{Hkonrost}

\begin{document}
    \maketitle

\begin{figure}[ht]
    \centering
    \setlength\figureheight{0.4\textwidth}
    \setlength\figurewidth{0.7\linewidth}
    \input{testStandalone.tex}
    \caption[Excitation vectors]{I wish standalone worked for this document.}
\end{figure}

\end{document}

输入文件 testStandalone.tex 包含以下内容:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.pathmorphing,calc}
\usepackage{amsmath}
\usepackage{3dplot}
\begin{document}
%set the plot display orientation
%syntax: \tdplotsetdisplay{\theta_d}{\phi_d}
\tdplotsetmaincoords{70}{110} % 60 110
% Define dimensions of sample box
\newcommand{\Depth}{8}
\newcommand{\Height}{0.5}
\newcommand{\Width}{8}
\begin{tikzpicture}[thick,tdplot_main_coords]

% Setting up coordinates
% -------------------------------
% x = depth, y = width, z = height
% Back face coordinates
\coordinate (O) at (0,0,0);
\coordinate (A) at (0,0,\Height);
\coordinate (B) at (0,\Width,\Height);
\coordinate (C) at (0,\Width,0);
% Front face coordinates
\coordinate (D) at (\Depth,0,0);
\coordinate (E) at (\Depth,0,\Height);
\coordinate (F) at (\Depth,\Width,\Height);
\coordinate (G) at (\Depth,\Width,0);
% Origin coordinate
\coordinate (origin) at (\Depth/6,\Width/6,0);

% Drawn structures
% --------------------------------------

% K-vector
\draw[red,ultra thick,->] (origin) --++ (0.58,0,-0.45) node[right] {$\Vec{k}$}; % K-vector

% Substrate surface planes
\draw[blue,fill=cyan!80,opacity=0.5] (O) -- (A) -- (B) -- (C) -- cycle; % Back Face
\draw[blue,fill=cyan!80,opacity=0.5] (O) -- (D) -- (G) -- (C) -- cycle; % Bottom Face
\draw[blue,fill=cyan!80,opacity=0.5] (O) -- (D) -- (E) -- (A) -- cycle; % Back Left Face
\draw[blue,fill=cyan!80,opacity=0.5] (C) -- (G) -- (F) -- (B) -- cycle; % Front Right Face
\draw[blue,fill=cyan!80,opacity=0.5] (D) -- (E) -- (F) -- (G) -- cycle; % Front Face
\draw[blue,fill=cyan!80,opacity=0.5] (E) -- (A) -- (B) -- (F) -- cycle; % Top Face

% Axes
\draw[very thick,black,->] (origin) --++ (\Depth*0.95,0,0) node [below] {x};
\draw[very thick,black,->] (origin) --++ (0,\Width*0.95,0) node [right] {y};
\draw[very thick,black,->] (origin) --++ (0,0,\Depth*0.5) node [above] {z, $\hat{\Vec{n}}$};

% Negative x-axis extension
\draw[thick,dashed] (origin) --++ (-3.5,0,0);

% Incoming photon;
\draw [violet,ultra thick,decorate,decoration={snake}] ($(origin)+(-3.5,0,2.7)$) -- ($(origin)$); % Photon

% xy projection plane
\draw[black,dashed] ($ (origin) + (4.5,0,0) $) --++ (0,4.5,0) --++ (-4.5,0,0);
\draw[black, dashed] (origin) --++ (4.5,4.5,0);

% Projection line O vector
\draw[black,dashed] ($ (origin) + (4.5,4.5,0) $) --++ (0,0,3.5);

% O vector
\draw[ultra thick,teal,->] (origin) --++ (4.5,4.5,3.5) node[above right] {$\Vec{O}$}; % E parallel

% xz plane
\draw[black,dashed] ($ (origin) + (4.5,0,0) $) --++ (0,0,3.5) --++ (-4.5,0,0);

% E-field vector components
\draw[ultra thick,red,->] (origin) --++ (4.5,0,3.5) node[above left] {$\Vec{\mathcal{E}}_{\parallel}$}; % E parallel
\draw[ultra thick,red,->] (origin) --++ (0,1,0) node[above right] {$\Vec{\mathcal{E}}_{\perp}$};;
\draw[very thick,red,dashed] ($(origin)+(0,0.45,0)$) --++ (0.58,0,0.45) --++ (0,-0.45,0);

% Drawing the arcs
% ----------------------------------------------------
% For drawing the different arcs, the plane spanned by theta rotation is rotated about the z-axis (azimuthally). Syntax: \tdplotsetthetaplanecoords{\phi}

% Azimuthal angle to vector O projection onto xy plane
\tdplotdrawarc{(origin)}{3}{0}{45}{anchor=north}{$\phi$};

% Angle theta to E parallel vector from z-axis
\tdplotsetthetaplanecoords{0}
\tdplotdrawarc[tdplot_rotated_coords]{(origin)}{1.5}{0}{52.1}{anchor=south east}{$\theta$};

% Angle alpha to O vector from z-axis
\tdplotsetthetaplanecoords{52.1}
\tdplotdrawarc[tdplot_rotated_coords]{(origin)}{1.5}{0}{58.44}{anchor=south west}{$\alpha$};

% Angle theta from x axis to incoming photon
\tdplotsetthetaplanecoords{180}
\tdplotdrawarc[tdplot_rotated_coords]{(origin)}{2.4}{52.1}{90}{anchor=west}{$\theta$};

\end{tikzpicture}
\end{document}

如能得到任何帮助我们将不胜感激!

答案1

standalone软件包确实可以为子文件创建单独的 PDF。为此,请将mode包选项设置为buildbuildmissingbuildnew并使用\includestandalone{file}(不带 .tex 扩展名!)而不是\input{file.tex}。这需要-shell-escape您已在使用的编译器开关。

如果您随后将build=tex其用于最终编译,则将使用源文件。请注意,这buildnew不适用于 XeLaTeX,因为它无法检查文件更改。

完整主文件为:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
    \usetikzlibrary{decorations.pathreplacing,decorations.pathmorphing,calc}
\usepackage{amsmath}
\usepackage{3dplot}
\usepackage[mode=build]{standalone}

\newlength\figureheight
\newlength\figurewidth

\title{Test}
\author{Hkonrost}

\begin{document}
    \maketitle

\begin{figure}[ht]
    \centering
    \setlength\figureheight{0.4\textwidth}
    \setlength\figurewidth{0.7\linewidth}
    \includestandalone{testStandalone}
    \caption[Excitation vectors]{I wish standalone worked for this document.}
\end{figure}

\end{document}

相关内容