|
Le but du jeu est d'affiché la valeur de chaque composant d'une couleur dans le modèle RGB. Je n'utilise que LaTeX3, c'est pour l'apprendre. Ex. R:0.949 G:0.376 B:0.207. Dans la première partie du code ci-dessous, je définie une variable de tokens Dans la seconde partie, je souhaiterai reproduire ce que j'ai fait dans la première, mais en partant de l'exportation d'une couleur.
Mais Enfin, comment différencier chaque composant pour l'afficher séparément ? \documentclass{article} \setlength{\parindent}{0pt} \ExplSyntaxOn \NewDocumentCommand \createColorCompoundsRawTl { } { \regex_replace_once:nnN { ^([0-9.]*),([0-9.]*),([0-9.]*) } { \cO\{ \1 \cO\}\c{c_space_tl}\cO\{ \2 \cO\}\c{c_space_tl}\cO\{ \3 \cO\} } \l__color_compounds_raw_tl } \ExplSyntaxOff \begin{document} \section{1er partie} \ExplSyntaxOn \tl_set:Nn \l_tmpa_tl { {0.94902}~{0.37646}~{0.20784} } Count~1:~\tl_count:N \l_tmpa_tl \\ R: \tl_item:Nn \l_tmpa_tl { 1 }~ G: \tl_item:Nn \l_tmpa_tl { 2 }~ B: \tl_item:Nn \l_tmpa_tl { 3 } \\ \ExplSyntaxOff \section{2sd partie} \ExplSyntaxOn \color_set:nnn {RedOrangeRGB}{RGB}{242,96,53} \color_export:nnN {RedOrangeRGB} {comma-sep-rgb}\l__color_compounds_raw_tl Count~2:~\tl_count:N \l__color_compounds_raw_tl \\ \createColorCompoundsRawTl Count~3:~\tl_count:N \l__color_compounds_raw_tl \\ R: \tl_item:Nn \l__color_compounds_raw_tl { 1 }~ G: \tl_item:Nn \l__color_compounds_raw_tl { 2 }~ B: \tl_item:Nn \l__color_compounds_raw_tl { 3 } \\ \ExplSyntaxOff \end{document} |
|
Je ne saisis pas tout à fait l'objectif final de ta démarche, mais au vu de ton code, je te suggère d'utiliser les \documentclass{article} \setlength{\parindent}{0pt} \begin{document} \ExplSyntaxOn \color_set:nnn {RedOrangeRGB}{RGB}{242,96,53} \color_export:nnN {RedOrangeRGB} {comma-sep-rgb} \l__color_compounds_raw_clist R: \clist_item:Nn \l__color_compounds_raw_clist { 1 }~ G: \clist_item:Nn \l__color_compounds_raw_clist { 2 }~ B: \clist_item:Nn \l__color_compounds_raw_clist { 3 } \\ \clist_map_inline:Nn \l__color_compounds_raw_clist { \ifnum\fp_eval:n { #1 > 0.5 ? 1 : 0 } = 0 \textit{#1} \else \textbf{#1}\fi ~-~ } \ExplSyntaxOff \end{document} |