I would like to define a tikz image element that I could re-use along a beamer presentation. I tried to define this as a pgfooclass, but this seems to be that I can only instantiate objects of a class in the frame where the class has been defined, and similarly, I can only use an instantiated object in the frame where it has been instantiated.
If I try to instantiate in a frame an object of a class defined outside a frame, I get an "Unknown class" error. I can instantiate such an object outside a frame, but I get an "Undefined control sequence" error when I try to use the object inside a frame.
Solved: The problem was due to the ignorenonframetext beamer option.
It turns out that pgfooclasses can be defined before the \begin{document}, and be then usable in frames, even with the ignorenonframetext option
Example:
\documentclass[ignorenonframetext]{beamer}
%\documentclass{beamer}
\usepackage{tikz}
\usepgfmodule{oo}
\author{bli}
% defining a class before the document
\pgfooclass{outdocclass}{
\method outdocclass(){}
\method draw(){
\node (outdoc) at (0,0) {outdoc};
}
}
\begin{document}
% defining a class outside a frame
\pgfooclass{outclass}{
\method outclass(){}
\method draw(){
\node (out) at (0,0) {out};
}
}
% instantiating an object of this class outside a frame works
%\pgfoonew \outobject=new outclass()
\begin{frame}{Class outclass is defined outside frames, and outdocclass before the beginning of the document}
Class outclass is instantiated as outobject outside frames
Class outdocclass is instantiated as outdocobject in this frame
% instantiating an object of the outocclass
\pgfoonew \outdocobject=new outdocclass()
\begin{tikzpicture}
\node at (0,1) {object outobject can be used in this picture};
%\outobject.draw()
% if the option ignorenonframetext is used:
%! Undefined control sequence.
%\beamer@doifinframe ... this picture}; \outobject
% .draw() \end {tikzpicture}...
%l.50 \end{frame}
\node[text width=0.75\textwidth] at (0,-1) {object outdocobject can be used in this picture, even with the ignorenonframetext beamer option};
\outdocobject.draw()
\end{tikzpicture}
\end{frame}
\end{document}
ignorenonframetextoption only affects text after the\begin{document}. Is there any reason why you can't declare your classes before the\begin{document}? – Andrew Stacey Oct 4 '12 at 13:44ignorenonframetexttemporarily by using\modecommands. So if you wrapped the declaration in\mode<all>{...}then that might work. – Andrew Stacey Oct 4 '12 at 13:47