
我正在使用cairolatex
終端來gnuplot
創建一些曲面圖(pgfplots
由於其對記憶體的渴望而導致任務失敗)。隨著繪圖數量的增加,我想將gnuplot
編譯包含到我的tex
編譯中,以確保繪圖是最新的。我發現了這個gnuplottex
包,它似乎可以處理該任務,儘管速度很慢。
我有一個大的嵌套文件。 Tex root 是thesis.tex
我在其中包含theory.tex
.我theory.tex
已經把
\begin{figure}[htbp]
\centering
\input{gnuplot/cascade}
\input{figures/cascade}
\end{figure}
其中gnuplot/cascade.tex
包含gnuplot
程式碼
\begin{gnuplot}[terminal=cairolatex]
set samp 100;
set iso 40;
set xrange [0:1];
set yrange [0:1];
set zrange [0.8:2];
unset key;
unset colorbox;
set hidden3d front;
a = 1;
set xyplane at a;
f(x,y) = (x+y)/(2*sqrt(x*y));
set xlabel "$\\tau_I$";
set ylabel "$\\tau_D$";
set zlabel "$\\zeta$";
set output "figures/cascade.tex"
splot f(x,y) with pm3d at b, f(x,y) with lines;
unset output
\end{gnuplot}
這個設定的輸出非常棒。但每當我更改某些內容時theory.tex
,整個gnuplottex
例程都會重新編譯。這需要相當長的時間,而且非常煩人。
為什麼latexmk
不認識到gnuplot
代碼沒有改變並留下它?可以指定這種依賴性嗎?
編輯:雖然速度很快gnuplottex
,但在我的系統上相當慢。gnuplot
如何避免使用gnuplottex
,它的編譯時間很長,從而避免gnuplottex
每次都重新編譯?
答案1
gnuplottex
我透過添加以下自訂依賴項來完全避免使用.latexmkrc
:
add_cus_dep('gnu','tex', 0, 'makegnu2tex');
sub makegnu2tex {
system("gnuplot \"$_[0].gnu\"") ;
}
我的gnuplot
文件使用cairolatex
終端(或生成文件的任何其他終端.tex
)。我的latex
文檔包含\input{gnuplot_output.tex}
其中的內容,由於新定義的依賴關係,會gnuplot
在tex
編譯時導致系統呼叫。文件.gnu
和.tex
文件現在是正常的依賴關係,gnuplot
除非更改時間戳,否則不會重新編譯。
需要注意的是,只要係統呼叫是由 引起的,檔案set output "path/gnuplot_output.tex"
中指定的路徑.gnu
就是相對於該檔案的。tex root
gnuplot
latexmk
答案2
我目前未使用的解決方案gnuplottex
是對我不久前發現的解決方案的修改(如何在 LaTeX 中包含 SVG 圖像)以包含 SVG(如有必要,自動呼叫 Inkscape)。
\newcommand{\executeiffilenewer}[3]{%
\ifnum\pdfstrcmp{\pdffilemoddate{#1}}%
{\pdffilemoddate{#2}}>0%
{\immediate\write18{#3}}\fi%
}
\newcommand{\includegp}[2]{%
\executeiffilenewer{#1#2.gp}{tmp/img/#2.tex}%
{gnuplot #1#2.gp}%
\import{tmp/img/}{#2.tex}%
}
我的 gnuplot 文件位於子資料夾中,例如img/ch01/foo.gp
,並且我喜歡將所有臨時文件tmp/
和所有臨時圖像文件放在其中tmp/img/
(因為我用來git
跟踪我的 tex 文件,但不想跟踪任何派生文件,即tmp/
)。然後可以將 gnuplot 文件嵌入到文件中,如下所示:
\begin{figure}
\centering
\includegp{img/ch01/}{foo}
\end{figure}
我透過 和 選項進行調用miktex-pdftex.exe
,以TeXworks
使其發揮作用。此外,包含 gnuplot 二進位檔案的資料夾必須位於 PATH 變數中,或者在我的情況下在 TeXworks 設定中設定(例如)。-aux-directory=tmp
-shell-escape
D:/gnuplot/bin