TransWikia.com

How to make tcolorbox find right paths of styles

TeX - LaTeX Asked on August 12, 2021

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=deftoccolumns{#1},
    }
    tcbset{/tcb/tocb/.cd,
      abstract/.code=deftocabstract{#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}

One Answer

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=deftoccolumns{#1},
  /tocb/abstract/.code=deftocabstract{#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).

Correct answer by Kpym on August 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP