# Using \def in \psplot

For reasons I cannot explain \def's don't seem to always work in/with \psplot as shown below

\documentclass[english, landscape, a4paper]{slides}

\usepackage{graphics}
\usepackage{graphicx}
\usepackage{babel}
\usepackage{fp}
\usepackage{pst-plot}
\usepackage{pstricks}

\usepackage[active,tightpage]{preview}
\PreviewBorder=4pt
\PreviewEnvironment{pspicture}

\begin{document}
\begin{center}
\begin{pspicture*}(-1.5,-1)(1.5,1.5)
\def\tI{0.0}
\psplot{0.0}{1.0}{x \tI sub}   % does not work
% \psplot{0.0}{1.0}{x \tI sub} % works
\end{pspicture*}
\end{center}
\end{document}


I compile the above file with xelatex file and get the error

Error: /undefined in 0.0sub
Operand stack:
--nostringval--   0.0   0.0
Execution stack:
%interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %s
--nostringval--   --nostringval--   false   1   %stopped_push   1910   1   3   %oparray_
pop   1893   1   3   %oparray_pop   1787   1   3   %oparray_pop   --nostringval--   %error
ingval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nos
...
** WARNING ** Filtering file via command -->mgs.exe -q -dNOPAUSE -dBATCH -sPAPERSIZE=a0 -s
yLevel=1.3 -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode -dAutoFilterColorIm
/FlateEncode -dUseFlateCompression=t


Can someone please suggest a workaround for this problem?

-
use \space after \tl –  Who is crazy first Sep 29 '12 at 17:45
Use: \psplot{0.0}{1.0}{x \tI\space sub} –  Marco Daniel Sep 29 '12 at 17:45
Just to add why: the space after \tI gets ignored while reading the input (it follows a command name) and the error line 0.0sub shows it. However, the common trick of putting {} after the command can't work here, while \space does the right thing. –  egreg Sep 29 '12 at 17:47

1. When you want to get a tight, separate PDF output for each pspicture, you can use standalone class instead of preview package to save some keystrokes.
2. Only use graphicx (the modern one) and it loads graphics internally.
3. Remove unnecessary packages.
4. No need to use center environment if you need to generate a tight, separate PDF output for each pspicture.
5. Only use pspicture* to trim the objects outside the canvas. If no objects outside the canvas exist, just use pspicture without stars.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}

\begin{document}
\begin{pspicture}[showgrid](-1.5,-1)(1.5,1.5)
\def\tI{0.0}
\psplot{0.0}{1.0}{x \tI\space sub}
\end{pspicture}
\end{document}


Now let's discuss your problem. Control words will eat spaces following them. So x \tI sub becomes x 0.0sub that is no meaning. To preserve the spaces, you need to use \space as shown in the code above.

## Another solution:

Make sure you put at least one space before the closing } in your macro definition. See the code below.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}

\begin{document}
\begin{pspicture}[showgrid](-1.5,-1)(1.5,1.5)
\def\tI{0.0 }% can you see there is one space before the closing }?
\psplot{0.0}{1.0}{x \tI sub}
\end{pspicture}
\end{document}

-
I think I don't need to add an animated version. –  Who is crazy first Sep 29 '12 at 18:35

use always a definition with a space at the end:

\def\tI{0.0 }


then you do not need the \space macro for the function.

-
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. –  Tom Bombadil Sep 29 '12 at 19:21
it could be good idea that you read the question! –  Herbert Sep 29 '12 at 19:24
It's the same what ガベージコレクタ did and also commented in his code. So your answer is nothing additional and should, in my humble opinion be a comment to ガベージコレクタ's answer. –  Tom Bombadil Sep 29 '12 at 19:26