# pdflatex and pstricks

Sometimes ago I wrote a style file for drawing GANNT charts with pstricks. I typically compile my code with latex+dvips+ps2pdf, and everything works fine. However, I am now preparing a presentation where I also need to include a lot of jpg and png files, and I do not want to convert all of them into eps. So, I have to use pdflatex.

However, my style does not work with pdflatex. I tried to include packages:

\usepackage[pdf]{pstricks}


and also

\usepackage{auto-pst-pdf}


But I always get this error:

! LaTeX Error: \begin{pspicture} on input line 469 ended by \end{RTGrid}.


The problem is that I define an environment \begin{RTGrid} \end{RTGRid}, which uses pspicture inside. It looks like auto-pst-pdf cannot correctly expand my environment. Does anybody has any clue on how to solve this?

Here is my style file rtsched.sty (I apologize if my coding style is not very good!):

\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{rtsched}[2005/01/01]
\typeout{'rtsched' style for Latex and PSTricks}
\typeout{Easily draw real-time schedules in TeX/Latex.}
\typeout{(c) 2005, Giuseppe Lipari, Pisa, Italy (g.lipari@sssup.it)}
\typeout{Version 1.0}

\RequirePackage{multido}
\RequirePackage{pstricks}
\RequirePackage{keyval}

% something removed here

\def\RTGrid{\@ifnextchar[\@mygrid@begin{\@mygrid@begin[]}}

\def\RTGridBegin{\@ifnextchar[\@mygrid@begin{\@mygrid@begin[]}}
\def\@mygrid@begin[#1]#2#3{\setkeys{RT}{#1}%
\begin{pspicture}(0,0)(\RTWindowLength,\hy) %
%% draw grid (if not invisible)
\if\RTGridInvisible\RTDefGridInvisible
\multips(0,\sy)(0,\sy){\nsy}{\psline[linecolor=lightgray]{-}(0,\sy)(\RTWindowLength,\sy)}%
\multips(\sx,0)(\sx,0){\nsx}{\psline[linecolor=lightgray]{-}(0,\sy)(0,\hy)}%
\psframe(0,\sy)(\RTWindowLength,\hy)%
\else\relax
\fi
}
\def\endRTGrid{
\end{pspicture}%
}
\newcommand{\@compute@xx}[1]{
\xx = #1\sx
\divide \xx by \RTXScale
}
\newcommand{\@compute@xxx}[1]{
\xxx = #1\sx
\divide \xxx by \RTXScale
}

\newcommand{\@compute@yy}[1]{
\yy = -3\sy \multiply \yy by #1
}
\setkeys{RT}{#1}%
\@compute@yy{#2}
\@compute@xx{#3}
\yyy = \yy \advance \yyy by 2\sy
\psline[linecolor=\RTLineColor]{->}(\xx,\yy)(\xx,\yyy)
\psline[linecolor=\RTLineColor]{->}(\xx,\yyy)(\xx,\yy)
}
\setkeys{RT}{#1}%
\@compute@yy{#2}
\@compute@xx{#3}
\yyy = \yy \advance \yyy by \sy
\@compute@xxx{#4}
\advance \xx by \xxx \xx = .5\xx
\uput{2pt}[u](\xx,\yy){%
\usefont{T1}{phv}{m}{n}%
\fontsize{\RTNumberLabelSize}{\RTNumberLabelSize}%
\selectfont{\RTExecLabel}%
}
}
\endinput


And here is the example:

\documentclass{article}
\usepackage{rtsched}
\usepackage{auto-pst-pdf}
\begin{document}
\begin{RTGrid}{2}{10}
\end{RTGrid}
\end{document}


PS: since I removed many lines of code from rtsched.sty, it may be possible that after solving the error described in this post, other errors will pop up. However, it is important for me to go past this error!

-
give a complete example and not only fragments –  Herbert Sep 27 '11 at 14:25
the example is quite long. I will try to isolate the error on a simple file, and get back to you. –  knulp Sep 27 '11 at 14:31
ok, now is somehow simpler (but still many lines of code). Should I edit the question? –  knulp Sep 27 '11 at 14:38
An alternative approach would be to create the chart as a single page postscript file (with no page number). Then use ps2eps to add a bounding box, and finally use epstopdf to create a pdf for inclusion in your presentation. This is likely to be a lot simpler than getting auto-pst-pdf to work with your code. –  Ian Thompson Sep 27 '11 at 15:08
@IanThompson I will consider your suggestion. However, I would first like to see if there is a direct solution. (I can also convert all those jpg and png into eps...) –  knulp Sep 27 '11 at 15:12

That example cannot work because a lot of variables are not defined. The reason why I cannot test it.

However, try this:

\pspicture(\RTWindowLength,\hy)
%% draw grid (if not invisible)
\if\RTGridInvisible\RTDefGridInvisible
\multips(0,\sy)(0,\sy){\nsy}{\psline[linecolor=lightgray]{-}(0,\sy)(\RTWindowLength,\sy)}%
\multips(\sx,0)(\sx,0){\nsx}{\psline[linecolor=lightgray]{-}(0,\sy)(0,\hy)}%
\psframe(0,\sy)(\RTWindowLength,\hy)%
\else\relax
\fi}
\def\endRTGrid{\endpspicture}

-
It does not work. Try this link for the whole file: retis.sssup.it/~lipari/rtsched.sty –  knulp Sep 27 '11 at 16:05
ops, sorry! It works now! Thanks a lot! –  knulp Sep 27 '11 at 16:07
To conclude: the problem was the use of \begin{pspicture}. I substituted it with \pspicture, and the corresponding closing with \endpspicture, and it works. Do you know why this happens? –  knulp Sep 27 '11 at 16:12