如果我做错了什么,请见谅,这是我的第一篇帖子。我通常使用 gnuplot 生成 pdf,方法是使用输出终端 tkiz 先生成 .tex,然后生成 .pdf。我最近更新到了 TeXLive。现在从 .tex 到 .pdf 的编译不再起作用了。
我的示例是一个由 gnuplot 中的“set term tkiz”输出生成的 .tex。我收到错误
! Undefined control sequence.
l.22 \gpsetdashtype
{gp dt solid}
无法解释。有人知道如何修复吗?感谢您调查此问题。
编辑:这是一个现在在空文件夹中运行的示例。但我不确定这个“createstyle”是做什么的。通常我在这里输入“独立标题“\usepackage{MyGnuplotLaTeX}”,这是一个 .sty 文件,它为我调用 usepackages,例如 siunitx。
#!/usr/bin/gnuplot
basename='test_graph.plt'
end3='.tex'
f(x)=sin(x)
plot f(x) with lines #ls 1
set term tikz size 342.435pt,228pt standalone create style font \\rmfamily,12pt"
set output basename.end3
replot
set output
system(sprintf('pdflatex %s%s', basename, end3))
%%%%%%%%%%%%%% Standalone example to be compiled via pdflatex for example. %%%%
\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[utf8x]{inputenc}
\usepackage{gnuplot-lua-tikz}
\pagestyle{empty}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{\gpbboxborder}
\begin{document}
\begin{tikzpicture}[gnuplot]
%% generated with GNUPLOT 5.0p1 (Lua 5.2; terminal rev. 99, script rev. 100)
%% Fri Sep 11 09:10:43 2015
\tikzset{every node/.append style={font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}}}
\path (0.000,0.000) rectangle (12.035,8.013);
\gpcolor{color=gp lt color border}
\gpsetlinetype{gp lt border}
\gpsetdashtype{gp dt solid}
\gpsetlinewidth{1.00}
\draw[gp path] (1.430,0.740)--(1.610,0.740);
\draw[gp path] (11.372,0.740)--(11.192,0.740);
\node[gp node right,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (1.210,0.740) {$-1$};
\draw[gp path] (1.430,1.423)--(1.610,1.423);
\draw[gp path] (11.372,1.423)--(11.192,1.423);
\node[gp node right,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (1.210,1.423) {$-0.8$};
\draw[gp path] (1.430,2.106)--(1.610,2.106);
\draw[gp path] (11.372,2.106)--(11.192,2.106);
\node[gp node right,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (1.210,2.106) {$-0.6$};
\draw[gp path] (1.430,2.789)--(1.610,2.789);
\draw[gp path] (11.372,2.789)--(11.192,2.789);
\node[gp node right,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (1.210,2.789) {$-0.4$};
\draw[gp path] (1.430,3.472)--(1.610,3.472);
\draw[gp path] (11.372,3.472)--(11.192,3.472);
\node[gp node right,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (1.210,3.472) {$-0.2$};
\draw[gp path] (1.430,4.155)--(1.610,4.155);
\draw[gp path] (11.372,4.155)--(11.192,4.155);
\node[gp node right,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (1.210,4.155) {$0$};
\draw[gp path] (1.430,4.838)--(1.610,4.838);
\draw[gp path] (11.372,4.838)--(11.192,4.838);
\node[gp node right,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (1.210,4.838) {$0.2$};
\draw[gp path] (1.430,5.521)--(1.610,5.521);
\draw[gp path] (11.372,5.521)--(11.192,5.521);
\node[gp node right,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (1.210,5.521) {$0.4$};
\draw[gp path] (1.430,6.204)--(1.610,6.204);
\draw[gp path] (11.372,6.204)--(11.192,6.204);
\node[gp node right,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (1.210,6.204) {$0.6$};
\draw[gp path] (1.430,6.887)--(1.610,6.887);
\draw[gp path] (11.372,6.887)--(11.192,6.887);
\node[gp node right,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (1.210,6.887) {$0.8$};
\draw[gp path] (1.430,7.570)--(1.610,7.570);
\draw[gp path] (11.372,7.570)--(11.192,7.570);
\node[gp node right,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (1.210,7.570) {$1$};
\draw[gp path] (1.430,0.740)--(1.430,0.920);
\draw[gp path] (1.430,7.570)--(1.430,7.390);
\node[gp node center,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (1.430,0.371) {$-10$};
\draw[gp path] (3.916,0.740)--(3.916,0.920);
\draw[gp path] (3.916,7.570)--(3.916,7.390);
\node[gp node center,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (3.916,0.371) {$-5$};
\draw[gp path] (6.401,0.740)--(6.401,0.920);
\draw[gp path] (6.401,7.570)--(6.401,7.390);
\node[gp node center,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (6.401,0.371) {$0$};
\draw[gp path] (8.887,0.740)--(8.887,0.920);
\draw[gp path] (8.887,7.570)--(8.887,7.390);
\node[gp node center,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (8.887,0.371) {$5$};
\draw[gp path] (11.372,0.740)--(11.372,0.920);
\draw[gp path] (11.372,7.570)--(11.372,7.390);
\node[gp node center,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (11.372,0.371) {$10$};
\draw[gp path] (1.430,7.570)--(1.430,0.740)--(11.372,0.740)--(11.372,7.570)--cycle;
\node[gp node right,font={\rmfamily\fontsize{12pt}{14.4pt}\selectfont}] at (9.652,7.205) {f(x)};
\gpcolor{rgb color={0.690,0.188,0.376}}
\gpsetlinewidth{2.00}
\draw[gp path] (9.872,7.205)--(10.932,7.205);
\draw[gp path] (1.430,6.013)--(1.530,5.400)--(1.631,4.737)--(1.731,4.050)--(1.832,3.367)%
--(1.932,2.716)--(2.033,2.124)--(2.133,1.615)--(2.233,1.208)--(2.334,0.922)--(2.434,0.767)%
--(2.535,0.750)--(2.635,0.871)--(2.736,1.126)--(2.836,1.504)--(2.936,1.990)--(3.037,2.564)%
--(3.137,3.203)--(3.238,3.881)--(3.338,4.569)--(3.438,5.241)--(3.539,5.868)--(3.639,6.426)%
--(3.740,6.892)--(3.840,7.246)--(3.941,7.474)--(4.041,7.568)--(4.141,7.523)--(4.242,7.340)%
--(4.342,7.028)--(4.443,6.600)--(4.543,6.071)--(4.644,5.465)--(4.744,4.806)--(4.844,4.120)%
--(4.945,3.435)--(5.045,2.780)--(5.146,2.181)--(5.246,1.662)--(5.347,1.244)--(5.447,0.945)%
--(5.547,0.777)--(5.648,0.745)--(5.748,0.853)--(5.849,1.095)--(5.949,1.461)--(6.050,1.937)%
--(6.150,2.503)--(6.250,3.136)--(6.351,3.811)--(6.451,4.499)--(6.552,5.174)--(6.652,5.807)%
--(6.752,6.373)--(6.853,6.849)--(6.953,7.215)--(7.054,7.457)--(7.154,7.565)--(7.255,7.533)%
--(7.355,7.365)--(7.455,7.066)--(7.556,6.648)--(7.656,6.129)--(7.757,5.530)--(7.857,4.875)%
--(7.958,4.190)--(8.058,3.504)--(8.158,2.845)--(8.259,2.239)--(8.359,1.710)--(8.460,1.282)%
--(8.560,0.970)--(8.661,0.787)--(8.761,0.742)--(8.861,0.836)--(8.962,1.064)--(9.062,1.418)%
--(9.163,1.884)--(9.263,2.442)--(9.364,3.069)--(9.464,3.741)--(9.564,4.429)--(9.665,5.107)%
--(9.765,5.746)--(9.866,6.320)--(9.966,6.806)--(10.066,7.184)--(10.167,7.439)--(10.267,7.560)%
--(10.368,7.543)--(10.468,7.388)--(10.569,7.102)--(10.669,6.695)--(10.769,6.186)--(10.870,5.594)%
--(10.970,4.943)--(11.071,4.260)--(11.171,3.573)--(11.272,2.910)--(11.372,2.297);
\gpcolor{color=gp lt color border}
\gpsetlinewidth{1.00}
\draw[gp path] (1.430,7.570)--(1.430,0.740)--(11.372,0.740)--(11.372,7.570)--cycle;
%% coordinates of the plot area
\gpdefrectangularnode{gp plot 1}{\pgfpoint{1.430cm}{0.740cm}}{\pgfpoint{11.372cm}{7.570cm}}
\end{tikzpicture}
%% gnuplot variables
\end{document}
答案1
每次运行时都会gnuplot-lua-tikz.sty
在运行目录中自动创建该文件。其内容是固定的:gnuplot <file>
gnuplot
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{gnuplot-lua-tikz}%
[2014/11/09 (rev. 100) GNUPLOT Lua terminal style]
\RequirePackage{tikz}
\usetikzlibrary{arrows,patterns,plotmarks,backgrounds,fit}
\input gnuplot-lua-tikz-common.tex
\endinput
并且每次都会创建其附带的文件gnuplot-lua-tikz-common.tex
(太长,无法在此显示)。
据我所知,这些文件不存在于系统中的任何地方,而是由我拥有的 Lua 脚本生成的
/usr/local/Cellar/gnuplot/5.0.1/share/gnuplot/5.0/lua/gnuplot-tikz.lua
(在其他系统上对应于/usr/local/share/gnuplot/...
或/usr/share/gnuplot/...
)。
如果你想让生成的test_graph.plt.tex
文件可编译,你可以需要将这些生成的文件与其一起保存。
可能较旧的版本gnuplot
提供了“修复”gnuplot-lua-tikz.sty
和gnuplot-lua-tikz-common.tex
,但最新版本没有。我认为将这些文件保存在 TeX 可搜索的目录中(例如$TEXMFHOME
)并不是一个好习惯,因为它们每次都会生成,这似乎意味着的开发人员gnuplot
希望可以自由更新它们,而无需与 TeX 发行版交互。
答案2
出现错误是因为您的 pdflatex 版本不知道如何处理\gpsetdashtype
。为了避免这种情况,您可以编辑gnuplot-tikz.lua
,此文件可能位于/usr/share/gnuplot/gnuplot/5.0/lua/
或类似位置。将行更改gp.write("\\gpsetdashtype{"..dashtype.."}\n")
为gp.write("$\\gpsetdashtype{"..dashtype.."}\n")
;这应该可以解决问题。为安全起见,在进行任何更改之前先复制一份。您可以执行以下操作
cd /usr/share/gnuplot/gnuplot/5.0/lua/ sudo cp gnuplot-tikz.lua gnuplot-tikz.lua.old
然后
sudo sed -i "s/\\\\\\\\gpsetdashtype/%\\\\\\\\gpsetdashtype/" gnuplot-tikz.lua