비머 문서의 그림에서만 에뮬레이션

비머 문서의 그림에서만 에뮬레이션

나는 비머를 사용하여 쓴 강의 노트를 바탕으로 책을 쓰고 있습니다. 이 노트에는 책으로 옮기고 싶은 TikZ를 사용하여 그린 그림이 있습니다. 그러나 그 중 일부는 다른 하위 그림을 표시하기 위해 \only를 사용합니다. 회고록 수업에서는 작동하지 않습니다. 내가 원하는 특정 슬라이드를 지정하는 환경 등을 에뮬레이트할 수 있는 방법이 있습니까 \begin{selectslide}{2} ... \end{selectslide}? 내 대안은 지루하고 오류가 발생하기 쉬운 올바른 슬라이드를 수동으로 추출하는 것입니다.

답변1

\only특히 TikZ의 맥락에서 에뮬레이션만 원한다면 이를 수행하기 위한 작은 파서를 작성할 수 있습니다.

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

나는 좋은 TeX 코딩 스타일을 가지고 있다고 주장하지 않습니다. 그러나 이것은 다음과 같이 컴파일됩니다. 여기에 이미지 설명을 입력하세요

답변2

불행하게도 비머 오버레이 사양으로 이를 수행하는 방법을 모르겠습니다. 하지만TikZ 스타일매우 강력하고 유사한 동작을 에뮬레이트하는 데 사용할 수 있지만 상용구 코드를 자르는 방법은 모르겠습니다.

다음은 문서화된 예입니다. 궁금한 점이 있으면 알려주세요.

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

결과는 다음과 같아야 합니다.

여기에 이미지 설명을 입력하세요

관련 정보