3

I am writing a book based on lecture notes I have written using beamer. In these notes I have figures drawn using TikZ which I would like to transfer to the book. However, some of them use \only to show different subfigures. This does not work in the memoir class. Is there a way to emulate it, with say an environment in which I specify the particular slide I want, \begin{selectslide}{2} ... \end{selectslide}? My alternative is to extract the right slide manually which is tedious and error-prone.

Liam
  • 461
  • 5
  • 12
  • One option is to extract the desired slide from the presentation PDF, crop it (to get rid of fooline/headline) and then include it in your document using a standard \includegraphics. – Gonzalo Medina Feb 19 '15 at 03:36
  • Yes, I suppose that would work. I was hoping for something a little bit simpler. – Liam Feb 19 '15 at 03:39
  • It is pretty easy to simply throw the overlay specifications away so that they are ignored entirely. But I doubt there is a 'little bit simpler' way to extract a particular point other than the one you'd get with handout mode. Does the beamer package not work with memoir? I presume it would work with book. – cfr Feb 19 '15 at 04:24
  • I asked the same thing here: http://tex.stackexchange.com/questions/214474/is-it-possible-to-use-beamers-overlay-specifications-in-other-documentclasses I'd still like to know a satisfying answer. – Turion Feb 23 '15 at 22:23
  • By the way, my solution was to define a "none"-style which one could apply to parts of the picture to hide it. If that would be suitable for you, let me knew, I can write the essential steps as an answer here. – Turion Feb 23 '15 at 23:19
  • @Turion: Thank you for the link to your question. I did search the site but did not see your question before. I am interested in your solution. – Liam Feb 24 '15 at 03:32

2 Answers2

2

If you only want emulate \only, especially in the context of TikZ, then we could write a little parser to do this.

\documentclass[12pt]{article}
\usepackage{tikz}

\makeatletter
\newcounter{only@begin}%
\newcounter{only@end}%
\def\@only@hyphen{-}%
\def\only<#1>#2{%
  \bgroup
    \def\only@test{#1}%
    \ifx\only@test\@only@hyphen
      \c@only@begin=-100\relax
      \c@only@end=100\relax
    \else
      \parseonlybegin\only@relax#1-\endparseonly
      \parseonlyend\only@relax#1-\endparseonly
    \fi
    \advance\c@only@begin by -1\relax
    \advance\c@only@end by 1\relax
    \ifnum\c@only@begin<\slide\relax
      \ifnum\c@only@end>\slide\relax
        #2\relax
      \fi
    \fi
  \egroup
}

\def\@only@relax{\only@relax}%
\def\only@striponetoken#1{}%
\def\only@gobblehyphen#1-{#1}
\def\parseonlybegin#1-#2\endparseonly{%
  \def\only@test{#1}%
  \ifx\only@test\@only@relax
    \setcounter{only@begin}{-100}%
  \else
    \expandafter\c@only@begin\only@striponetoken#1\relax%
  \fi
}
\def\parseonlyend#1-#2\endparseonly{%
  \def\only@test{#2}%
  \ifx\only@test\@empty
    % No hyphen in original.
    \c@only@end=\c@only@begin%
  \else
    \ifx\only@test\@only@hyphen
      % \only<a->
      \setcounter{only@end}{100}%
    \else
      % \only<a-b> or \only<-b>; #2 contains 'b-'
      \expandafter\c@only@end\only@gobblehyphen#2\relax%
    \fi
  \fi
}

\makeatother
\begin{document}

\def\mypic#1{%
  \def\slide{#1}%
  \begin{tikzpicture}[every node/.style={anchor=base,circle, draw}]
    \draw (0,0) rectangle (6,2);
    \node at (1,1) {a};
    \only<2->{ \node at (2,1) {b}; }
    \only<2-3>{ \node at (3,1) {c}; }
    \only<3>{ \node at (4,1) {d}; }
    \only<-4>{ \node at (5,1) {e}; }
  \end{tikzpicture}%
  \par
}

\mypic{1}%
\mypic{2}%
\mypic{3}%
\mypic{4}%
\mypic{5}%

\end{document}

I make no claims to have good TeX coding style, but this compiles to enter image description here

  • I tried this and it did not work; I got an error. I have been meaning to dig more into the problem but haven't had the time. If I am able to figure out the problem I will post again. – Liam Dec 24 '15 at 15:51
1

I unfortunately don't know how to do it with beamer overlay specifications. But TikZ styles are very powerful and can be used to emulate a similar behaviour, although I don't know a way to cut the boilerplate code.

Here is a documented example. Let me know if you have questions.

\documentclass{article}

\usepackage{tikz}
\begin{document}
    \tikzset{
        % Define the 'none'-style, which hopefully ensures that nothing is being drawn visibly.
        none/.style         = {
            draw               = none,
            fill               = none,
            text opacity       = 0
        },
        % --------------------------
        % Boilerplate code to roughly emulate beamer overlay behaviour.
        % Use the 'onlyslide'-style in all nodes, paths etc. that you want to appear only on one specific slide.
        % You can't use more than one onlyslide on one node or path.
        onlyslide1/.style   = {none},
        slide1/.style       = { onlyslide1/.style = {} },
        % Copy the code for every slide
        onlyslide2/.style   = {none},
        onlyslide3/.style   = {none},
        % This is what you could do if you wanted something to appear on more than one slides, but not on all
        onlyslides23/.style = {none},
        slide2/.style       = {
            onlyslide2/.style  = {},
            onlyslide23/.style = {}
        },
        slide3/.style       = {
            onlyslide3/.style  = {},
            onlyslide23/.style = {}
        },
        % --------------------------
        % This is the actual image you want to draw. I'm drawing it as a pic for convenience.
        % You would need TikZ 3.0 for that to work. But you can use the styles above also in a normal tikzpicture.
        yourimage/.pic      = {
            \node[draw,onlyslide1]          {Only visible on slide 1};
            \node[draw,onlyslide2] at (2,0) {Only visible on slide 2};
            \node[draw]            at (6,0) {Always visible};
        }
    }

    % --------------------------
    % Finally, let's use all that in your actual document:

    This is how it looks on the first slide:

    \begin{tikzpicture}[slide1]
        \pic {yourimage};
    \end{tikzpicture}

    This is how it looks on the second slide:

    \begin{tikzpicture}[slide2]
        \pic {yourimage};
    \end{tikzpicture}
\end{document}

The result should look like this:

enter image description here

Turion
  • 4,622