Debian Codegraph @

texmf-dist/source/latex/ltx-talk/ltx-talk-color.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: ltx-talk-color.dtx Copyright (C) 2025,2026 Joseph Wright
4 %
5 % It may be distributed and/or modified under the conditions of the
6 % LaTeX Project Public License (LPPL), either version 1.3c of this
7 % license or (at your option) any later version. The latest version
8 % of this license is in the file
9 %
10 % https://www.latex-project.org/lppl.txt
11 %
12 % This file is part of the "ltx-talk bundle" (The Work in LPPL)
13 % and all files in that bundle must be distributed together.
14 %
15 % The released version of this bundle is available from CTAN.
16 %
17 % -----------------------------------------------------------------------
18 %
19 % The development version of the bundle can be found at
20 %
21 % https://github.com/josephwright/ltx-talk
22 %
23 % for those people who are interested.
24 %
25 % -----------------------------------------------------------------------
26 %
27 %<*driver>
28 \documentclass{l3doc}
29 % Additional commands needed in this source
30 \NewDocumentCommand\email{m}{\href{mailto:#1}{\nolinkurl{#1}}}
31 \begin{document}
32 \DocInput{\jobname.dtx}
33 \end{document}
34 %</driver>
35 % \fi
36 %
37 % ^^A As we are dealing with a class, this has to be done manually
38 % \def\filedate{2026-04-30}
39 % \def\fileversion{v0.5.0}
40 %
41 % \title{^^A
42 % \pkg{ltx-talk-color} -- Color definitions^^A
43 % \thanks{This file describes \fileversion,
44 % last revised \filedate.}^^A
45 % }
46 %
47 % \author{^^A
48 % Joseph Wright^^A
49 % \thanks{^^A
50 % E-mail: \email{[email protected]}^^A
51 % }^^A
52 % }
53 %
54 % \date{Released \filedate}
55 %
56 % \maketitle
57 %
58 % \begin{documentation}
59 %
60 % \end{documentation}
61 %
62 % \begin{implementation}
63 %
64 % \section{\pkg{ltx-talk-color} implementation}
65 %
66 % Start the \pkg{DocStrip} guards.
67 % \begin{macrocode}
68 %<*class>
69 % \end{macrocode}
70 %
71 % Identify the internal prefix.
72 % \begin{macrocode}
73 %<@@=talk>
74 % \end{macrocode}
75 %
76 % The aim here is to \emph{test} how well \pkg{l3color} can support the range
77 % of color functions that are needed for a presentation. As such, this is
78 % very much experimental, but deliberately so. In particular, there is an
79 % important question about the need for global colors: used throughout
80 % \cls{beamer} but otherwise not widely encountered. At the same time, there is
81 % a need to work with packages that expect color to be managed in a
82 % predictable way: \pkg{pgf} in particular makes use of \pkg{xcolor} internal
83 % as part of color management.
84 %
85 % Currently, colors defined using \pkg{xcolor} will be passed on to
86 % \pkg{l3color} provided \cs{DocumentMetadata} is active. As that is a
87 % requirement in any case for \cls{ltx-talk}, some of the setup is relatively
88 % easy to do.
89 %
90 % \subsection{Existing definitions}
91 %
92 % \begin{macrocode}
93 \RequirePackage { xcolor }
94 % \end{macrocode}
95 %
96 % \begin{macro}{\stdcolor, \stdmathcolor, \stdtextcolor}
97 % Save the document commands.
98 % \begin{macrocode}
99 \NewCommandCopy \stdcolor \color
100 \NewCommandCopy \stdmathcolor \mathcolor
101 \NewCommandCopy \stdtextcolor \textcolor
102 % \end{macrocode}
103 % \end{macro}
104 %
105 % \subsection{Document (and interface) commands}
106 %
107 % \begin{macrocode}
108 \cs_generate_variant:Nn \color_select:n { e }
109 \cs_generate_variant:Nn \color_select:nn { ne }
110 \cs_generate_variant:Nn \color_math:nn { e }
111 \cs_generate_variant:Nn \color_math:nnn { ne }
112 % \end{macrocode}
113 %
114 % \begin{macro}{\color, \mathcolor, \textcolor}
115 % Add the overlay specification and use \pkg{l3color}.
116 % \begin{macrocode}
117 \RenewDocumentCommand \color { D <> { all } o m }
118 {
119 \@@_if_overlay:nT {#1}
120 {
121 \IfNoValueTF {#2}
122 { \color_select:e {#3} }
123 { \color_select:ne {#2} {#3} }
124 }
125 \ignorespaces
126 }
127 \RenewDocumentCommand \mathcolor { D <> { all } o m +m }
128 {
129 \@@_if_overlay:nT {#1}
130 {
131 \IfNoValueTF {#2}
132 { \color_math:en {#3} {#4} }
133 { \color_math:nen {#2} {#3} {#4} }
134 }
135 }
136 \RenewDocumentCommand \textcolor { D <> { all } o m +m }
137 {
138 \mode_leave_vertical:
139 \group_begin:
140 \@@_if_overlay:nT {#1}
141 {
142 \IfNoValueTF {#2}
143 { \color_select:e {#3} }
144 { \color_select:ne {#2} {#3} }
145 }
146 #4
147 \group_end:
148 }
149 % \end{macrocode}
150 % \end{macro}
151 %
152 % \begin{macro}{\pagecolor}
153 % \begin{macro}{\@@_pagecolor:n}
154 % Here, the definition is different: we directly use the shipout hook.
155 % \begin{macrocode}
156 \RenewDocumentCommand \pagecolor { D <> { all } o m }
157 {
158 \@@_if_overlay:nT {#1}
159 {
160 \IfNoValueTF {#2}
161 { \@@_pagecolor:n { {#3} } }
162 { \@@_pagecolor:n { [ {#2} ] {#3} } }
163 }
164 }
165 \cs_new_protected:Npn \@@_pagecolor:n #1
166 {
167 \AddToHook { shipout / background }
168 {
169 \color #1
170 \put ( 0cm, -\paperheight )
171 { \rule { \paperwidth } { \paperheight } }
172 }
173 }
174 % \end{macrocode}
175 % \end{macro}
176 % \end{macro}
177 %
178 % \begin{macro}{\stdset@color, \stdreset@color}
179 % \begin{macrocode}
180 \cs_set_eq:NN \stdset@color \set@color
181 \cs_set_eq:NN \stdreset@color \reset@color
182 % \end{macrocode}
183 % \end{macro}
184 %
185 % \begin{macro}{\set@color, \reset@color}
186 % Part of code-level interface for color: simply use the \pkg{expl3} version
187 % of the same idea.
188 % \begin{macrocode}
189 \cs_set_eq:NN \set@color \color_ensure_current:
190 \cs_set_eq:NN \reset@color \__color_backend_reset:
191 % \end{macrocode}
192 % \end{macro}
193 %
194 % \subsection{Color definition}
195 %
196 % \begin{macro}{\DeclareColor}
197 % Provide a single interface here: as the data will be passed to
198 % \pkg{l3color} in any case, there is not too much to do.
199 % \begin{macrocode}
200 \NewDocumentCommand \DeclareColor { m o m }
201 {
202 \IfNoValueTF {#2}
203 { \colorlet {#1} {#3} }
204 { \definecolor {#1} {#2} {#3} }
205 }
206 % \end{macrocode}
207 % \end{macro}
208 %
209 % \subsection{Semantic colors}
210 %
211 % Pick up the standard colors from \pkg{beamer}.
212 % \begin{macrocode}
213 \DeclareColor { alert } [ RGB ] { 200 , 0 , 0 }
214 \DeclareColor { example } { green!50!black }
215 \DeclareColor { structure } [ rgb ] { 0.2 , 0.2 , 0.7 }
216 % \end{macrocode}
217 %
218 % \begin{macrocode}
219 %</class>
220 % \end{macrocode}
221 %
222 % \end{implementation}
223 %
224 % \PrintIndex