4

Possible Duplicate:
Wrapping code (listings, verbatim, or other method) inside a newcommand

I'm new to LaTeX and trying to write a command to plot files using the gnuplottex package (and gnuplot).

For now I am doing this (and it works):

\documentclass{article}
\usepackage{gnuplottex}

\begin{document}
\begin{gnuplot}[terminal=pdf,scale=1]
    plot 'testfile' using 1:2
\end{gnuplot}
\end{document}

What I would like to do is:

\documentclass{article}
\usepackage{gnuplottex}

\newcommand{\plotdata}[1]
{
    \begin{gnuplot}[terminal=pdf,scale=1]
        plot '#1' using 1:2
    \end{gnuplot}
}

\begin{document}
\plotdata{testfile} % this is the goal
\end{document}

But the build fails in the second case due to gnuplot errors (it fails to produce plots).

I'm using TeXLive/Ubuntu. Any ideas, why it does not work (or how I can see the code generated after \newcommand macros execution)?

  • What are the errors? What does #1 mean? Where should it come from? – Bernhard Mar 25 '12 at 10:15
  • For your last question, use \show\plotdata. – Caramdir Mar 26 '12 at 03:30
  • 1
    The problem is that the contents of the gnuplot environment are scanned like a verbatim. Putting verbatim-like environments into a command usually runs into problems. I don't know any workarounds, but maybe someone else can pick up from here. – Caramdir Mar 26 '12 at 03:35
  • See also http://www.tex.ac.uk/cgi-bin/texfaq2html?label=verbwithin – Caramdir Mar 26 '12 at 03:42

0 Answers0