Debian Codegraph @

texmf-dist/doc/latex/tikz-ext/tikz-ext-manual-en-library-beamer.tex

raw
1 % !TeX TS-program = lualatex
2 % !TeX spellcheck = en_US
3 % !TeX root = tikz-ext-manual.tex
4 % Copyright 2025 by Qrrbrbirlbel
5 %
6 % This file may be distributed and/or modified
7 %
8 % 1. under the LaTeX Project Public License and/or
9 % 2. under the GNU Free Documentation License.
10 %
11
12 \section{Beamer with \tikzname}
13 \label{tikzlibrary:beamer}
14 \begin{tikzlibrary}{ext.beamer}
15 This library can help create \tikzname\ diagrams in the \Beamer\ class.
16 \end{tikzlibrary}
17
18 %\begin{multicols*}{2}
19 \subsection{Helpers}
20 These helpers are always available, even if this library is loaded outside of \Beamer.
21 \begin{key}{/\tikzext/ignore line width}
22 If this key is used on a scope (or the \tikzname\ picture itself),
23 the line widths of paths will not contribute to the bounding box
24 of the diagram.
25 \end{key}
26 \begin{key}{/\tikzext/max bounding box=\meta{name}}
27 This key is to be used on multiple |tikzpicture| environments.
28 All \tikzname\ diagram with the same \meta{name} will have the same bounding box.
29 Refrain from using (unprotected) commas (|,|) in the \meta{name}.
30
31 This uses the \filetype{aux} file and
32 is therefore incompatible with the \referenceLibraryandIndexO{external} library.
33
34 However, it is made compatible with the
35 \referencePackageandIndexO{memoize} \cite{memoize} package,
36 even if it takes a few compilations until it is stable again
37 after a new diagram is added to the group.
38 \end{key}
39
40 \subsection{Beamer}
41 While \tikzname\ has some rudimentary support for the \Beamer\ class,
42 i.\,e. in the form of \texttt{\string\path<}\meta{overlay specification}\texttt{>},
43 this uses \Beamer's |\alt| command internally so that on overlays
44 that are not included in \meta{overlay specification}, the path will not be typeset
45 and will therefore not contribute to the diagram's bounding box.
46
47 This in turn will lead to the diagram \enquote{jumping around}
48 as every overlay will contain a different diagram with different dimensions.
49 The \referencePackageandIndexO{aobs-tikz} package solves this by setting the |opacity| to zero
50 for all those slides an element shouldn't be visisble on.
51
52 I believe we can do better.
53
54 Though, remember that for many simple diagrams,
55 you can simply use \referenceCommandandIndexO{\onslide}.
56 The following diagram will show
57 \begin{itemize}
58 \item nodes and edges transparent on overlay 1,
59 \item nodes fully visible and edges transparent on overlay 2 and
60 \item all elements fully visible on overlay 3.
61 \end{itemize}
62 \begin{codeexample}[preamble=\usetikzlibrary{ext.beamer} \setbeamercovered{transparent},code only]
63 \begin{tikzpicture}
64 \onslide<2->
65 \path node (a) {A}
66 node (b) at (1,2) {B};
67 \onslide<3->
68 \path (a) edge[bend right] (b);
69 \onslide
70 \end{tikzpicture}
71 \end{codeexample}
72 \subsubsection{Stop Jumping}
73 One solution to this is to have the same \tikzname\ diagram
74 have the same size on every overlay.
75 The |/tikz/ext/ignore line width| might help if all that changes between overlays
76 is the line width of elements.
77
78 Another one is the following key.
79 \begin{key}{/\tikzext/sync bounding box}
80 This key uses |ext/max bounding box| with a specific \meta{name}
81 that is stable across overlays.
82
83 If you find yourself often rearrange diagrams or changing overlays,
84 you might be better off using the |ext/sync bounding box| key
85 directly with a distinct \meta{name}.
86 \end{key}
87
88 \subsubsection{\Beamer Function and keys}
89 \begin{key}{/\tikzext/beamer function=\mchoice{original, alt, only, uncover, visible, invisible}}
90 This key changes how the \meta{overlay specification} in
91 \texttt{\string\path<}\meta{overlay specification}\texttt{>}
92 is applied internally.
93 The choices |original|, |alt| and |only| are all the same
94 and will result in the default behavior of \tikzname.
95
96 The same overlays as above can be created now with the following diagram.
97 \begin{codeexample}[preamble=\usetikzlibrary{ext.beamer} \setbeamercovered{transparent},code only]
98 \begin{tikzpicture}[ext/beamer function=uncover]
99 \path<2-> node (a) {A}
100 node (b) at (1,2) {B};
101 \path<3-> (a) edge[bend right] (b);
102 \end{tikzpicture}
103 \end{codeexample}
104 \end{key}
105
106 \begin{keylist}[/\tikzext]{%
107 uncover=\meta{overlay specification} (default all),
108 cover=\meta{overlay specification} (default all),
109 visible=\meta{overlay specification} (default all),
110 invisible=\meta{overlay specification} (default all)%
111 }
112 These keys work similar to \Beamer's own |\onslide| command
113 but only apply to the element it is used on.
114
115 The implementation of this is rather experimental and should be used carefully.
116 Multiple uses of these options \emph{don't} stack, only the last one wins --
117 this includes the use of the first syntax shortcuts introduced
118 in the next subsubsection.
119
120 The same overlays as above can be created with the first of the following diagram.
121 In the second diagram |ext/uncover| is only used on the (actual) empty path.
122 Just like |draw|/|\draw|, the nodes will not observe the request to be covered on overlay 1.
123 \begin{codeexample}[preamble=\usetikzlibrary{ext.beamer} \setbeamercovered{transparent},code only]
124 \begin{tikzpicture}
125 \path[nodes={ext/uncover=2-}]
126 node (a) {A}
127 node (b) at (1,2) {B}
128 (a) edge[bend right, ext/uncover=3-] (b);
129 \end{tikzpicture}
130 \begin{tikzpicture}
131 \draw[ext/uncover=2-]
132 node (a) {A}
133 node (b) at (1,2) {B};
134 \end{tikzpicture}
135 \end{codeexample}
136 \end{keylist}
137 \begin{keylist}[/\tikzext]{%
138 aobs visible=\meta{overlay specifcation} (default all),
139 aobs invisible=\meta{overlay specifcation} (default all)%
140 }
141 In case one wants to use the method of simply setting the opacity of elements to zero
142 to hide them, these keys are also available.
143 \end{keylist}
144 Of course, an extension to Beamer is not complete without the following keys.
145 \begin{key}{/\utilsext/only=\marg{overlay specification}\marg{key-value list}}
146 Applies the \meta{key-value list} only on \meta{overlay specification}.
147 \end{key}
148 \begin{key}{/\utilsext/alt=\marg{overlay specification}\marg{default kv list}\marg{alternative kv list}}
149 Applies the \meta{default kv list} on \meta{overlay specification},
150 otherwise the \meta{alternative kv list}.
151 \end{key}
152 \begin{key}{/\utilsext/temporal=\marg{overlay specification}%
153 \marg{before kv list}\marg{default kv list}\marg{after kv list}}
154 Applies the specific list depending whether the current overlay is before,
155 on or after the specified \meta{overlay specification}.
156 \end{key}
157 \subsubsection{\Beamer Shortcuts}
158 But, of course, no one wants to write |/utils/ext/only={2}{red}| to
159 make an element red on overlay 2.
160 \begin{key}{/\tikzext/beamer shortcuts=\marg{key-value list}}
161 This executes the \meta{key-value list} in the namespace |/tikz/ext/beamer shortcuts|.
162 \end{key}
163 \begin{key}{/\tikzext/beamer shortcuts/aot}
164 This forwards the keys \referenceKeyandIndex{alt}, \referenceKeyandIndex{only}
165 and \referenceKeyandIndex{temporal} to the aforementioned homonymous |/utils/ext| keys.
166 \end{key}
167 \begin{key}{/\tikzext/beamer shortcuts/first char=%
168 \mchoice{uncover, cover, visible, invisible, aobs visible, aobs invisible} (initially uncover)}
169 The value of this key will be used for the first char shorthands that can be enabled with the following keys.
170 \begin{key}{/\tikzext/beamer shortcuts/enable first char <}
171 This install a \enquote{first char} handler with the character |<|.
172
173 This allows the example diagram to specified in the following way.
174 \begin{codeexample}[preamble=\usetikzlibrary{ext.beamer} \setbeamercovered{transparent},code only]
175 \begin{tikzpicture}[ext/beamer shortcuts={enable first char <}]
176 \node (a) [<2->] {A};
177 \node (b) [<2->] at (1,2) {B};
178 \path (a) edge[<3->, bend right] (b);
179 \end{tikzpicture}
180 \end{codeexample}
181
182 Internally, this will be converted to |ext/uncover=|\marg{overlay specification}.
183
184 Actually, the full syntax is much more versatile
185 \begin{quote}
186 |<|\meta{overlay specification}|>|\opt{|'|}\opt{\meta{options}}\\
187 |<|\meta{overlay specification}|>|\opt{|'|}\opt{\marg{options A}}\opt{\marg{options B}}\opt{\marg{options C}}
188 \end{quote}
189
190 If no options are present the \meta{overlay specification} will
191 be forwarded to one of the keys explained in the subsection above
192 -- depending on |ext/beamer shortcuts/first char|.
193 The optional |'| after |>| will invert the \meta{overlay specification}.
194
195 If \meta{options} or \marg{options A} are present,
196 these will only applied on \meta{overlay specifications} (or the inverse of them with the |'|).
197 If two sets of options are present, they will be |\alt|ed, three options will be |\temporal|ed.
198
199 The |'| will swap two sets of options while for three the first and the last will be swapped.
200 \end{key}
201 \begin{key}{/\tikzext/beamer shortcuts/enable first char=\marg{character}}
202 As the |<| character might lead to problems as it conflicts with the \tikzname\ shorthand
203 of specifying arrow tip sequences
204 (i.\,e. the famous |<->|\footnote{Though, remember, you can always write \texttt{arrows = <->}.})
205 and the \referenceLibraryandIndexO{graphs} library's own first char syntax
206 an alternative is presented here.
207
208 This key enables a first char syntax with \meta{character} where the full syntax is the same as above:
209 \begin{quote}
210 \meta{character}|<|\meta{overlay specification}|>|\opt{|'|}\opt{\meta{options}}\\
211 \meta{character}|<|\meta{overlay specification}|>|\opt{|'|}\opt{\marg{options A}}\opt{\marg{options B}}\opt{\marg{options C}}
212 \end{quote}
213
214 This means, the example diagram can be created in the following way.
215 \begin{codeexample}[preamble=\usetikzlibrary{ext.beamer} \setbeamercovered{transparent},code only]
216 \begin{tikzpicture}[ext/beamer shortcuts={enable first char=?}]
217 \node (a) [?<2->] {A};
218 \node (b) [?<2->] at (1,2) {B};
219 \path (a) edge[?<3->, bend right] (b);
220 \end{tikzpicture}
221 \end{codeexample}
222 \end{key}
223 \begin{key}{/{tikz/graphs/ext}/better beamer shortcut}
224 This sets up a few things that enables the |<| first char syntax in the appropriate places.
225 For nodes, it tries to be smart and checks for the presence of a |>| to decide whether the \Beamer\ shortcut
226 or the the |graphs| library's own shortcut should be used.
227 \end{key}
228 \end{key}
229
230 \subsubsection{Key Handler}
231 Maybe this is a syntax that someone wants \dots
232 \begin{ext_handler}{{<}|=|\meta{overlay specification}|>| \opt{value}}
233 This handler applies the key on \meta{overlay specification}.
234 If \meta{value} is missing, then the key is also used without a value.
235 For an empty value, use |{}|. If the \meta{value} contains comas or equal signs,
236 as always, you will need to protect those with |{}|.
237 \begin{key}{/\tikzext/beamer shortcuts/enable handler}
238 If |ext_| is too much, using this key activates the |.<| handler.
239 \begin{handler}{{.<}|=|\meta{overlay specification}|>| \opt{value}}
240 This handler is then an alias for the |.ext_<| handler.
241 \end{handler}
242 \end{key}
243 \end{ext_handler}
244 %\end{multicols*}
245 \endinput