환경에 대한 연속 호출 테스트

환경에 대한 연속 호출 테스트

저는 비머를 사용하여 통계 수업을 위한 슬라이드를 만들고 이제 파워포인트와 유사한 출력을 생성하는 아주 좋은 설정을 갖게 되었습니다(질문 참조:Beamer를 사용하여 페이지당 3개의 슬라이드를 옆에 메모와 함께 넣습니다(예: PowerPoint)).

이 시스템이 작동하려면 각 슬라이드의 슬라이드와 연결된 노트에 대한 정의가 필요합니다. 그렇지 않으면 노트가 슬라이드와 동기화되지 않게 됩니다. 동기화가 절대 해제되지 않도록 슬라이드에 대한 "기본" 노트 정의를 정의하는 더 좋은 방법이 있을 수 있지만 이는 라텍스에 대한 내 능력을 넘어서는 것이며 환경이 충분히 복잡하여 MWE를 게시하면 (나를 위해) 힘들어요.

대신 슬라이드에 정의된 노트가 없다는 오류라도 잡아내고 싶습니다. 제가 생각할 수 있는 가장 쉬운 방법은 아래와 같은 MWE로 축소되었습니다.

\documentclass[10pt]{article}

\newcounter{mypagecount}
\setcounter{mypagecount}{1}

\newcommand\incpagecount{
  \stepcounter{mypagecount}
}
\newcommand\getpagecount{
  \themypagecount
}

