Skip to content

[Request] Add a string-based cell colouring example as that of an extension to the existing int-based one #644

Description

@quark67

Description of the proposed feature

If the manual, we have the following example (int-base example):

Image

Trying to adapt this to a Yes/No table doesn't work. Probably because my missing knowledge.
Probably a text-based example would be useful.

How the proposed feature compares to existing feature(s)

Explain with a working example how to color the following table (Yes in green, No in red):

\begin{tblr}{hlines,vlines,process=\colorBack}
    Yes & No & No \\
    No & No & Yes \\
    No & Yes & No \\
\end{tblr}

Additional context

This (natural) attempt doesn't work:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{functional} 
\begin{document}
\IgnoreSpacesOn
\prgNewFunction \colorBack {} {
	\intStepOneInline {1} {\arabic{rowcount}} {
		\intStepOneInline {1} {\arabic{colcount}} {
			\strSet \lTmpaStr {\cellGetText {##1} {####1}}
			\strCase {\lTmpaStr} {
				{No} {\cellSetStyle {##1} {####1} {bg=red!20}}
				{Yes} {\cellSetStyle {##1} {####1} {bg=green!20}}
				}
		}
	}
}
\IgnoreSpacesOff

\begin{tblr}{hlines,vlines,process=\colorBack}
    Yes & No & No \\
    No & No & Yes \\
    No & Yes & No \\
\end{tblr}
\end{document}

Result:

Image

No code error, but nothing...

Moreover: replacing \strSet \lTmpaStr {\cellGetText {##1} {####1}} with \strSet \lTmpaStr {No} still doesn't work, and this is really very strange (in this case, I wait for a whole light red background, but no, the background is still white).

Dumb "working" case (I need here to test "No" with "No"):

\IgnoreSpacesOn
\prgNewFunction \colorBack {} {
	\intStepOneInline {1} {\arabic{rowcount}} {
		\intStepOneInline {1} {\arabic{colcount}} {
			%\strSet \lTmpaStr {\cellGetText {##1} {####1}}
			\strSet \lTmpaStr {No}
			%\strCase {\lTmpaStr} {
			\strCase {No} {
				{No} {\cellSetStyle {##1} {####1} {bg=red!20}}
				{Yes} {\cellSetStyle {##1} {####1} {bg=green!20}}
				}
		}
	}
}
\IgnoreSpacesOff

Image

NB: I don't know what is a token list, I know the concept of string.

The functional manual say that \strCase wait a string, and compare it to a string. Isn't \lTempaStr a string?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions