summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/overlays/overlays.sty
blob: 8cf8df8a89305dc20b6fd9ea50b72038015f67aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
\ProvidesPackage{overlays}[2016/09/30 v2.0 Incremental slides]

% Copyright (C) 2016 Andreas Nolda

% Author: Andreas Nolda <andreas@nolda.org>
% Version: 2.0

% This work may be distributed and/or modified under the conditions of the LaTeX
% Project Public License, either version 1.3 of this license or (at your option)
% any later version. The latest version of this license is in
% http://www.latex-project.org/lppl.txt and version 1.3 or later is part of all
% distributions of LaTeX version 2005/12/01 or later.

% The following code is inspired by Matthias Meister's "present" package. It
% uses an algorithm by Martin Scharrer for testing numbers in numerical ranges
% (http://tex.stackexchange.com/q/19000/). The code for processing overlays with
% verbatim content is taken from the "texpower" package, which in turn took it
% from Till Tantau's "beamer" package.

\RequirePackage{color}
\RequirePackage{environ}
\RequirePackage{pgffor}

\definecolor{background}{rgb}{1,1,1}
\definecolor{alert}{rgb}{1,0,0}

\newcount\curoverl@y
\newcount\maxoverl@y
\newcount\overl@yspeca
\newcount\overl@yspecb
\newcount\saveequ@tion

\def\@getoverl@yspecb-#1\relax%
  {\ifx\relax#1\relax
     \overl@yspecb=\maxoverl@y
   \else
     \overl@yspecb=#1\relax
   \fi}

\def\getoverl@yspecb%
  {\@ifnextchar\relax
     {\overl@yspecb=\overl@yspeca}%
     {\@getoverl@yspecb}}

\def\ifinoverl@yspec#1#2%
  {\global\let\inoverl@yspec\@secondoftwo
   \foreach \i in {#2}
     {\afterassignment\getoverl@yspecb
      \overl@yspeca=0\i\relax
      \pgfmathtruncatemacro\result{(#1>=\overl@yspeca) && (#1<=\overl@yspecb)}%
      \ifnum\result=1\relax
        \breakforeach
        \global\let\inoverl@yspec\@firstoftwo
      \fi}%
   \inoverl@yspec}

\long\def\overl@y#1#2#3{\ifinoverl@yspec{\curoverl@y}{#1}{#2}{#3}}

\NewEnviron{overlays}[1]%
  {\maxoverl@y=#1%
   \curoverl@y=0%
   \saveequ@tion=\value{equation}%
   \loop
     \advance\curoverl@y by 1%
     \begingroup
     \BODY
     \endgroup
     \ifnum\curoverl@y<\maxoverl@y%
       \vfill
       \clearpage
       \addtocounter{page}{-1}%
       \setcounter{equation}{\saveequ@tion}%
   \repeat}

\newwrite\verb@timfileout

\def\verb@timreadslide
  {\begingroup%
   \let\do\@makeother\dospecials%
   \count@=127%
   \@whilenum\count@<255 \do
     {\advance\count@ by 1%
      \catcode\count@=11}
   \@makeother\^^L
   \endlinechar`\^^M \catcode`\^^M=12 \processslidefirstline}

{\catcode`\^^M=12\endlinechar=-1%
 \long\gdef\processslidefirstline#1^^M%
   {\def\overl@ystest{#1}%
    \ifx\overl@ystest\stopslidefirst%
      \let\next=\endfr@gileoverl@ys%
    \else
      \ifx\overl@ystest\@empty%
      \else%
        \@temptokena={#1}%
        \immediate\write\verb@timfileout{\the\@temptokena}%
      \fi%
      \let\next=\processslideline%
    \fi%
    \next}
 \long\gdef\processslideline#1^^M%
   {\def\overl@ystest{#1}%
    \ifx\overl@ystest\stopslide%
      \let\next=\endfr@gileoverl@ys%
    \else
      \immediate\write\verb@timfileout{#1}%
    \fi%
    \next}}

{\escapechar=-1\relax%
 \xdef\stopslide{\string\\end\string\{fragileoverlays\string\}}
 \xdef\stopslidefirst{\noexpand\end\string\{fragileoverlays\string\}}}

\newenvironment{fragileoverlays}[1]
  {\maxoverl@y=#1%
   \def\verb@timfilen@me{\jobname.vrb}%
   \immediate\openout\verb@timfileout=\verb@timfilen@me%
   \verb@timreadslide}
  {\immediate\closeout\verb@timfileout%
   \begin{overlays}{\maxoverl@y}
   \def\verbatim@nolig@list{\do\`\do\<\do\>\do\'} % do not make "," and "-" active
   \input{\verb@timfilen@me}%
   \end{overlays}}

\def\endfr@gileoverl@ys{\endgroup\end{fragileoverlays}}

\newcommand{\only}[2]{\overl@y{#1}{#2}{\relax}}

\newcommand{\visible}[2]{\overl@y{#1}{#2}{{\color{background}#2\ifvmode\unskip\fi}}}

\newcommand{\alert}[2]{\overl@y{#1}{{\color{alert}#2\ifvmode\unskip\fi}}{#2}}