Debian Codegraph @

texmf-dist/doc/latex/spotxcolor/spotxcolor-technote.tex

raw
1 %#!lualatex -synctex=1 spotxcolor-technote
2 \documentclass[luatex]{article}
3 \usepackage{shortvrb}\AtBeginDocument{\MakeShortVerb{\|}}
4 \usepackage{amsmath}
5 \usepackage{hyperref}
6 \usepackage{xcolor}
7 \usepackage{tikz}
8 \usepackage{tcolorbox}
9 \tcbuselibrary{skins}
10
11 \usepackage{spotxcolor}
12 % Define Triadic Spot Colors for Examples
13 \definespotcolor{DIC161s}{DIC 161s*}{0, 0.64, 1, 0} % Vermilion
14 \definespotcolor{DIC256s}{DIC 256s*}{0.9, 0, 0.4, 0} % Green
15 \definespotcolor{DIC200s}{DIC 200s*}{0.5, 0.8, 0, 0} % Purple
16
17 \newcommand\pkg[1]{\textsf{#1}}
18 \newcommand\cs[1]{\texttt{\textbackslash #1}}
19 \newcommand\op[1]{\texttt{#1}}
20
21 \title{\textsf{spotxcolor} Technical Note}
22 \author{Munehiro Yamamoto}
23 \date{2026/03/29 v1.7}
24
25 \begin{document}
26 \maketitle
27
28 \begin{abstract}
29 This document describes the design rationale and internal architecture of the \pkg{spotxcolor} package.
30 It is intended for developers, contributors, and advanced users who wish to understand how spot color output is achieved across all \TeX\ engines and graphics layers, and why certain limitations exist.
31 For usage instructions, see the companion document \texttt{spotxcolor.tex}.
32 \end{abstract}
33
34 \tableofcontents
35
36 % =====================================================================
37 \section{Design Philosophy}
38 % =====================================================================
39
40 \subsection{The Problem}
41
42 PDF spot colors (Separation color spaces) require a fundamentally different PDF structure from process colors (DeviceCMYK/DeviceRGB).
43 While \pkg{xcolor} provides an excellent color mixing and tinting engine, it has no awareness of PDF Separation color spaces.
44 Every color---including spot colors registered via |\definecolor{...}{cmyk}{...}|---is ultimately emitted as CMYK (or RGB) operators in the PDF content stream.
45
46 The legacy \pkg{spotcolor} package and the more modern \pkg{colorspace} package each attempted to solve this, but with significant limitations:
47 \pkg{spotcolor} suffered from structural PDF issues with modern \pkg{expl3}/\pkg{xcolor} updates,
48 and \pkg{colorspace} lacked full support for \texttt{dvipdfmx}-based workflows ((u)p\LaTeX).
49
50 \subsection{The Strategy: Intercept, Detect, Replace}
51
52 Rather than modifying \pkg{xcolor}'s internal color model (which would break its mixing engine),
53 \pkg{spotxcolor} takes a non-invasive approach:
54
55 \begin{enumerate}
56 \item \textbf{Register normally.}
57 Each spot color is registered in \pkg{xcolor}'s database as standard CMYK via |\definecolor|.
58 This preserves full compatibility with \pkg{xcolor}'s tinting (|DIC161s!50|), mixing, and color expression engine.
59
60 \item \textbf{Create PDF objects.}
61 At definition time, \pkg{spotxcolor} creates the PDF Separation color space objects (Tint Transform Function + Separation array) and registers them in the page's |/ColorSpace| resource dictionary.
62
63 \item \textbf{Intercept at output time.}
64 At the point where CMYK values are about to be written into the PDF content stream, \pkg{spotxcolor} checks whether those values are a proportional scalar multiple of any registered spot color's base CMYK.
65 If so, the CMYK operators are replaced with Separation color space operators.
66 \end{enumerate}
67
68 This ``late interception'' strategy means \pkg{spotxcolor} is transparent to \pkg{xcolor}, \pkg{PGF}/\pkg{TikZ}, \pkg{tcolorbox}, and \pkg{colortbl}---they all continue to work with standard CMYK values, unaware that the final PDF output uses spot colors.
69
70 \subsection{Proportional Tint Detection}
71
72 The core matching algorithm is simple:
73 given the current CMYK values $(c, m, y, k)$ and a registered spot color with base CMYK $(b_c, b_m, b_y, b_k)$,
74 \pkg{spotxcolor} computes the tint factor $t$ from the dominant (largest) base component and verifies that all four components satisfy:
75 \[
76 \lvert c_i - t \cdot b_i \rvert < \varepsilon \quad (i \in \{c, m, y, k\})
77 \]
78 where $\varepsilon = 0.005$.
79 If all four pass, the color is recognized as tint $t$ of that spot color.
80
81 This detects all expressions of the form |DIC161s!N| (where $N$ is a percentage).
82 Expressions like |DIC161s!80!black| produce non-proportional CMYK values (the K component is introduced by the black mix) and correctly fall back to CMYK.
83
84 % =====================================================================
85 \section{Interception Points}
86 % =====================================================================
87
88 \pkg{spotxcolor} patches multiple interception points to achieve comprehensive spot color coverage.
89 Each point addresses a different code path through which colors reach the PDF content stream.
90
91 \subsection{Layer 1: \cs{set@color} (xcolor/LaTeX color stack)}
92
93 \textbf{Covers:} |\color|, |\textcolor|, \pkg{colortbl} row colors, \pkg{tcolorbox} elements.
94
95 When \pkg{xcolor} processes a color command, it computes the final CMYK values, stores them in |\current@color|, and calls |\set@color| to push the color onto the PDF color stack.
96
97 \pkg{spotxcolor} patches |\set@color| at |\AtBeginDocument|:
98
99 \begin{itemize}
100 \item \textbf{pdfTeX/LuaTeX:}
101 Before the original |\set@color| executes, |\current@color| is parsed.
102 If a spot color match is found, |\current@color| is replaced with the spot color operator string (e.g., |/DIC161s cs /DIC161s CS 0.5 sc 0.5 SC|).
103 The original |\set@color| then pushes this modified string onto the color stack via |\pdfliteral|.
104
105 \item \textbf{dvipdfmx/XeTeX:}
106 |\current@color| cannot be replaced with raw PDF operators because |\special{color push cmyk ...}| expects model-prefixed format.
107 Instead, the original |\set@color| runs first (CMYK color push), then |\special{pdf:code ...}| is emitted to override with spot color operators.
108 \end{itemize}
109
110 \medskip
111 \noindent\textbf{Technical pitfall---ExplSyntax catcodes:}
112 All references to |\set@color|, |\current@color|, and |\set@page@color| in \pkg{expl3} code must use |c|-type access (e.g., |\cs_set_eq:cc{...}{set@color}|) because |@| is catcode~12 (other) in \pkg{expl3} but catcode~11 (letter) in these \LaTeX\ kernel macros.
113 Attempting to write |\set@color| directly in \pkg{expl3} code causes \TeX\ to parse it as |\set| followed by |@color|.
114
115 \subsection{Layer 2: \cs{set@page@color} (\cs{pagecolor})}
116
117 \textbf{Covers:} |\pagecolor|, |\nopagecolor|.
118
119 \pkg{xcolor}'s |\pagecolor| calls |\set@page@color| \emph{without} going through |\set@color|, so the Layer~1 patch does not affect it.
120
121 \begin{itemize}
122 \item \textbf{pdfTeX/LuaTeX:}
123 |\set@page@color| copies |\current@color| to |\current@page@color|.
124 \pkg{spotxcolor} intercepts \emph{before} this copy, modifying |\current@color| so the fill rectangle uses spot operators.
125
126 \item \textbf{dvipdfmx/XeTeX:}
127 |\special{background cmyk ...}| only supports standard color models.
128 \pkg{spotxcolor} lets the original run (CMYK fallback), stores the spot color operators, and uses a |shipout/background| hook to overdraw with a spot-colored full-page rectangle.
129 A reverse-CTM translation (|q 1 0 0 1 -TX -TY cm ... Q|) maps coordinates from the content stream's translated origin back to absolute PDF coordinates.
130 \end{itemize}
131
132 \subsection{Layer 3: PGF Driver Macros (TikZ fill/stroke)}
133
134 \textbf{Covers:} |\fill|, |\draw|, |\pgfsetfillcolor|, |\pgfsetstrokecolor|, all TikZ color operations.
135
136 PGF's internal color management resolves colors through its own code path and calls low-level driver macros defined in \texttt{pgfsys-common-pdf.def}:
137
138 \begin{quote}
139 \begin{verbatim}
140 \pgfsys@color@cmyk@fill#1#2#3#4
141 → \pgfsysprotocol@literal{#1 #2 #3 #4 k}
142 \pgfsys@color@cmyk@stroke#1#2#3#4
143 → \pgfsysprotocol@literal{#1 #2 #3 #4 K}
144 \end{verbatim}
145 \end{quote}
146
147 These macros bypass |\set@color| entirely.
148 \pkg{spotxcolor} patches all four CMYK driver macros (|cmyk@fill|, |cmyk@stroke|, |cmy@fill|, |cmy@stroke|) to check the four component arguments against registered spot colors.
149 If matched, fill uses |/NAME cs TINT sc| and stroke uses |/NAME CS TINT SC|.
150
151 Since \texttt{pgfsys-common-pdf.def} is shared by all engines, a single set of patches covers pdfTeX, LuaTeX, XeTeX, and dvipdfmx.
152
153 \subsection{Layer 4: PGF Uncolored Patterns}
154
155 \textbf{Covers:} |pattern color=DIC161s!60|, |pattern={Lines[...]}, pattern color=...|.
156
157 PGF uncolored patterns use a dedicated color space |[/Pattern /DeviceCMYK]| (registered as |/pgfpcmyk|) with the operator format:
158 \begin{quote}
159 |/pgfpcmyk cs C M Y K /pgfpatN scn|
160 \end{quote}
161
162 For spot colors, a different color space is needed: |[/Pattern [/Separation ...]]|.
163 \pkg{spotxcolor} creates these objects (one per registered spot color) at |\AtBeginDocument| and registers them as |/pgfpspot_NAME| in page resources.
164
165 Then |\pgfsys@setpatternuncolored| is wrapped: when the CMYK arguments match a spot color, the output becomes:
166 \begin{quote}
167 |/pgfpspot_DIC161s cs 0.6 /pgfpat21 scn|
168 \end{quote}
169
170 \medskip
171 \noindent\textbf{Technical pitfall---catcode boundary crossing:}
172 The pattern patch must be installed inside a |\makeatletter| / |\AtBeginDocument| block (to run after PGF defines |\pgfsys@setpatternuncolored|), but the patch code uses \pkg{expl3} functions.
173 Writing |\ExplSyntaxOn| inside |\AtBeginDocument{...}| has \emph{no effect} because the argument is already tokenized at file-read time with |_| as catcode~8 (subscript).
174
175 The solution: define a wrapper function |\__spotxcolor_install_pattern_spot_patch:| in the \pkg{expl3} region (correct catcodes), then call it from the |\makeatletter| block via |\csname __spotxcolor_install_pattern_spot_patch:\endcsname|.
176 |\csname| constructs control sequence names from character codes, ignoring catcodes, and thus correctly bridges the catcode boundary.
177
178 % =====================================================================
179 \section{What Cannot Be Intercepted}
180 % =====================================================================
181
182 \subsection{Hatching vs.\ Shading: A Structural Difference}
183
184 Both hatching (patterns) and shading (gradients) are PDF features used by PGF/TikZ, but they differ fundamentally in \emph{where the color information lives} in the PDF structure.
185
186 \subsubsection{Hatching (Uncolored Patterns)}
187
188 Color is specified by \textbf{operators in the content stream}:
189 \begin{quote}
190 \begin{verbatim}
191 /pgfpcmyk cs 0 0.64 1 0 /pgfpat3 scn % CMYK hatching
192 \end{verbatim}
193 \end{quote}
194
195 The pattern tile itself (defined in a separate Pattern object) is color-independent---it describes only geometry (line angles, spacing, dot radii).
196 The color is applied at the point of use via the |cs|/|scn| operators.
197
198 \pkg{spotxcolor} intercepts at this point: it wraps |\pgfsys@setpatternuncolored| and replaces the operator with a spot color pattern color space:
199 \begin{quote}
200 \begin{verbatim}
201 /pgfpspot_DIC161s cs 0.6 /pgfpat21 scn % spot color hatching
202 \end{verbatim}
203 \end{quote}
204
205 This required creating |[/Pattern [/Separation ...]]| color space objects but \emph{no changes} to PGF's pattern generation code.
206
207 \subsubsection{Shading (Gradients)}
208
209 Color is \textbf{frozen into a standalone PDF object} (Shading dictionary) at definition time:
210 \begin{quote}
211 \begin{verbatim}
212 << /ShadingType 2
213 /ColorSpace /DeviceRGB % hardcoded by PGF
214 /Function << /C0 [r g b] % endpoint colors as RGB
215 /C1 [r g b] ... >>
216 >>
217 \end{verbatim}
218 \end{quote}
219
220 This Shading dictionary is wrapped in a Form XObject (|/Fm16|, |/Fm17|, etc.) and referenced from the content stream with a single operator:
221 \begin{quote}
222 \begin{verbatim}
223 /Fm16 Do % "paint this shading" — no color info here
224 \end{verbatim}
225 \end{quote}
226
227 The content stream contains \emph{no color operators} to intercept.
228 The color has already been resolved to RGB and embedded in the object.
229
230 True spot color gradients would require:
231 \begin{enumerate}
232 \item Generating Shading objects with |/ColorSpace [/Separation /DIC#20161s* /DeviceCMYK funcRef]|
233 \item Using tint values (|/C0 [1]|, |/C1 [0.1]|) instead of RGB triples
234 \item Rewriting PGF's shading generation code in \texttt{pgfcoreshading.code.tex}
235 \end{enumerate}
236
237 This is architecturally infeasible at the driver-patch level and constitutes a PGF core modification.
238
239 \subsection{Non-Proportional Color Mixes and DeviceN}
240
241 Expressions like |DIC161s!80!black| produce CMYK values $(0, 0.512, 0.8, 0.2)$.
242 The $K=0.2$ component breaks proportionality with the base $(0, 0.64, 1, 0)$, so no single-spot tint can represent this color.
243
244 The PDF specification provides |/DeviceN| color spaces for multi-ink combinations:
245 \begin{quote}
246 \begin{verbatim}
247 [/DeviceN [/DIC#20161s* /Black] /DeviceCMYK ...]
248 \end{verbatim}
249 \end{quote}
250
251 Implementing DeviceN support would require:
252 \begin{itemize}
253 \item Parsing non-proportional CMYK values to decompose them into spot + process components
254 \item Creating DeviceN color space objects with multi-dimensional tint transform functions
255 \item Extending the matching engine to handle multi-spot combinations
256 \end{itemize}
257
258 This is a substantial extension and is considered out of scope for \pkg{spotxcolor}.
259
260 % =====================================================================
261 \section{Operator String Construction}
262 % =====================================================================
263
264 A recurring technical challenge in \pkg{spotxcolor} is constructing PDF operator strings with correct spacing in the \pkg{expl3} environment.
265
266 \subsection{The Space Swallowing Problem}
267
268 In \pkg{expl3}, |~| (tilde) has catcode~10 (space).
269 However, after \TeX\ reads a control sequence name, it enters ``state~S'' (skipping spaces).
270 In this state, a catcode-10 token is silently discarded:
271
272 \begin{quote}
273 \begin{verbatim}
274 % BROKEN: space after \g__spotxcolor_matched_name_tl is swallowed
275 \tl_set:Nx \l_tmpa_tl
276 { / \g__spotxcolor_matched_name_tl ~ cs ~ ... }
277 % Produces: /DIC161scs (no space!)
278 \end{verbatim}
279 \end{quote}
280
281 \subsection{The Solution: n-type Alternation}
282
283 \pkg{spotxcolor} builds operator strings using |\tl_put_right:Nn| (n-type, literal tokens) alternating with |\tl_put_right:NV| (V-type, variable expansion):
284
285 \begin{quote}
286 \begin{verbatim}
287 \tl_clear:N \l_tmpb_tl
288 \tl_put_right:Nn \l_tmpb_tl { / }
289 \tl_put_right:NV \l_tmpb_tl \g__spotxcolor_matched_name_tl
290 \tl_put_right:Nn \l_tmpb_tl { ~cs~/ } % ~ is in braces → state M
291 \tl_put_right:NV \l_tmpb_tl \g__spotxcolor_matched_name_tl
292 \tl_put_right:Nn \l_tmpb_tl { ~CS~ }
293 ...
294 \end{verbatim}
295 \end{quote}
296
297 The |~| inside braces is read in state~M (middle of line), where catcode-10 tokens are preserved.
298 This guarantees correct spacing: |/DIC161s cs /DIC161s CS 1 sc 1 SC|.
299
300 % =====================================================================
301 \section{Engine-Specific Considerations}
302 % =====================================================================
303
304 \subsection{pdfTeX and LuaTeX}
305
306 These engines support |\pdfliteral| (or |\pdfextension literal|) which writes raw strings directly into the content stream.
307 |\current@color| is stored as a raw operator string (e.g., |0 0.64 1 0 k 0 0.64 1 0 K|).
308 \pkg{spotxcolor} can modify |\current@color| in-place before it is pushed, making interception clean and complete.
309
310 \subsection{dvipdfmx and XeTeX}
311
312 These engines use |\special{color push cmyk c m y k}| for color stack management.
313 The |cmyk| model prefix is required; raw PDF operators cannot be passed through this channel.
314
315 \pkg{spotxcolor}'s approach for these engines:
316 \begin{enumerate}
317 \item Let the original |\set@color| execute (CMYK color push via |\special{color push ...}|).
318 \item Immediately emit |\special{pdf:code /NAME cs /NAME CS TINT sc TINT SC}| to override.
319 \end{enumerate}
320
321 This produces content streams where CMYK operators appear followed by spot color operators.
322 The spot color operators override the CMYK state, so the visual result is correct.
323
324 For |\pagecolor|, |\special{background cmyk ...}| generates a separate background content stream that cannot be overridden.
325 \pkg{spotxcolor} uses the |shipout/background| hook to emit a spot-colored full-page rectangle in the main content stream, which paints over the CMYK background.
326
327
328 \section{Comparison of Implementation Approaches}
329
330 This section compares the internal architecture of the four spot color packages.
331 Understanding these differences explains why each package has its particular set of capabilities and limitations.
332
333 \subsection{\textsf{spotcolor} --- Direct PDF Literal Injection}
334
335 The \textsf{spotcolor} package (2006) takes the simplest possible approach.
336 Designed exclusively for pdfTeX, its |\SpotColor| command directly emits PDF literal operators via |\pdfliteral|:
337
338 \begin{quote}
339 \begin{verbatim}
340 \pdfliteral{/NAME cs /NAME CS TINT sc TINT SC}
341 \end{verbatim}
342 \end{quote}
343
344 This bypasses the \LaTeX\ color stack entirely, so the spot color state is lost at page breaks.
345 The package does define a custom \pkg{xcolor} color model (|spotcolor|) via |\xcolor@{}{}{spotcolor}{...}|, but \pkg{xcolor}'s driver code does not know how to render this model, so standard commands like |\textcolor| do not produce spot color output.
346
347 There is no PGF integration, no pattern support, and no interaction with |\set@color|.
348
349 \subsection{\textsf{xespotcolor} --- XeTeX/dvipdfmx Focused}
350
351 The \textsf{xespotcolor} package (2014--2021) targets Xe\LaTeX\ and \texttt{dvipdfmx}.
352 Its core command |\SpotColor| uses |\special{pdf:literal ...}| followed by |\aftergroup\reset@color| to partially manage the color state.
353
354 Its most notable contribution is defining custom PGF driver macros:
355
356 \begin{quote}
357 \begin{verbatim}
358 \gdef\pgfsys@color@spotcolor@stroke#1#2{
359 \special{pdf:literal /#1 CS #2 SC}}
360 \gdef\pgfsys@color@spotcolor@fill#1#2{
361 \special{pdf:literal /#1 cs #2 sc}}
362 \end{verbatim}
363 \end{quote}
364
365 However, these macros are only called when the user explicitly invokes spot color commands.
366 Standard \pkg{xcolor} operations (|\color|, |\textcolor|) go through the normal CMYK driver macros and produce process color output.
367 The package also disables PGF's color space management (|\pgf@sys@pdf@colorspaces@existsfalse|) when TikZ or \pkg{tcolorbox} is loaded, which is a workaround for resource dictionary conflicts.
368
369 \subsection{\textsf{colorspace} --- xcolor Internal Hook}
370
371 The \textsf{colorspace} package (2015--2019) takes a more sophisticated approach.
372 It defines custom \pkg{xcolor} color models and hooks into \pkg{xcolor}'s internal color representation by storing a ``spot color reference'' (the PDF color space name) alongside the standard color data.
373
374 When |\set@color| processes a color, \textsf{colorspace} extracts this reference from |\current@color| and uses it to emit the correct Separation operators.
375 It also provides PGF driver macros (|\pgfsys@color@&spot@fill|, etc.) that retrieve the spot color reference from PGF's internal fill/stroke color variables.
376
377 Key limitations:
378
379 \begin{itemize}
380 \item \textbf{No dvipdfmx/XeTeX support:} The package directly uses |\pdfobj| and |\pdfpageresources|, which are pdfTeX/LuaTeX primitives.
381 There is no |\special|-based fallback.
382
383 \item \textbf{Manual page resource management:} Users must call |\pagecolorspace{...}| and |\resetpagecolorspace| to manage the |/ColorSpace| dictionary, which is fragile in modern \LaTeX.
384
385 \item \textbf{No pattern support:} While the package provides fill/stroke PGF driver macros, uncolored patterns still use the default |[/Pattern /DeviceCMYK]| color space with CMYK values.
386
387 \item \textbf{DeviceN support:} Uniquely among these packages, \textsf{colorspace} supports |/DeviceN| color spaces for multi-ink combinations.
388 \end{itemize}
389
390 \subsection{\textsf{spotxcolor} --- Late-Stage Interception}
391
392 \pkg{spotxcolor} (2026) takes a fundamentally different approach: rather than modifying \pkg{xcolor}'s internal color model, it lets \pkg{xcolor} operate entirely in CMYK and intercepts the output at multiple stages.
393
394 The key insight is that for proportional tints (|DIC161s!N|), the resulting CMYK values are always a scalar multiple of the base spot color's CMYK values.
395 By checking this proportionality at output time, \pkg{spotxcolor} can transparently convert CMYK to Separation operators without any cooperation from \pkg{xcolor}'s mixing engine.
396
397 Four interception layers cover all output paths:
398
399 \begin{enumerate}
400 \item |\set@color| (xcolor color stack) --- covers |\color|, |\textcolor|, \pkg{colortbl}, \pkg{tcolorbox}
401 \item |\set@page@color| --- covers |\pagecolor|
402 \item PGF driver macros (|\pgfsys@color@cmyk@fill|, etc.) --- covers TikZ fill/stroke
403 \item |\pgfsys@setpatternuncolored| --- covers pattern fills via |[/Pattern [/Separation ...]]|
404 \end{enumerate}
405
406 This approach has the advantage of being completely transparent to all packages that use \pkg{xcolor} or PGF for color management, requiring no special commands or manual resource management.
407 The trade-off is that non-proportional mixes (|DIC161s!80!black|) cannot be detected and fall back to CMYK, whereas \textsf{colorspace}'s DeviceN support can theoretically handle such cases.
408
409 \subsection{Summary of Architectural Differences}
410
411 \begin{center}
412 \renewcommand{\arraystretch}{1.3}
413 \small
414 \begin{tabular}{lllll}
415 \hline
416 \textbf{Aspect}
417 & \textsf{spotcolor}
418 & \textsf{xespotcolor}
419 & \textsf{colorspace}
420 & \textsf{spotxcolor} \\
421 \hline
422 Color model
423 & custom
424 & custom
425 & custom
426 & CMYK (native) \\
427 Interception
428 & none
429 & explicit cmd
430 & |\current@color|
431 & |\set@color| + PGF \\
432 Color stack
433 & no
434 & partial
435 & yes
436 & yes \\
437 Resource mgmt
438 & manual
439 & manual
440 & manual
441 & automatic \\
442 Engine support
443 & pdf only
444 & xe/dvipdfmx
445 & pdf/lua
446 & all four \\
447 Code style
448 & \LaTeXe
449 & \LaTeXe
450 & \LaTeXe
451 & expl3 + \LaTeXe \\
452 \hline
453 \end{tabular}
454 \end{center}
455
456
457 % =====================================================================
458 \section{Compatibility with pdfmanagement (v1.6+)}
459 % =====================================================================
460
461 \subsection{The Resource Registration Conflict}
462
463 When pdfmanagement (|\DocumentMetadata{}|) is active, it takes exclusive control of all PDF page resources.
464 It redefines PGF's |\pgfutil@addpdfresource@colorspaces| with its own parser (|\__pdfmanagement_patch_pgfcolorspaces:w|), which scans for a |\q_stop| delimiter in a specific argument format.
465
466 \pkg{spotxcolor} passed arguments like |/DIC161s \l_tmpb_tl \space 0 R| where |\l_tmpb_tl| was an already-expanded object number.
467 This token list did not contain the delimiter expected by the pdfmanagement parser, causing a ``Runaway argument'' error:
468
469 \begin{quote}
470 \begin{verbatim}
471 Runaway argument?
472 DIC161 \l_tmpb_tl \space 0 R\q_stop ...
473 ! File ended while scanning use of
474 \__pdfmanagement_patch_pgfcolorspaces:w.
475 \end{verbatim}
476 \end{quote}
477
478 Similarly, direct |\pdfpageresources| access (the fallback path when PGF is not loaded) is explicitly forbidden when pdfmanagement is active.
479
480 \subsection{Centralized Resource Dispatch}
481
482 A boolean flag |\g__spotxcolor_pdfmanagement_bool| is detected at package load time via |\IfPDFManagementActiveTF|, and rewires the centralized resource helper |\spotxcolor_add_colorspace_resource:nn|:
483
484 \begin{quote}
485 \begin{verbatim}
486 \bool_if:NTF \g__spotxcolor_pdfmanagement_bool
487 { \pdfmanagement_add:nne
488 { Page/Resources/ColorSpace } {#1} {#2} }
489 { % traditional path:
490 % \pgfutil@addpdfresource@colorspaces
491 % or \pdfpageresources / \special{pdf:put}
492 }
493 \end{verbatim}
494 \end{quote}
495
496 Note the use of the |nne| variant (not |nnn|): the third argument (object reference, e.g., |42 0 R|) must be e-expanded at call time.
497 The |nnn| variant stores the unexpanded token list, and since |\spotxcolor_add_colorspace_resource:nn| is called multiple times (once per |\definespotcolor|), the last call's object reference overwrites earlier ones---causing all spot colors to share a single Separation CS.
498
499 This completely bypasses the pdfmanagement-patched |\pgfutil@addpdfresource@colorspaces|, eliminating the argument format mismatch.
500
501 The path format |Page/Resources/ColorSpace| (no spaces around slashes) is confirmed from \texttt{colorspace-patches-tmp-ltx.sty} in the \TeX\ Live distribution, which uses |\pdfmanagement_add:nee {Page/Resources/ColorSpace}| for the same purpose.
502
503 \subsection{Affected Code Paths}
504
505 Four code paths were updated to use centralized dispatch:
506
507 \begin{enumerate}
508 \item \textbf{Separation CS registration} (|\spotxcolor_create_pdf_obj:nnn|):
509 Called at |\definespotcolor| time.
510 Each spot color's |/NAME objRef| entry is registered via |\spotxcolor_add_colorspace_resource:nn|, which now branches internally.
511
512 \item \textbf{Bulk resource fallback} (|\AtBeginDocument|, |\g_spotxcolor_resource_tl|):
513 When PGF is not loaded in traditional mode, accumulated resources are injected via |\pdfpageresources|.
514 This block is now guarded by |\bool_if:NF \g__spotxcolor_pdfmanagement_bool|.
515 (When pdfmanagement is active, resources were already registered individually via path~1.)
516
517 \item \textbf{Pattern CS creation} (|\__spotxcolor_create_pattern_cs:|):
518 Creates |[/Pattern [/Separation ...]]| objects and registers them as |/pgfpspot_NAME|.
519 Previously called |\pgfutil@addpdfresource@colorspaces| directly; now uses the centralized helper with |\exp_args:NnV| to safely pass expanded object references.
520
521 \item \textbf{CMYK Pattern CS} (|\AtBeginDocument|, |/pgfpcmyk|):
522 The |/pgfpcmyk [/Pattern /DeviceCMYK]| registration previously used |\pgfutil@addpdfresource@colorspaces|; now uses |\csname spotxcolor_add_colorspace_resource:nn\endcsname| to bridge the catcode boundary from |\makeatletter| context.
523 \end{enumerate}
524
525 \subsection{Interaction with PGF's Own pdfmanagement Awareness}
526
527 Recent PGF versions (3.1.10+) include their own pdfmanagement patches, which also rewrite |\pgfutil@addpdfresource@colorspaces|.
528 Because \pkg{spotxcolor} completely bypasses |\pgfutil@addpdfresource@colorspaces| when pdfmanagement is active, there is no risk of double-patching or argument format conflicts between \pkg{spotxcolor} and PGF's pdfmanagement layer.
529
530 \subsection{Note on l3color}
531
532 \pkg{spotxcolor} registers spot colors via \pkg{xcolor}'s |\definecolor{...}{cmyk}{...}|.
533 The \textsf{expl3} color system (\textsf{l3color}) maintains a separate color database and does not automatically import \pkg{xcolor} definitions, so |\color_select:n{DIC161s}| will fail with ``Unknown color''.
534
535 This is not a limitation of \pkg{spotxcolor} but a consequence of the current \pkg{xcolor}--\textsf{l3color} boundary:
536 \pkg{xcolor} does not yet provide a bridge to register its colors in the \textsf{l3color} database.
537 Package developers building on \pkg{spotxcolor} should use the standard \pkg{xcolor} interface (|\color|, |\textcolor|, etc.)\ rather than \textsf{l3color} commands.
538
539
540 \end{document}