Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Considerations:

  • I have to use beamer document class to create a step-by-step tutorial.
  • I have to use preview package to trim everything outside pspicture.
  • Using standalone document class is not possible because we cannot accomplish both requirements above.
  • I have to define constants that must be available in both TeX and PostScript worlds.
  • Constant declarations must not be verbose. A single declaration must provide a constant in both worlds at once.

What I have done:

  • I have defined (with the help of David Carlisle) a macro \const[]{}{} to defined a constant in both TeX and PostScript worlds at once. Please see the MWE below for the details.

MWE:

\documentclass{beamer}
\usepackage[nomessages]{fp}
\newcommand\const[3][6]{%
    \edef\temporary{trunc(#3}%
    \expandafter\FPeval\csname#2\expandafter\endcsname
        \expandafter{\temporary:#1)}%
        \pstVerb{/#2 \csname#2\endcsname\space def}%
}

\usepackage{pst-node}

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

\const{Major}{3}% semi major
\const{Minor}{2}% semi minor

\begin{document}
\begin{frame}
\begin{pspicture}[showgrid](-\Major,-\Minor)(\Major,\Minor)
    \pause
    \psellipse(0,0)(!Major Minor)% produces GhostScript errors
    %\psellipse(0,0)(!\Major\space \Minor)
\end{pspicture}
\end{frame}
\end{document}

Problems:

Compilation with GhostScript fails because all constants in PostScript world get discarded by preview.

Failed Solutions:

  • Moving

    \const{Major}{3}% semi major
    \const{Minor}{2}% semi minor
    

    from preamble to the body of pspicture

    \begin{frame}
    \begin{pspicture}[showgrid](-\Major,-\Minor)(\Major,\Minor)
        \const{Major}{3}% semi major
        \const{Minor}{2}% semi minor
        \pause
        \psellipse(0,0)(!Major Minor)% produces GhostScript errors
        %\psellipse(0,0)(!\Major\space \Minor)
    \end{pspicture}
    \end{frame}
    

    is not possible because the constants in TeX world must be accessible for \begin{pspicture}[showgrid](-\Major,-\Minor)(\Major,\Minor).

Bad Solutions:

  • Using \psellipse(0,0)(!\Major\space \Minor) instead of \psellipse(0,0)(!Major Minor) makes the RPN expressions cryptic.

  • Using \pstheader is not convenient because I have to declare a single constant for each world manually.

Promising Idea:

Edit \const[]{}{} implementation to create a new header file (if not exists) and append each PostScript constant to the the header file. Later this header file can be loaded with \pstheader{} macro.

Question:

How to prevent preview from discarding my PostScript constants defined in the preamble while making my scenario done?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You can save up your ps definitions and inject them inside the pspicture:

\documentclass{beamer}
\usepackage[nomessages]{fp}
\newcommand\const[3][3]{%
    \edef\temporary{round(#3}%
    \expandafter\FPeval\csname#2\expandafter\endcsname
        \expandafter{\temporary:#1)}%
        \edef\pspicturedefs{\pspicturedefs
            \noexpand\pstVerb{/#2 \csname#2\endcsname\space def}}%
}

\usepackage{pst-node}

\def\pspicturedefs{}

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

\const{Major}{3}% semi major
\const{Minor}{2}% semi minor

\begin{document}
\begin{frame}
\begin{pspicture}[showgrid](-\Major,-\Minor)(\Major,\Minor)
\pspicturedefs
    \pause
    \psellipse(0,0)(!Major Minor)% produces GhostScript errors
    %\psellipse(0,0)(!\Major\space \Minor)
\end{pspicture}
\end{frame}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.