| 1 |
% \title{Commands to show \href{https://www.first.org/tlp/}{TLP 2.0} \\ (Traffic Light Protocol) \\ labels} |
| 2 |
% |
| 3 |
% \author{Jan Starke \\ \texttt{[email protected]}} |
| 4 |
% |
| 5 |
% \changes{0.1}{07.04.2025}{inital Version} |
| 6 |
% \changes{0.2}{08.04.2025}{rename package to traffic-light-protocol} |
| 7 |
% \iffalse |
| 8 |
%<*driver> |
| 9 |
\ProvidesFile{traffic-light-protocol.dtx} |
| 10 |
%</driver> |
| 11 |
%<*package> |
| 12 |
\NeedsTeXFormat{LaTeX2e}[2003/12/01] |
| 13 |
\ProvidesPackage{traffic-light-protocol}[2025/04/08 v0.2] |
| 14 |
%</package> |
| 15 |
%<*driver> |
| 16 |
\PassOptionsToPackage{numbered}{hypdoc} |
| 17 |
\documentclass{ltxdoc} |
| 18 |
\usepackage{hypdoc} |
| 19 |
\usepackage{hyperref} |
| 20 |
\usepackage{traffic-light-protocol} |
| 21 |
\RecordChanges |
| 22 |
\begin{document} |
| 23 |
\DocInput{\jobname.dtx} |
| 24 |
\end{document} |
| 25 |
%</driver> |
| 26 |
% \fi |
| 27 |
% |
| 28 |
% \maketitle |
| 29 |
% |
| 30 |
% \AtEndDocument{\PrintChanges} |
| 31 |
% |
| 32 |
% \tableofcontents |
| 33 |
% \newpage |
| 34 |
% \PrintIndex |
| 35 |
% \newpage |
| 36 |
% \begin{abstract} |
| 37 |
% This document describes usage and implementation of the |traffic-light-protocol| package, |
| 38 |
% which allows typesetting TLP labels in your document.tags |
| 39 |
% \end{abstract} |
| 40 |
% |
| 41 |
% \section{Usage} |
| 42 |
% |
| 43 |
% You can simply use this package by calling the |\tlp| \marg{level} command. |
| 44 |
% For example, calling |\tlp{red}| yields \tlp{red}. |
| 45 |
% |
| 46 |
% This package provides the following options for the |\tlp| command: |
| 47 |
% |
| 48 |
% \begin{center} |
| 49 |
% \begin{tabular}{ll} |
| 50 |
% \tt red & \tlp{red}\\\hline |
| 51 |
% \tt amber & \tlp{amber}\\\hline |
| 52 |
% \tt amber+strict & \tlp{amber+strict}\\\hline |
| 53 |
% \tt green & \tlp{green}\\\hline |
| 54 |
% \tt clear & \tlp{clear}\\ |
| 55 |
% \end{tabular} |
| 56 |
% \end{center} |
| 57 |
% |
| 58 |
% \section{Package options} |
| 59 |
% This package allows to set one of the options |rgb| or |cmyk|, which |
| 60 |
% control whether use CMYK or RGB to define colors |
| 61 |
% (the TLP standard allow any of them). |
| 62 |
% |
| 63 |
% \clearpage |
| 64 |
% |
| 65 |
% \section{Implementation} |
| 66 |
% |
| 67 |
% We rely on some package to display colored boxes: |
| 68 |
% |
| 69 |
% \begin{macrocode} |
| 70 |
\RequirePackage{expl3} |
| 71 |
\RequirePackage{l3keys2e} |
| 72 |
\RequirePackage{xcolor} |
| 73 |
% \end{macrocode} |
| 74 |
% |
| 75 |
% Load and execute package options |
| 76 |
% |
| 77 |
% \begin{macrocode} |
| 78 |
\ExplSyntaxOn |
| 79 |
\str_new:N\tlp_font_color |
| 80 |
\str_new:N\tlp_name |
| 81 |
\str_new:N\tlp_bg_color |
| 82 |
\str_set:Nn\tlp_bg_color{tlp-bg-black} |
| 83 |
\str_new:N\color_mode |
| 84 |
\str_set:Nn\color_mode{rgb} |
| 85 |
\keys_define:nn { tlp }{ |
| 86 |
color-mode .choice:, |
| 87 |
color-mode/rgb .code:n = \str_set:N\color_mode{rgb}, |
| 88 |
color-mode/cmyk .code:n = \str_set:N\color_mode{cmyk}, |
| 89 |
|
| 90 |
level .choice:, |
| 91 |
level / red .code:n = |
| 92 |
\str_set:Nn\tlp_font_color{tlp-font-red} |
| 93 |
\str_set:Nn\tlp_name{RED}, |
| 94 |
level / amber .code:n = |
| 95 |
\str_set:Nn\tlp_font_color{tlp-font-amber} |
| 96 |
\str_set:Nn\tlp_name{AMBER}, |
| 97 |
level / amber+strict .code:n = |
| 98 |
\str_set:Nn\tlp_font_color{tlp-font-amber} |
| 99 |
\str_set:Nn\tlp_name{AMBER+STRICT}, |
| 100 |
level / green .code:n = |
| 101 |
\str_set:Nn\tlp_font_color{tlp-font-green} |
| 102 |
\str_set:Nn\tlp_name{GREEN}, |
| 103 |
level / clear .code:n = |
| 104 |
\str_set:Nn\tlp_font_color{tlp-font-clear} |
| 105 |
\str_set:Nn\tlp_name{CLEAR}, |
| 106 |
} |
| 107 |
\ProcessKeysPackageOptions{tlp/color-mode} |
| 108 |
\ExplSyntaxOff |
| 109 |
% \end{macrocode} |
| 110 |
% |
| 111 |
% \subsection{Color definitions} |
| 112 |
% |
| 113 |
% The following color definitions are based on the |
| 114 |
% \href{https://www.first.org/tlp/}{TLP 2.0} standard. |
| 115 |
% |
| 116 |
% \begin{macrocode} |
| 117 |
% |
| 118 |
\ExplSyntaxOn |
| 119 |
\msg_new:nnn{traffic-light-protocol}{illegal_color_mode} |
| 120 |
{Illegal\ color\ mode:\ #1\ (only\ 'rgb'\ and\ 'cmyk'\ are\ supported)} |
| 121 |
\cs_new_protected_nopar:Npn\tlp_set_rgb_colornames:{ |
| 122 |
\definecolor{tlp-bg-black}{RGB}{0,0,0} |
| 123 |
\definecolor{tlp-font-red}{RGB}{255,43,43} |
| 124 |
\definecolor{tlp-font-amber}{RGB}{255,192,0} |
| 125 |
\definecolor{tlp-font-green}{RGB}{51,255,0} |
| 126 |
\definecolor{tlp-font-clear}{RGB}{255,255,255} |
| 127 |
} |
| 128 |
\cs_new_protected_nopar:Npn\tlp_set_cmyk_colornames:{ |
| 129 |
\definecolor{tlp-bg-black}{CMYK}{0,0,0,255} |
| 130 |
\definecolor{tlp-font-red}{CMYK}{0,83,83,0} |
| 131 |
\definecolor{tlp-font-amber}{CMYK}{0,25,100,0} |
| 132 |
\definecolor{tlp-font-green}{CMYK}{79,0,100,0} |
| 133 |
\definecolor{tlp-font-clear}{CMYK}{0,0,0,0} |
| 134 |
} |
| 135 |
\str_case:NnF\color_mode |
| 136 |
{ |
| 137 |
{rgb} {\tlp_set_rgb_colornames:} |
| 138 |
{cmyk} {\tlp_set_cmyk_colornames:} |
| 139 |
} {\msg_err:nnV{traffic-light-protocol}{illegal_color_mode}{\color_mode}} |
| 140 |
\ExplSyntaxOff |
| 141 |
% \end{macrocode} |
| 142 |
% |
| 143 |
% Now we can define the |\tlp| macro. |
| 144 |
% |
| 145 |
% \begin{macro}{\tlp} |
| 146 |
% \begin{macrocode} |
| 147 |
\ExplSyntaxOn |
| 148 |
\NewDocumentCommand{\tlp}{m}{ |
| 149 |
\keys_set:nn{tlp/level}{#1} |
| 150 |
\colorbox{\str_use:N\tlp_bg_color} |
| 151 |
{\textcolor{\str_use:N\tlp_font_color}{ |
| 152 |
\textsf{\textbf{TLP:\str_use:N\tlp_name}}}} |
| 153 |
} |
| 154 |
\ExplSyntaxOff |
| 155 |
% \end{macrocode} |
| 156 |
% \end{macro} |
| 157 |
% |