2

Objectives:

I want to throw exceptions (or error messages) when the following illegal code is invoked.

\const[c,any]{temp}{\f[\i]}
\const[others]{temp}{\f[\i]}

Minimal Working Example:

I cannot minimize the code because minimizing it might be no longer applicable to the real scenario.

\documentclass{beamer}
\usepackage{multido}
\usepackage{pstricks}
\usepackage[nomessages]{fp}

\def\filter#1,#2#3\relax#4{%
    \if t#1
        trunc(#4:#2)%
    \else   \if r#1 
        round(#4:#2)%
    \else   \if c#1
        clip(#4)%
    \else
        \ERRORHERE
    \fi\fi\fi}

% \pstVerb concatenator
\def\LoadConstants{}

% Constant declarator invoked in the preamble
\newcommand\const[3][]{%
    \if\relax\detokenize{#1}\relax
        \edef\temporary{#3}%
    \else
        \edef\temporary{\filter#1,any\relax{#3}}%
    \fi
    \expandafter\FPeval\csname#2\expandafter\endcsname
        \expandafter{\expandafter{\temporary}}%
    \toks0=\expandafter{\LoadConstants\pstVerb}
    \edef\LoadConstants{\the\toks0 {/#2 \csname#2\endcsname\space def}}}

\makeatletter
\def\pst@@picture@i[#1]#2(#3,#4){%
% BEGIN - redefine \const for invocation inside pspicture
    \renewcommand\const[3][]{%
    \if\relax\detokenize{##1}\relax
        \edef\temporary{##3}%
    \else
        \edef\temporary{\filter##1,any\relax{##3}}%
    \fi
    \expandafter\FPeval\csname##2\expandafter\endcsname
        \expandafter{\expandafter{\temporary}}%
        \pstVerb{/##2 \csname##2\endcsname\space def}\ignorespaces}%
% END - redefine \const for invocation inside pspicture
    \@ifnextchar(% ignore anything between [] and ()
% BEGIN - inject \LoadConstants into pspicture
    {\pst@@@picture[#1](#3,#4)\LoadConstants}%
    {\pst@@@picture[#1](0,0)(#3,#4)\LoadConstants}%
% END - inject \LoadConstants into pspicture    
}
\makeatother

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


\SpecialCoor
\const{Side}{root(2,17)}% the square root of 17
\def\f[#1]{cos(#1*pi/180)}

\begin{document}
\begin{frame}   
\begin{pspicture}(\Side,\Side)
    \psframe(!Side dup)\pause
    \multido{\i=0+30}{12}{%
        \const{temp}{\f[\i]}% legal
        \const[r,3]{temp}{\f[\i]}% legal
        \const[t,3]{temp}{\f[\i]}% legal
        \const[c]{temp}{\f[\i]}% legal
        %\const[c,any]{temp}{\f[\i]} must throw an error and terminate the compilation.
        %\const[others]{temp}{\f[\i]} must throw an error and terminate the compilation.
        \rput{\i}(!Side 2 div dup dup \i\space PtoC 3 1 roll add 3 1 roll add){$\temp$}\pause
    }
\end{pspicture}
\end{frame}
\end{document}

NOTE:

For this problem please give me fish rather than comments how to catch fish because it will become useless, confusing, etc.

  • Error-reporting can be invoked using: \@latex@error{<message>}{<error handler>} – Werner Apr 27 '13 at 20:42
  • You'd like to abort the compilation when you're building a pspicture, which is rather complicated: \end (the primitive TeX command) isn't legal other than in the outer vertical mode: see "The TeXbook", p. 283. – egreg Apr 27 '13 at 20:57
  • @egreg: No. Abortion must be in TeX compilation first so dvips and ps2pdf have no chance to compile. – kiss my armpit Apr 27 '13 at 20:58
  • There is no "abort" command, except during error recovery, requiring the user to press the X key. The only way to abort a TeX run without user intervention is by using \end (\@@end in LaTeX). – egreg Apr 27 '13 at 21:02
  • @Werner you can't use error messages there (in an edef) undefined command is teh only error possible in an edef (more or less) – David Carlisle Apr 27 '13 at 21:35
  • @Bugbusters I can not see what is wrong with this code (that I suggested in chat) It gives an error ! Undefined control sequence. \filter ...\else \if c#1 clip(#4)\else \ERRORHERE which is the only error you can throw in an edef. – David Carlisle Apr 27 '13 at 21:40
  • Also (unrelated to question) you are missing % at ends of line in the definition after the three #1 in the i.f tests – David Carlisle Apr 27 '13 at 21:54

0 Answers0