| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3opacity.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2021-2026 The LaTeX Project |
| 6 |
% |
| 7 |
% It may be distributed and/or modified under the conditions of the |
| 8 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 9 |
% license or (at your option) any later version. The latest version |
| 10 |
% of this license is in the file |
| 11 |
% |
| 12 |
% http://www.latex-project.org/lppl.txt |
| 13 |
% |
| 14 |
% This file is part of the "l3kernel bundle" (The Work in LPPL) |
| 15 |
% and all files in that bundle must be distributed together. |
| 16 |
% |
| 17 |
% ----------------------------------------------------------------------- |
| 18 |
% |
| 19 |
% The development version of the bundle can be found at |
| 20 |
% |
| 21 |
% https://github.com/latex3/latex3 |
| 22 |
% |
| 23 |
% for those people who are interested. |
| 24 |
% |
| 25 |
%<*driver> |
| 26 |
\documentclass[full]{l3doc} |
| 27 |
\begin{document} |
| 28 |
\DocInput{\jobname.dtx} |
| 29 |
\end{document} |
| 30 |
%</driver> |
| 31 |
% \fi |
| 32 |
% |
| 33 |
% \title{^^A |
| 34 |
% The \pkg{l3opacity} module\\ Opacity (transparency) support^^A |
| 35 |
% } |
| 36 |
% |
| 37 |
% \author{^^A |
| 38 |
% The \LaTeX{} Project\thanks |
| 39 |
% {^^A |
| 40 |
% E-mail: |
| 41 |
% \href{mailto:[email protected]} |
| 42 |
% {[email protected]}^^A |
| 43 |
% }^^A |
| 44 |
% } |
| 45 |
% |
| 46 |
% \date{Released 2026-05-15} |
| 47 |
% |
| 48 |
% \maketitle |
| 49 |
% |
| 50 |
% \begin{documentation} |
| 51 |
% |
| 52 |
% \section{Selecting opacity} |
| 53 |
% |
| 54 |
% Opacity (transparency) shares many characteristics with color. However, |
| 55 |
% limitations in terms of backends mean that it is not always possible |
| 56 |
% to use a dedicated stack for tracking opacity. The best results when |
| 57 |
% breaking pages are therefore likely to result using direct PDF output |
| 58 |
% (\pdfTeX{}, \LuaTeX{}). |
| 59 |
% |
| 60 |
% For users of PostScript-based routes, note that there are security |
| 61 |
% restrictions which can prevent opacity being available in output. In |
| 62 |
% particular, using Adobe Distiller, you will need to enable transparency |
| 63 |
% in the (text-based) configuration: this is not selectable from the GUI. |
| 64 |
% |
| 65 |
% For users of PDF-based routes, note that opacity only takes effect if |
| 66 |
% |\RequirePackage{pdfmanagement}| or \cs{DocumentMetadata}|{}| is |
| 67 |
% added \emph{before} \cs[no-index]{documentclass}, which loads and activates |
| 68 |
% the PDF management. |
| 69 |
% See \file{pdfmanagement-testphase.pdf} for more info. |
| 70 |
% |
| 71 |
% \begin{function}[added = 2025-03-27] |
| 72 |
% {\opacity_select:n, \opacity_fill:n, \opacity_stroke:n} |
| 73 |
% \begin{syntax} |
| 74 |
% \cs{opacity_select:n} \Arg{expression} |
| 75 |
% \end{syntax} |
| 76 |
% Evaluates the \meta{expression}, which should yield a value in the |
| 77 |
% range~$[0,1]$. This is then activated as an opacity for all cases |
| 78 |
% (\texttt{select}) or selectivity (\texttt{fill} and \texttt{stroke}). |
| 79 |
% The scope of the opacity setting is limited to the current \TeX{} group. |
| 80 |
% \end{function} |
| 81 |
% |
| 82 |
% \begin{function}[added = 2026-01-14] |
| 83 |
% { |
| 84 |
% \opacity_begin:n , |
| 85 |
% \opacity_fill_begin:n , |
| 86 |
% \opacity_stroke_begin:n , |
| 87 |
% \opacity_end: , |
| 88 |
% \opacity_fill_end: , |
| 89 |
% \opacity_stroke_end: |
| 90 |
% } |
| 91 |
% \begin{syntax} |
| 92 |
% \cs{opacity_begin:n} \Arg{expression} |
| 93 |
% \meta{content} |
| 94 |
% \cs{opacity_end:} |
| 95 |
% \end{syntax} |
| 96 |
% Evaluates the \meta{expression} and activates opacity for all cases |
| 97 |
% (\texttt{begin}) or selectivity (\texttt{fill} and \texttt{stroke}). |
| 98 |
% Each \texttt{begin} must have a matching \texttt{end}, but these may occur |
| 99 |
% at \emph{different} group levels. |
| 100 |
% \begin{texnote} |
| 101 |
% These functions do \emph{not} create a \TeX{} group, so can be split |
| 102 |
% for example across \tn{halign} cells. |
| 103 |
% \end{texnote} |
| 104 |
% \end{function} |
| 105 |
% |
| 106 |
% \end{documentation} |
| 107 |
% |
| 108 |
% \begin{implementation} |
| 109 |
% |
| 110 |
% \section{\pkg{l3opacity} implementation} |
| 111 |
% |
| 112 |
% \begin{macrocode} |
| 113 |
%<*code> |
| 114 |
% \end{macrocode} |
| 115 |
% |
| 116 |
% \begin{macrocode} |
| 117 |
%<@@=opacity> |
| 118 |
% \end{macrocode} |
| 119 |
% |
| 120 |
% Transitional support. |
| 121 |
% \begin{macrocode} |
| 122 |
\cs_if_exist:NT \@expl@finalise@setup@@@@ |
| 123 |
{ |
| 124 |
\tl_gput_right:Nn \@expl@finalise@setup@@@@ |
| 125 |
{ \declare@file@substitution { l3opacity.sty } { null.tex } } |
| 126 |
} |
| 127 |
% \end{macrocode} |
| 128 |
% |
| 129 |
% \begin{variable}{\l_@@_tmp_fp} |
| 130 |
% Temporary storage. |
| 131 |
% \begin{macrocode} |
| 132 |
\fp_new:N \l_@@_tmp_fp |
| 133 |
% \end{macrocode} |
| 134 |
% \end{variable} |
| 135 |
% |
| 136 |
% \begin{macro}{\opacity_select:n, \opacity_fill:n, \opacity_stroke:n} |
| 137 |
% \begin{macro} |
| 138 |
% {\opacity_begin:n, \opacity_fill_begin:n, \opacity_stroke_begin:n} |
| 139 |
% \begin{macro}{\opacity_end:, \opacity_fill_end:, \opacity_stroke_end:} |
| 140 |
% \begin{macro}{\@@_select:nNn} |
| 141 |
% \begin{macro}{\@@_select:nN} |
| 142 |
% Thin wrapper with error checking. Opacity is passed to backend |
| 143 |
% functions as a bounded, evaluated decimal number. |
| 144 |
% \begin{macrocode} |
| 145 |
\cs_new_protected:Npn \opacity_select:n #1 |
| 146 |
{ |
| 147 |
\@@_select:nNn {#1} \@@_backend_select:n |
| 148 |
{ \group_insert_after:N \@@_backend_reset: } |
| 149 |
} |
| 150 |
\cs_new_protected:Npn \opacity_fill:n #1 |
| 151 |
{ |
| 152 |
\@@_select:nNn {#1} \@@_backend_fill:n |
| 153 |
{ \group_insert_after:N \@@_backend_reset_fill: } |
| 154 |
} |
| 155 |
\cs_new_protected:Npn \opacity_stroke:n #1 |
| 156 |
{ |
| 157 |
\@@_select:nNn {#1} \@@_backend_stroke:n |
| 158 |
{ \group_insert_after:N \@@_backend_reset_stroke: } |
| 159 |
} |
| 160 |
\cs_new_protected:Npn \opacity_begin:n #1 |
| 161 |
{ \@@_select:nN {#1} \@@_backend_select:n } |
| 162 |
\cs_new_protected:Npn \opacity_fill_begin:n #1 |
| 163 |
{ \@@_select:nN {#1} \@@_backend_fill:n } |
| 164 |
\cs_new_protected:Npn \opacity_stroke_begin:n #1 |
| 165 |
{ \@@_select:nN {#1} \@@_backend_stroke:n } |
| 166 |
\cs_new_protected:Npn \opacity_end: |
| 167 |
{ \@@_backend_reset: } |
| 168 |
\cs_new_protected:Npn \opacity_fill_end: |
| 169 |
{ \@@_backend_reset_fill: } |
| 170 |
\cs_new_protected:Npn \opacity_stroke_end: |
| 171 |
{ \@@_backend_reset_stroke: } |
| 172 |
\cs_new_protected:Npn \@@_select:nNn #1#2#3 |
| 173 |
{ |
| 174 |
\fp_set:Nn \l_@@_tmp_fp {#1} |
| 175 |
\bool_lazy_or:nnTF |
| 176 |
{ \fp_compare_p:nNn \l_@@_tmp_fp < \c_zero_fp } |
| 177 |
{ \fp_compare_p:nNn \l_@@_tmp_fp > \c_one_fp } |
| 178 |
{ \msg_error:nnn { opacity } { out-of-range } {#1} } |
| 179 |
{ |
| 180 |
\exp_args:Ne #2 { \fp_use:N \l_@@_tmp_fp } |
| 181 |
#3 |
| 182 |
} |
| 183 |
} |
| 184 |
\cs_new_protected:Npn \@@_select:nN #1#2 |
| 185 |
{ \@@_select:nNn {#1} #2 { } } |
| 186 |
\msg_new:nnnn { opacity } { out-of-range } |
| 187 |
{ Opacity~value~out~of~range. } |
| 188 |
{ |
| 189 |
LaTeX~was~asked~to~set~opacity~of~#1,~but~only~values~in~the~range~ |
| 190 |
0~to~1~are~supported. |
| 191 |
} |
| 192 |
% \end{macrocode} |
| 193 |
% \end{macro} |
| 194 |
% \end{macro} |
| 195 |
% \end{macro} |
| 196 |
% \end{macro} |
| 197 |
% \end{macro} |
| 198 |
% |
| 199 |
% \begin{macrocode} |
| 200 |
%</code> |
| 201 |
% \end{macrocode} |
| 202 |
% |
| 203 |
% \end{implementation} |
| 204 |
% |
| 205 |
% \PrintIndex |