\newenvironment{mypage}[1]{%
Parameter: #1 Expected: \getpagecount Body :}{ \incpagecount \\ }

\begin{document}

\begin{mypage}{1} foo \end{mypage}
\begin{mypage}{2} foo \end{mypage}
\begin{mypage}{4} foo \end{mypage}
\begin{mypage}{5} foo \end{mypage}

\end{document}

질문: mypage {3}에 대한 호출이 없음을 감지하면 라텍스에서 오류가 발생하도록 하려면 어떻게 해야 합니까? c 프로그래머의 경우, 매개변수가 예상 값과 동일하지 않다는 c 스타일 주장을 사용하는 방법을 보여주는 것이 좋을 것입니다!

모두 감사합니다.

답변1

주장하지 마세요. .!=\if, \ifdim, \ifx, \ifcase, \@ifundefined, 등도 있습니다 \@ifl@aded. TeXbook(Knuth) 및 source2e.pdf(CTAN)를 참조하세요.

환경 외부에서는 로컬 정의를 사용할 수 없습니다. 다행히 카운터 작업에서는 글로벌 버전을 사용합니다. 사용할 수 있지만 \global\let사용할 수 는 없습니다.\xdef\setlength\renewcommand

\documentclass[10pt]{article}

\newcounter{mypagecount}
\setcounter{mypagecount}{1}

\newcommand\incpagecount{%
  \stepcounter{mypagecount}%
}
\newcommand\getpagecount{% redundant
  \themypagecount
}

\newenvironment{mypage}[1]{%
\ifnum\value{mypagecount}=#1\relax
\else
  \errmessage{Parameter: #1 Expected: \getpagecount}%
  \setcounter{mypagecount}{#1}%
\fi
\noindent Body :}%
{ \incpagecount \\ }

\begin{document}

\begin{mypage}{1} foo \end{mypage}
\begin{mypage}{2} foo \end{mypage}
\begin{mypage}{4} foo \end{mypage}
\begin{mypage}{5} foo \end{mypage}

\end{document}

답변2

나는 다른 해결책을 제안합니다. 이것은 현재 개념 증명입니다. 특히 환경 이외의 옵션을 전달하면 실패 label합니다 frame. 제 생각에는 이 문제를 해결할 수 있지만 문제가 복잡해질 것입니다.

아이디어는 슬라이드를 다른 방식으로 유인물에 포함시키는 것입니다. 이는 Beamer의 beamerarticle패키지, 환경 label옵션 frame\includeslide매크로를 사용합니다. 또한 ( s 등을 사용 xcoffins하는 데 너무 좌절했기 때문에 ) 및 .minipageenviron

작업 흐름:

  • 3개의 파일 중 2개는 세 번째 파일을 입력하는 매우 간단한 래퍼입니다.

  • 세 번째 파일에는 가 포함되어 있지 않지만 \documentclass슬라이드와 노트가 모두 포함되어 있습니다. 이것이 이라고 가정해보자 <main file name>.tex.

  • 슬라이드는 frame평소와 같이 환경에서 진행됩니다. 옵션 을 사용하여 라벨이 지정됩니다 label.

  • 메모는 annot환경에 저장됩니다. 여기에는 해당 슬라이드에 대한 레이블을 제공하는 인수가 필요합니다. (일반적으로 슬라이드를 참조하는 경우 이 인수를 제공합니다 \ref{}.) 선택적 인수를 사용하여 슬라이드를 포함할 때 사용되는 설정을 재정의할 수 있습니다.

  • 첫 번째 래퍼는 슬라이드를 생성하기 위해 컴파일됩니다. 나는 이것을 불렀다 <main file name>-beamer.tex. 이 파일의 내용은 다음과 같아야 합니다.

    \pdfminorversion=7% comment this out if not using pdftex
    \documentclass[ignorenonframetext]{beamer}
    \input{<main file name>}% substitute appropriately here
    

    이건 컴파일해야 해첫 번째.

  • 두 번째 래퍼는 유인물을 생성하기 위해 컴파일됩니다. 클래스와 비머 모드를 <main file name>-article.tex사용했기 때문에 이렇게 부르게 되었습니다 . 이 파일의 내용은 다음과 같아야 합니다.articlearticle

    \pdfminorversion=7% comment this out if not using pdftex
    \documentclass{article}% adjust if you prefer a different class
    \usepackage{beamerarticle,graphicx}
    \setjobnamebeamerversion{<main file name>-beamer}% substitute appropriately here
    \input{<main file name>}% substitute appropriately here
    

    이건 컴파일해야 해두번째.

그런 다음 <main file name>.tex나머지 서문과 document본문을 넣습니다. 나는 대부분의 사용자 정의 항목을 여기 서문에 넣어 Beamer article모드로 제한했지만 원하는 경우 이를 유인물 래퍼로 이동할 수 있습니다.

% \jobname.tex = <main file name>.tex
\mode<article>
{

이는 모드에서만 실행됩니다 article.

  \usepackage{xcoffins,environ,geometry,calc,pgf}

xcoffins, environpgfcalc필요합니다. geometry방금 나쁜 상자를 제거했습니다.

첫째, 나중에 필요한 몇 가지 새로운 길이입니다.

  \newlength\annotsep
  \setlength\annotsep{.5em}% set the horizontal separation of frames and annotations
  \newlength\frmwd
  \AtBeginDocument{%
    \setlength\frmwd{.5\linewidth-.5\annotsep-2\fboxsep-2\fboxrule}%
  }

그리고 관 두 개.

  \NewCoffin\AnnotCoffin
  \NewCoffin\FrameCoffin

이제 우리는 환경을 정의 annot하지만 전체 콘텐츠를 관에 넣고 싶어서 \NewEnviron보다는 사용하는 것이 가장 쉬울 것 같았습니다. \newenvironment(여기서는 구문을 피하려고 했습니다 expl3.)

  \NewEnviron{annot}[2][]{%
    \edef\tempa{\extractedref}\edef\tempb{#2}%
    \ifx\tempa\tempb\relax
    \else\outputempty\fi\xdef\extractedref{}%

이 주석에 대한 프레임 외에 슬라이드를 넣지 않은 프레임이 있는지 확인합니다. 이 노트 세트와 일치하지 않는 라벨이 있는 경우 frame프레임에 노트가 없다고 가정하고 대신 오른쪽에 공백을 출력합니다.

\FrameCoffin이제 관련 슬라이드(즉, annot환경의 필수 인수를 사용하여 참조한 슬라이드) 의 액자 복사본을 사용하여 첫 번째 관인 을 설정합니다 .

    \SetVerticalCoffin\FrameCoffin{.5\linewidth-.5\annotsep}{%
      \fbox{\includeslide[width=\frmwd,#1]{#2}}% depending on theme, remove frame if not required
    }%

\AnnotCoffin이제 우리는 메모를 위한 두 번째 관을 설치했습니다 .

    \SetVerticalCoffin\AnnotCoffin{.5\linewidth-.5\annotsep}{%
      \BODY
    }%

우리는 상단에 관을 결합하여 노드를 약간 가로 질러 아래로 밀어냅니다.

    \JoinCoffins\FrameCoffin[t,r]\AnnotCoffin[t,l](\annotsep,-.5\baselineskip)

슬라이드가 페이지에서 균등한 간격을 갖도록 관을 조판하고 유연한 수직 공간을 남겨두십시오.

    \TypesetCoffin\FrameCoffin
    \medskip\vfill\par
  }
  \usepackage{kantlipsum}

이 패키지는 예시일 뿐입니다. Kant의 관련 발췌문을 조판하고 아마도 오래된 번역에 신경 쓰지 않는 한 실제 문서에 이것을 로드하지 마십시오.

몇 가지 새로운 명령.

  \newcommand\extractref{}
  \newcommand\extractedref{}

그 중 하나를 도우미 매크로로 정의하세요.

  \def\extractref label=#1\null{#1}

frame이는 모드 의 정의를 변경합니다 article. 일반적으로 Beamer는 frame모든 모드에서 콘텐츠를 조판합니다. 그러나 여기서 우리는 그것을 원하지 않습니다. 단일 선택적 인수를 취하도록 정의합니다. 다른 모든 것은 사라질 것입니다. 그러나 선택적 첫 번째 인수가 있고 비어 있지 않은 경우 이를 a라고 가정 label=<key for label>하고 이 참조를 추출합니다.

  \RenewEnviron{frame}[1][]{%
    \edef\tempa{#1}\edef\tempb{}%
    \ifx\tempa\tempb\relax
    \else
      \outputempty

trac을 유지하는 매크로가 \extractedref비어 있지 않으면 해당 노트 세트가 없는 슬라이드가 있으므로 슬라이드에 노트가 없다고 가정하고 오른쪽에 빈 노트 세트와 함께 해당 슬라이드를 출력합니다.

      \xdef\extractedref{\extractref #1\null}%

현재 의 경우 frame아무것도 조판하지 않습니다. 우리는 참조를 추출하여 \extractedref.

    \fi
  }

이제 주석 없이 s를 출력하는 매크로입니다 frame. 이는 재정의된 환경 frame과 환경 에서 사용됩니다 annot.

  \newcommand\outputempty{%
    \edef\tempb{}%
    \edef\tempa{\extractedref}%
    \ifx\tempa\tempb\relax
    \else

여기에는 관이 필요하지 않지만 기본 구성을 사용하여 슬라이드를 출력하고 동일한 수직 공간을 넣어 슬라이드가 페이지에 고르게 퍼지도록 합니다.

      \fbox{\includeslide[width=\frmwd]{\extractedref}}%
      \medskip\vfill\par
    \fi
  }
}

여기서 단락 들여쓰기를 원하지 않는 것 같습니다. 패키지 사용을 고려할 수도 있지만 parskip메모 내용에 따라 중요하지 않을 수도 있습니다.

  \setlength\parindent{0pt}

마지막 항목 frame에 라벨이 붙어 있지만 메모가 없으면 유인물에 들어가도록 해야 합니다. 한 명 더 \outputempty해야 합니다.

  \AtEndDocument{\outputempty}

그것이 바로 구성입니다. 이제 문서입니다.

\begin{document}

여기 프레임이 있습니다 frame-a.

\begin{frame}[label=frame-a]{A Frame}%
  \includegraphics[height=.75\textheight,width=\textwidth,keepaspectratio]{example-image-a}
\end{frame}

에 대한 참고 사항은 다음과 같습니다 frame-a.

\begin{annot}{frame-a}
  Not much to say about image A.
\end{annot}

마찬가지로, frame-bframe-c.

\begin{frame}[label=frame-b]{B Frame}%
  \includegraphics[height=.75\textheight,width=\textwidth,keepaspectratio]{example-image-b}
\end{frame}
\begin{annot}{frame-b}
  Not much to say about image b.
\end{annot}

\begin{frame}[label=frame-c]{C Frame}%
  \includegraphics[height=.75\textheight,width=\textwidth,keepaspectratio]{example-image-c}
\end{frame}
\begin{annot}{frame-c}
  Not much to say about image C.
\end{annot}

geometry그러면 의 기본 레이아웃 으로 페이지가 만들어집니다 .

여기 있습니다 frame-another. 이건 메모가 부족해서 따라갈 수 없습니다 annot.

\begin{frame}[label=frame-another]{Another Frame}%
  \includegraphics[height=.75\textheight,width=\textwidth,keepaspectratio]{example-image}
\end{frame}

모드 에서는 해당 프레임에 대한 메모가 없다고 가정하므로 article다음 프레임이 출력됩니다 . MWE의 이미지가 다 떨어져서 지루해졌기 때문에 여기에 좋은 대안이 있습니다.frame-anotherframe

\begin{frame}[label=frame-tiger]{Tiger Frame}%
  \includegraphics[height=.75\textheight,width=\textwidth,keepaspectratio]{tiger}
\end{frame}
\begin{annot}{frame-tiger}
  This frame shows a large, wild cat.
  Well, what it actually shows is a small picture of a wild cat, but you are meant to infer that it represents a larger reality.
\end{annot}

다음에 frame는 메모가 매우 길어서 별도의 페이지로 끝납니다. 여기서는 포효가 조금 적지만 아마도 숫자로는 안전할 것입니다.

\begin{frame}[label=frame-cats]{Cats Frame}%
  \includegraphics[height=.75\textheight,width=\textwidth,keepaspectratio]{cathod}
\end{frame}
\begin{annot}{frame-cats}
  \kant[1-2]
\end{annot}

\begin{frame}[label=frame-which]{Which Frame?}%
 \includegraphics[height=.75\textheight,width=\textwidth,keepaspectratio]{cauldron}
\end{frame}
\begin{annot}{frame-which}
  This frame includes a pun, a cauldron and a question.
  More accurately, it includes a pun, a depiction of a cauldron and a question mark.
\end{annot}

그리고 마지막으로, 최종 결과가 제대로 작동하는지 frame확인하기 위한 메모가 없습니다.\outputempty

\begin{frame}[label=frame-gadael]
  \includegraphics[width=\textwidth]{cath-gadael-chartref}
\end{frame}

\end{document}

슬라이드:

슬라이드

유인물/메모:

메모가 있는 유인물

전체 코드(표시된 경우 파일 이름을 대체해야 함):

\begin{filecontents}{\jobname-beamer.tex}
\documentclass[ignorenonframetext]{beamer}
\input{<main file name>}% substitute \jobname or whatever here
\end{filecontents}
\begin{filecontents}{\jobname-article.tex}
\documentclass{article}
\usepackage{beamerarticle,graphicx}
\setjobnamebeamerversion{<main file name>-beamer}% substitute \jobname or whatever here
\input{<main file name>}% substitute \jobname or whatever here
\end{filecontents}

% \jobname.tex = <main file name>.tex
\mode<article>
{
  \usepackage{xcoffins,environ,geometry,calc,pgf}
  \newlength\annotsep
  \setlength\annotsep{.5em}% set the horizontal separation of frames and annotations
  \newlength\frmwd
  \AtBeginDocument{%
    \setlength\frmwd{.5\linewidth-.5\annotsep-2\fboxsep-2\fboxrule}%
  }
  \NewCoffin\AnnotCoffin
  \NewCoffin\FrameCoffin
  \NewEnviron{annot}[2][]{%
    \edef\tempa{\extractedref}\edef\tempb{#2}%
    \ifx\tempa\tempb\relax
    \else\outputempty\fi\xdef\extractedref{}%
    \SetVerticalCoffin\FrameCoffin{.5\linewidth-.5\annotsep}{%
      \fbox{\includeslide[width=\frmwd,#1]{#2}}% depending on theme, remove frame if not required
    }%
    \SetVerticalCoffin\AnnotCoffin{.5\linewidth-.5\annotsep}{%
      \BODY
    }%
    \JoinCoffins\FrameCoffin[t,r]\AnnotCoffin[t,l](\annotsep,-.5\baselineskip)
    \TypesetCoffin\FrameCoffin
    \medskip\vfill\par
  }
  \usepackage{kantlipsum}
  \newcommand\extractref{}
  \newcommand\extractedref{}
  \def\extractref label=#1\null{#1}
  \RenewEnviron{frame}[1][]{%
    \edef\tempa{#1}\edef\tempb{}%
    \ifx\tempa\tempb\relax
    \else
      \outputempty
      \xdef\extractedref{\extractref #1\null}%
    \fi
  }
  \newcommand\outputempty{%
    \edef\tempb{}%
    \edef\tempa{\extractedref}%
    \ifx\tempa\tempb\relax
    \else
      \fbox{\includeslide[width=\frmwd]{\extractedref}}%
      \medskip\vfill\par
    \fi
  }
  \setlength\parindent{0pt}
  \AtEndDocument{\outputempty}
}
\begin{document}
\begin{frame}[label=frame-a]{A Frame}%
  \includegraphics[height=.75\textheight,width=\textwidth,keepaspectratio]{example-image-a}
\end{frame}
\begin{annot}{frame-a}
  Not much to say about image A.
\end{annot}

\begin{frame}[label=frame-b]{B Frame}%
  \includegraphics[height=.75\textheight,width=\textwidth,keepaspectratio]{example-image-b}
\end{frame}
\begin{annot}{frame-b}
  Not much to say about image b.
\end{annot}

\begin{frame}[label=frame-c]{C Frame}%
  \includegraphics[height=.75\textheight,width=\textwidth,keepaspectratio]{example-image-c}
\end{frame}
\begin{annot}{frame-c}
  Not much to say about image C.
\end{annot}

\begin{frame}[label=frame-another]{Another Frame}%
  \includegraphics[height=.75\textheight,width=\textwidth,keepaspectratio]{example-image}
\end{frame}

\begin{frame}[label=frame-tiger]{Tiger Frame}%
  \includegraphics[height=.75\textheight,width=\textwidth,keepaspectratio]{tiger}
\end{frame}
\begin{annot}{frame-tiger}
  This frame shows a large, wild cat.
  Well, what it actually shows is a small picture of a wild cat, but you are meant to infer that it represents a larger reality.
\end{annot}

\begin{frame}[label=frame-cats]{Cats Frame}%
  \includegraphics[height=.75\textheight,width=\textwidth,keepaspectratio]{cathod}
\end{frame}
\begin{annot}{frame-cats}
  \kant[1-2]
\end{annot}

\begin{frame}[label=frame-which]{Which Frame?}%
 \includegraphics[height=.75\textheight,width=\textwidth,keepaspectratio]{cauldron}
\end{frame}
\begin{annot}{frame-which}
  This frame includes a pun, a cauldron and a question.
  More accurately, it includes a pun, a depiction of a cauldron and a question mark.
\end{annot}

\begin{frame}[label=frame-gadael]
  \includegraphics[width=\textwidth]{cath-gadael-chartref}
\end{frame}

\end{document}

관련 정보