8

Finally I have decided to go PDF. I can add pictures without EPS wrapper, and do drawings with TikZ - life is good :o)

But how do I use gnuplot? For consistency I would like to use the tikz terminal, and I would like to be able to preview my graphs without including them in a document. This

set term tikz standalone preamble '\usepackage[version=3]{mhchem}'
set output "test.tex"
plot x title '\ce{H2O}'

will make an article class document that can compile alone, but it can not be included in another document.

One solution would be not to use the standalone option, and then make a small script, that wraps the output in the standalone class. Now the document can compile alone, and it can be included in a document, but I would not be able to specify an additional preamble. :o(

Does anyone have a smart solution?

Werner
  • 603,163
  • Did you try KtikZ (QtikZ) ? You can edit the preamble of the compiling document for further modifications. – percusse Dec 03 '11 at 05:03
  • 1
    I would recommend you use PGFplots, which can use gnuplots to do the calculations, but creates the plots directly in your LaTeX document. – Jake Dec 03 '11 at 05:14
  • Apropos of @Jake's comment, tikz itself has a \draw plot function {...}; operator that passes the braced function straight to gnuplot. See the 2.10 manual, section 19.6. – Ryan Reich Dec 03 '11 at 05:31
  • I think that Hans-Peter wants to work initially in gnuplot to figure out the plot parameters and stuff, and only go to TeX for when it is to be included in the document. Am I right? In which case a simple script to strip out the preamble would seem simplest. Can you post a typical file from gnuplot? Both with and without the preamble stuff. – Andrew Stacey Dec 03 '11 at 06:02
  • I would like to tryout QtikZ(if nothing else - just for the fun of it). I am on a mac, and I read here: http://tex.stackexchange.com/questions/633/is-there-any-way-to-get-real-time-compilation-for-latex that 'brew install qt' should do something - what!? – hpekristiansen Dec 03 '11 at 06:37
  • As Andrew writes, I wold like to do my plots within gnuplot(I like automatic axes, tics, titles,...)- making a script which output does not need further editing before inclusion(so I can rerun the script, if my data changes). – hpekristiansen Dec 03 '11 at 06:42
  • @AndrewStacey: How do I post files? – hpekristiansen Dec 03 '11 at 06:43
  • 1
    @Hans-PeterE.Kristiansen: You can edit your question to include example code. I would still recommend PGFplots instead of using Gnuplot's TikZ terminal. It has all the automatic plot features, but it generates much nicer legends and titles, and in my experience it's easier to annotate your plots. – Jake Dec 03 '11 at 07:07
  • Perhaps a solution is to use gnuplottex – Alain Matthes Dec 03 '11 at 07:55
  • Take a look at an answer I gave to a question on plotting. Lower down it shows how to plot data from a file. It would be trivial to have a minimal document with pgfplots to test your plots before putting them into a main document. – qubyte Dec 03 '11 at 10:02
  • @Jake : Don't you mean that TikZ does not have all the automatic plot features? – hpekristiansen Dec 03 '11 at 20:37
  • @Hans-PeterE.Kristiansen: No, PGFplots (which uses TikZ for the drawing, and which can use gnuplot in the background for the calculations) does have all the features. – Jake Dec 04 '11 at 00:31
  • @jake : Can I read about these features(axis, tics,...) somewhere in the pgfmanual.pdf? – hpekristiansen Dec 04 '11 at 00:36
  • @Hans-PeterE.Kristiansen: PGFplots is a different package that is built on top of TikZ. The manual is here – Jake Dec 04 '11 at 00:38

1 Answers1

4

With standaloneand gnuplottexyou can get only the picture but pgfplots is preferable because it's hard to manage the font for the labels between gnuplot and latex

\documentclass{standalone}
\usepackage[]{gnuplottex} 
\usepackage[version=3]{mhchem}

\begin{document}       
  \begin{gnuplot}
      plot x title '\ce{H2O}'
  \end{gnuplot}        
\end{document} 

enter image description here

Alain Matthes
  • 95,075
  • Oooh - I think that is a solution. Instead of writing a gnuplot script, I write in latex using gnuplot. But I can still use the TikZ terminal! – hpekristiansen Dec 03 '11 at 20:08
  • :I can not compile your example - when trying pdflatex -shell-escape test.tex, I get ! Undefined control sequence. \gnuplotverbatimwrite ...e \openout \verbatim@out #1 \BeforeStream \let \do ... l.7 p lot x title '\ce{H2O}' – hpekristiansen Dec 03 '11 at 20:10
  • I managed to compile the example after editing the gnuplottex.sty as described by sdaau here: http://tex.stackexchange.com/questions/16393/gnuplottex-basic-example-fails-with-undefined-control-sequence – hpekristiansen Dec 03 '11 at 23:35