pdflatex 和 pstricks

pdflatex 和 pstricks

前段时间,我编写了一个样式文件,用于使用 pstricks 绘制 GANNT 图表。我通常使用 latex+dvips+ps2pdf 编译代码,一切运行正常。但是,我现在正在准备一个演示文稿,其中还需要包含大量 jpg 和 png 文件,我不想将它们全部转换为 eps。所以,我必须使用 pdflatex。

但是,我的风格不适用于 pdflatex。我尝试包含以下包:

\usepackage[pdf]{pstricks}

并且

\usepackage{auto-pst-pdf}

但我总是收到这个错误:

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

问题是我定义了一个环境\begin{RTGrid} \end{RTGRid},其中使用了 pspicture。看来 auto-pst-pdf 无法正确扩展我的环境。有人知道如何解决这个问题吗?

这是我的样式文件 rtsched.sty(如果我的编码风格不是很好,我很抱歉!):

\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 ([email protected])}
\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
   \advance \xx by \sx
 }
 \newcommand{\@compute@xxx}[1]{
    \xxx = #1\sx
    \divide \xxx by \RTXScale
    \advance \xxx by \sx
 }

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

以下是示例:

\documentclass{article}
\usepackage{rtsched}
\usepackage{auto-pst-pdf}
\begin{document}
\begin{RTGrid}{2}{10}
  \TaskArrDead{1}{0}{5}
  \TaskArrDead{1}{5}{5}
  \TaskExecution{1}{0}{4}
\end{RTGrid}
\end{document}

PS:由于我从 rtsched.sty 中删除了许多行代码,因此在解决本文所述的错误后,可能会出现其他错误。但是,克服这个错误对我来说很重要!

答案1

该示例无法运行,因为许多变量未定义。我无法测试它的原因。

但是,尝试一下这个:

\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}

相关内容