3

I define my options of tcolorbox with different paths by \tcbset(Please see the following code).

I'd like to know how to make tcolorbox find the right path of an option? I know that I can invoke a option with its real path. But this is boring because you have to give the path every time. Is there a way to tell tcolorbox all the related paths in advance, then every option can be used directily with its name without path?

CODE:

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{geometry}
\geometry{showframe}

    \begin{document}
    \tcbset{/tcb/toca/.cd,
      columns/.code=\def\toccolumns{#1},
    }
    \tcbset{/tcb/tocb/.cd,
      abstract/.code=\def\tocabstract{#1}
    }
    
    \begin{tcolorbox}[
      colback=black!30,
      /tcb/toca/columns=1,% This is right
      abstract={some text}, % This is a wrong way because path is not given.
      ]
      something
    \end{tcolorbox}
    \end{document}

1 Answer 1

3

One possible strategy is to use .search also handler to indicate that if some (non fully qualified) key is missing in the default /tcb path, pgf should search in other paths.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{geometry}
\geometry{showframe}


\tcbset{
  /toca/columns/.code=\def\toccolumns{#1},
  /tocb/abstract/.code=\def\tocabstract{#1},
  /tcb/.search also={/toca, /tocb},
}

\begin{document}

  \begin{tcolorbox}[
    colback=red!21,
    /toca/columns=1,% This is a fully qualified key
    abstract={some text}, % This key is missing in /tcb/, so we search in /toca and /tocb
    ]
    something
  \end{tcolorbox}
\end{document}

Note: If you use /tcb/toca and /tcb/tocb in place of /toca and /tocb an infinite lookup will occur (with the default handlers).

2
  • If both /toca and /tocb have a option with the same name, columns for example, which one will be in use when invoke columns=2?
    – lyl
    Jun 30, 2021 at 12:46
  • @lyl the one that is in the first path in .search also. In this case /toca/columns.
    – Kpym
    Jun 30, 2021 at 12:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .