Debian Codegraph @

texmf-dist/source/latex/beamer-varbox/beamer-varbox.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2026 Fabian Fuchs
4 %
5 % This file may be distributed and/or modified
6 %
7 % 1. under the LaTeX Project Public License and/or
8 % 2. under the GNU Public License.
9 %
10 % The latest version of the LaTeX Project Public
11 % License can be found under:
12 %
13 % http://www.latex-project.org/lppl.txt
14 %
15 %
16 % \fi
17 %
18 % \iffalse
19 %<package>\NeedsTeXFormat{LaTeX2e}[2023-11-01]
20 %<package>\ProvidesPackage{beamer-varbox}[2026-05-12 A package providing variable size corners for beamer boxes.]
21 %
22 %<*driver>
23 \documentclass{ltxdoc}
24 \usepackage{beamer-varbox}
25 \usepackage{graphicx}
26 \EnableCrossrefs
27 \CodelineIndex
28 \RecordChanges
29 \begin{document}
30 \DocInput{beamer-varbox.dtx}
31 \end{document}
32 %</driver>
33 % \fi
34 %
35 % \changes{2025-09-11}{2025-09-11}{Initial version}
36 % \changes{2026-05-12}{2026-05-12}{Documentation Improvements}
37 %
38 % \GetFileInfo{beamer-varbox.sty}
39 %
40 % \DoNotIndex{⟨list of control sequences⟩}
41 % \NewDocElement{Opt}{option}
42 %
43 % \title{The \textsf{beamer-varbox} package\thanks{This document
44 % corresponds to \textsf{beamer-varbox}~\fileversion,
45 % dated \filedate.}}
46 % \author{Fabian Fuchs \\ \texttt{[email protected]}}
47 %
48 % \maketitle
49 %
50 % \begin{abstract}
51 % A package providing variable size corners for beamer boxes.
52 % \end{abstract}
53 %
54 % \section{Usage}
55 % Loading the package provides the \texttt{variable rounded} predefined option for
56 % the beamer elements \texttt{block begin}, \texttt{block alerted begin},
57 % \texttt{block example begin}, \texttt{block end}, \texttt{block alerted end}, and
58 % \texttt{block example end} and sets them as the default for these element.
59 %
60 % \section{Options}
61 %
62 % \DescribeOpt{cornerpercent}
63 % The package has one option, |cornerpercent|, that describes the scale of corner arc
64 % relative to the standard rounded predefined option provided by the beamer class.
65 % It is a keyword option that takes values between 0 and 1 (inclusive), where 0 indicates sharp corners
66 % and 1 the standard corners of the beamer package. It can be called either
67 % when including the package as
68 %
69 % |\usepackage| [cornerpercent=⟨\textit{value}⟩] \{beamer-varbox\}
70 %
71 % \noindent or when setting the template manually as, e.g.,
72 %
73 % |\setbeamertemplate| \marg{element name} [variable rounded] [cornerpercent=⟨\textit{value}⟩]
74 %
75 % \noindent The default value is \texttt{0.3}.
76 %
77 % \section{Examples of Use}
78 % Some examples of the effects of the |cornerpercent| option are the following. Note that 1 is equivalent
79 % to the standard beamer boxes, 0.3 is the default setting for this package, and 0 does not have any rounding at the corners.\\
80 % \includegraphics[width=0.49\textwidth]{default_beamer.png}
81 % \includegraphics[width=0.49\textwidth]{point_six_option.png}\\
82 % \includegraphics[width=0.49\textwidth]{default_option.png}
83 % \includegraphics[width=0.49\textwidth]{no_rounding.png}
84 %
85 % \MaybeStop{\PrintIndex}
86 %
87 % \section{Implementation}
88
89 % \begin{macrocode}
90 % Check that beamer class is loaded
91 %
92 \@ifclassloaded{beamer}{}{%
93 \PackageError{beamer-varbox}{%
94 This package needs the beamer class.\MessageBreak
95 To use this package, load the beamer class.
96 }{%
97 The package could not be loaded, because it needs\MessageBreak
98 beamer class to function.
99 }%
100 \endinput
101 }
102
103
104 % Require xkeyval to do modern package keyval handling
105 \RequirePackage{xkeyval}
106
107 \DeclareOptionX{cornerpercent}[0.3]{\def\beamer@cornerpercentdefault{#1}}
108 \ExecuteOptionsX{cornerpercent=0.3}
109 \ProcessOptionsX\relax
110
111 % Define 0 to compare against
112 \def\bmb@zero{0}
113
114 %
115 % Define used keys
116 %
117 \define@key{beamerboxes}{scheme}{\def\bmb@upper{@scheme upper #1}%
118 \def\bmb@lower{@scheme lower #1}}
119 \define@key{beamerboxes}{upper}{\def\bmb@upper{#1}}
120 \define@key{beamerboxes}{lower}{\def\bmb@lower{#1}}
121 \define@key{beamerboxes}{width}{\edef\bmb@width{#1}}
122 \define@key{beamerboxes}{shadow}[true]{\csname bmb@shadow#1\endcsname}
123 \define@key{beamerboxes}{cornerpercent}{\def\bmb@cornerpercent{#1}}
124
125 % Define neeeded variables
126 \newif\ifbmb@shadow
127 \newbox\bmb@box
128 \newbox\bmb@colorbox
129 \newdimen\bmb@boxwidth
130 \newdimen\bmbboxheight
131 \newdimen\bmb@prevheight
132 \newdimen\bmb@temp
133 \newdimen\bmb@dima
134 \newdimen\bmb@dimb
135 \newdimen\bmb@dimc
136 \newdimen\bmb@prevheight
137 \newdimen\bmb@supportcorner
138 \newdimen\bmb@initstart
139 \newdimen\bmb@advance
140
141 %
142 % The below is adapted from the beamer package
143 % files beamerbaseboxes.sty and beamerbaseauxtemplates.sty.
144 % Authors of those files are:
145 % Till Tantau, Vedran Mileti\'c, Joseph Wright,
146 % Louis Stuart, and samcarter.
147 % Thanks for the work!!
148 %
149 \newcommand\beamerboxesvariablerounded[2][]{%
150 \global\let\beamer@firstlineitemizeunskip=\relax%
151 \vbox\bgroup%
152 \setkeys{beamerboxes}{upper=block title,lower=block body,%
153 width=\textwidth,shadow=false,%
154 cornerpercent=\beamer@cornerpercentdefault}%
155 \setkeys{beamerboxes}{#1}%
156 {%
157 \usebeamercolor{\bmb@lower}%
158 \globalcolorstrue%
159 \colorlet{lower.bg}{bg}%
160 }%
161 {%
162 \usebeamercolor{\bmb@upper}%
163 \globalcolorstrue%
164 \colorlet{upper.bg}{bg}%
165 }%
166
167 %
168 % Typeset head
169 %
170 \vskip4bp
171 \setbox\bmb@box=\hbox{%
172 \begin{minipage}[b]{\bmb@width}%
173 \usebeamercolor[fg]{\bmb@upper}%
174 #2%
175 \end{minipage}}%
176 \ifdim\wd\bmb@box=0pt%
177 \setbox\bmb@box=\hbox{}%
178 \ht\bmb@box=1.5pt%
179 \bmb@prevheight=-4.5pt%
180 \else%
181 \wd\bmb@box=\bmb@width%
182 \bmb@temp=\dp\bmb@box%
183 \ifdim\bmb@temp<1.5pt%
184 \bmb@temp=1.5pt%
185 \fi%
186 \setbox\bmb@box=\hbox{\raise\bmb@temp\hbox{\box\bmb@box}}%
187 \dp\bmb@box=0pt%
188 \bmb@prevheight=\ht\bmb@box%
189 \fi%
190 %
191 %
192 %
193 \ifdim\bmb@cornerpercent pt >1pt
194 \PackageError{beamer-varbox}{%
195 The key cornerpercent is above 1.\MessageBreak
196 The key is allowed to take values in between 0 and 1 (inclusive)%
197 }{%
198 cornerpercent is allowed to be between 0 and 1 (inclusive)%
199 }%
200 \fi
201 %
202 % Check if the corners should be sharp
203 %
204 \if\bmb@cornerpercent\bmb@zero
205 \bmb@temp=\bmb@width%
206 \bmb@dima=\bmb@temp\advance\bmb@dima by8bp%
207 \bmb@dimc=-\ht\bmb@box\advance\bmb@dimc by-2pt%
208 \hbox{%
209 \begin{pgfpicture}{0bp}{+-\ht\bmb@box}{0bp}{+-\ht\bmb@box}
210 \ifdim\wd\bmb@box=0pt%
211 \color{lower.bg}%
212 \pgfsetfillopacity{0}
213 \else%
214 \color{upper.bg}%
215 \fi%
216 \pgfpathqmoveto{-4bp}{\bmb@dimc}%
217 \pgfpathqlineto{-4bp}{3bp}%
218 \pgfpathqlineto{\bmb@dima}{3bp}%
219 \pgfpathqlineto{\bmb@dima}{\bmb@dimc}%
220 \pgfsetlinewidth{1.5pt}
221 \pgfusepath{fill,stroke}
222 \end{pgfpicture}%
223 \copy\bmb@box%
224 }%
225 \else
226 %
227 % Calculate dimensions for adjusted corner
228 %
229 \bmb@supportcorner=\dimexpr\bmb@cornerpercent\dimexpr1.8bp\relax\relax%
230 \bmb@initstart=\dimexpr 4bp-\bmb@cornerpercent\dimexpr4bp\relax\relax%
231 \bmb@advance=\dimexpr \bmb@initstart+\bmb@cornerpercent\dimexpr2.2bp\relax\relax%
232 % Calculate aux sizes
233 \bmb@temp=\bmb@width%
234 \bmb@dima=\bmb@temp\advance\bmb@dima by\bmb@advance%
235 \bmb@dimb=\bmb@temp\advance\bmb@dimb by4bp%
236 \bmb@dimc=-\ht\bmb@box\advance\bmb@dimc by-2pt%
237 \hbox{%
238 \begin{pgfpicture}{0bp}{+-\ht\bmb@box}{0bp}{+-\ht\bmb@box}
239 \ifdim\wd\bmb@box=0pt%
240 \color{lower.bg}%
241 \pgfsetfillopacity{0}
242 \else%
243 \color{upper.bg}%
244 \fi%
245 \pgfpathqmoveto{-4bp}{\bmb@dimc}
246 \pgfpathlineto{\pgfpoint{-4bp}{-1bp+\bmb@initstart}}
247 \pgfpathcurveto% Upper left corner
248 {\pgfpoint{-4bp}{3bp-\bmb@supportcorner}}%
249 {\pgfpoint{-4bp+\bmb@supportcorner}{3bp}}%
250 {\pgfpoint{-\bmb@initstart}{3bp}}%
251 \pgfpathlineto{\pgfpoint{\bmb@temp+\bmb@initstart}{3bp}}
252 \pgfpathcurveto% Upper right corner
253 {\pgfpoint{\bmb@dima}{3bp}}%
254 {\pgfpoint{\bmb@dimb}{3bp-\bmb@supportcorner}}%
255 {\pgfpoint{\bmb@dimb}{-1bp+\bmb@initstart}}%
256 \pgfpathqlineto{\bmb@dimb}{-1bp}%
257 \pgfpathlineto{\pgfpoint{\bmb@dimb}{\bmb@dimc}}
258 \pgfsetlinewidth{1.5pt}
259 \pgfusepath{fill,stroke}
260 \end{pgfpicture}%
261 \copy\bmb@box%
262 }%
263 \fi % of sharp corner check
264 \nointerlineskip%
265 \vskip-1pt%
266 \ifdim\wd\bmb@box=0pt%
267 \else%
268 \vskip3pt%
269 \fi%
270 \setbox\bmb@colorbox=\hbox{{\pgfpicturetrue\pgfsetcolor{lower.bg}}}%
271 \setbox\bmb@box=\hbox\bgroup\begin{minipage}[b]{\bmb@width}%
272 \vskip2pt%
273 \usebeamercolor[fg]{\bmb@lower}%
274 \colorlet{beamerstructure}{upper.bg}%
275 \colorlet{structure}{upper.bg}%
276 }
277
278
279
280 \def\endbeamerboxesvariablerounded{%
281 \end{minipage}\egroup%
282 \bmb@temp=\dp\bmb@box%
283 \advance\bmb@temp by.5pt%
284 \setbox\bmb@box=\hbox{\raise\bmb@temp\hbox{\box\bmb@box}}%
285 \dp\bmb@box=0pt%
286 \bmb@boxwidth=\bmb@width%
287 \bmb@boxheight=\ht\bmb@box%
288 \advance\bmb@boxheight by4bp%
289 \advance\bmb@boxheight by\bmb@prevheight%
290 \ifbmb@shadow%
291 \xdef\beamer@storecolorhook{\beamer@colorhook}
292 \xdef\beamer@colorhook{}
293 \pgfdeclareradialshading{bmb@shadowball}{\pgfpointorigin}
294 {%
295 color(0bp)=(pgftransparent!50);
296 color(4bp)=(pgftransparent!100)
297 }%
298 \pgfdeclareradialshading{bmb@shadowballlarge}{\pgfpointorigin}
299 {%
300 color(0bp)=(pgftransparent!0);
301 color(8bp)=(pgftransparent!100)
302 }%
303 \pgfdeclarehorizontalshading{bmb@shadowhorz\the\bmb@boxheight}{\[email protected]}
304 {%
305 color(0bp)=(pgftransparent!0);
306 color(8bp)=(pgftransparent!100)
307 }%
308 \pgfdeclareverticalshading{bmb@shadowvert\the\bmb@boxwidth}{\bmb@boxwidth-4bp}
309 {%
310 color(0bp)=(pgftransparent!100);
311 color(8bp)=(pgftransparent!0)
312 }%
313 \begingroup%
314 \selectcolormodel{gray}
315 \pgfdeclarefading{bmb@shadowmask\the\bmb@boxwidth\the\bmb@boxheight}
316 {%
317 \begin{pgfpicture}
318 \pgftext[at=\pgfpoint{4bp}{4bp}]{\pgfuseshading{bmb@shadowball}}%
319 % bottom left shadow
320 \ifdim\bmb@boxheight>9.5bp%
321 \pgftext[at=\pgfpoint{\bmb@boxwidth}{8bp}]%
322 {\pgfuseshading{bmb@shadowballlarge}}% bottom right shadow
323 \pgftext[at=\pgfpoint{\bmb@boxwidth+4bp}{\bmb@boxheight+2bp}]%
324 {\pgfuseshading{bmb@shadowball}}% top right shadow
325 \pgftext[base, at=\pgfpoint{\bmb@boxwidth+4bp}{7.5bp}]%
326 {\pgfuseshading{bmb@shadowhorz\the\bmb@boxheight}}% right edge shadow
327 \else%
328 \pgftext[at=\pgfpoint{\bmb@boxwidth}{4bp}]%
329 {\pgfuseshading{bmb@shadowball}}% right shadow
330 \fi%
331 \pgftext[left, at=\pgfpoint{4bp}{4bp}]%
332 {\pgfuseshading{bmb@shadowvert\the\bmb@boxwidth}}% bottom edge
333 %
334 % clipping is needed because shadow is typeset on top of box
335 \begin{pgfscope}
336 \pgfsetcolor{beamer@safeblack}
337 \pgfpathrectangle{\pgfpoint{4bp}{8.1bp}}%
338 {\pgfpoint{\bmb@boxwidth}{\bmb@boxheight-2bp}}
339 \pgfusepath{fill}
340 \end{pgfscope}
341 \end{pgfpicture}%
342 \hskip4bp%
343 }%
344 \endgroup%
345
346 \fi%
347 %
348 % Check if the corners should be sharp
349 %
350 \if\bmb@cornerpercent\bmb@zero
351 \bmb@temp=\bmb@width%
352 \bmb@dima=\bmb@temp\advance\bmb@dima by8bp%
353 \bmb@dimc=\ht\bmb@box
354 \hbox{%
355 \begin{pgfpicture}{0bp}{0bp}{0bp}{0bp}
356 \ifbmb@shadow%
357 \begin{pgfscope}
358 \pgfpathrectangle{\pgfpoint{0bp}{-7bp}}
359 {\pgfpoint{\bmb@boxwidth+8bp}{\bmb@boxheight+6bp}}
360 \pgfsetfading{bmb@shadowmask\the\bmb@boxwidth\the\bmb@boxheight}{%
361 \pgftransformshift{\pgfpoint{0.5\bmb@boxwidth+6bp}{0.5\bmb@boxheight-4bp}}}
362 \pgfusepath{fill}
363 \end{pgfscope}
364 \fi%
365 \unhbox\bmb@colorbox%
366 \pgfpathqmoveto{-4bp}{\bmb@dimc}%
367 \pgfpathqlineto{-4bp}{-3bp}%
368 \pgfpathqlineto{\bmb@dima}{-3bp}%
369 \pgfpathqlineto{\bmb@dima}{\bmb@dimc}%
370 \pgfsetlinewidth{1.5pt}
371 \pgfusepath{stroke}
372 \end{pgfpicture}%
373 \box\bmb@box%
374 }%
375 \else
376 \bmb@temp=\bmb@width%
377 \bmb@dima=\bmb@temp\advance\bmb@dima by\bmb@advance%
378 \bmb@dimb=\bmb@temp\advance\bmb@dimb by4bp%
379 \hbox{%
380 \begin{pgfpicture}{0bp}{0bp}{0bp}{0bp}
381 \ifbmb@shadow%
382 \begin{pgfscope}
383 \pgfpathrectangle{\pgfpoint{0bp}{-7bp}}
384 {\pgfpoint{\bmb@boxwidth+8bp}{\bmb@boxheight+6bp}}
385 \pgfsetfading{bmb@shadowmask\the\bmb@boxwidth\the\bmb@boxheight}{%
386 \pgftransformshift{\pgfpoint{0.5\bmb@boxwidth+6bp}{0.5\bmb@boxheight-4bp}}}
387 \pgfusepath{fill}
388 \end{pgfscope}
389 \fi%
390 \unhbox\bmb@colorbox%
391 \bmb@dimc=\ht\bmb@box
392 \pgfpathqmoveto{-4bp}{\bmb@dimc}
393 \pgfpathlineto{\pgfpoint{-4bp}{1bp-\bmb@initstart}}
394 \pgfpathcurveto% Lower left corner
395 {\pgfpoint{-4bp}{-3bp+\bmb@supportcorner}}%
396 {\pgfpoint{-4bp+\bmb@supportcorner}{-3bp}}%
397 {\pgfpoint{-\bmb@initstart}{-3bp}}%
398 \pgfpathlineto{\pgfpoint{\bmb@temp+\bmb@initstart}{-3bp}}
399 \pgfpathcurveto% Lower right corner
400 {\pgfpoint{\bmb@dima}{-3bp}}%
401 {\pgfpoint{\bmb@dimb}{-3bp+\bmb@supportcorner}}%
402 {\pgfpoint{\bmb@dimb}{1bp-\bmb@initstart}}%
403 \pgfpathqlineto{\bmb@dimb}{-1bp}%
404 \pgfpathlineto{\pgfpoint{\bmb@dimb}{\bmb@dimc}}
405 \pgfsetlinewidth{1.5pt}
406 \pgfusepath{stroke}
407 \end{pgfpicture}%
408 \box\bmb@box%
409 }%
410 \fi% of corner check
411 \ifbmb@shadow%
412 \vskip4bp minus 2bp%
413 \else%
414 \vskip2bp%
415 \fi%
416 \egroup% of \vbox\bgroup
417 \ifbmb@shadow%
418 \xdef\beamer@colorhook{\beamer@storecolorhook}
419 \fi
420 }
421
422
423 \defbeamertemplate*{block begin}{variable rounded}[1][shadow=false]%
424 {%
425 \par\vskip\medskipamount%
426 \begin{beamerboxesvariablerounded}[upper=block title,lower=block body,#1]%
427 {\raggedright\usebeamerfont*{block title}\insertblocktitle}%
428 \raggedright%
429 \usebeamerfont{block body}%
430 }%
431
432 \defbeamertemplate*{block end}{variable rounded}%
433 {%
434 \end{beamerboxesvariablerounded}\vskip\smallskipamount
435 }%
436
437 \defbeamertemplate*{block alerted begin}{variable rounded}[1][shadow=false]
438 {%
439 \par\vskip\medskipamount%
440 \begin{beamerboxesvariablerounded}[upper=block title alerted,lower=block body alerted,#1]%
441 {\raggedright\usebeamerfont*{block title alerted}\insertblocktitle}%
442 \raggedright%
443 \usebeamerfont{block body alerted}%
444 }%
445 \defbeamertemplate*{block alerted end}{variable rounded}[1][]
446 {
447 \end{beamerboxesvariablerounded}\vskip\smallskipamount
448 }
449
450 \defbeamertemplate*{block example begin}{variable rounded}[1][shadow=false]
451 {%
452 \par\vskip\medskipamount%
453 \begin{beamerboxesvariablerounded}[upper=block title example,lower=block body example,#1]
454 {\raggedright\usebeamerfont*{block title example}\insertblocktitle}%
455 \raggedright%
456 \usebeamerfont{block body example}%
457 }%
458 \defbeamertemplate*{block example end}{variable rounded}[1][]
459 {\end{beamerboxesvariablerounded}\vskip\smallskipamount}
460 % \end{macrocode}
461 %
462 % \Finale
463 \endinput