T-F-S / tcolorbox

A LaTeX package to create highly customizable colored boxes.
http://www.ctan.org/pkg/tcolorbox
LaTeX Project Public License v1.3c
224 stars 16 forks source link

New command like `\lstdefinestyle` #280

Closed matteofg closed 4 months ago

matteofg commented 4 months ago

in tcolorbox the definition of a style is done through the command \tcbset and the key .style, according to the following syntax:

\tcbset{%
  <style1>/.style = {%
    <key> = <value>,
    ...
  },
  <style2>/.style = {%
    <key> = <value>,
    ...
  },
}

Wouldn't it be better to simplify the syntax and provide a command similar to \lstdefinestyle (the name could be \tcbdefinestyle), so as to set the various styles as follows?

\tcbdefinestyle{<style1>}{<key> = <value>, ...}
\tcbdefinestyle{<style2>}{<key> = <value>, ...}
T-F-S commented 4 months ago

The listings package does not use pgfkeys and its powerful key handler mechanism. Therefore, \lstdefinestyle is needed to create own keys in the sense of styles.

On the other hand, the tcolorbox package relies on pgf and its pgfkeys. The key handlers are quite sophisticated and allow much more than only to define a style. The .style handler can have arguments, even argument patterns, etc. Often, you may want to use .code or append thing, and so on.

So, for the task of shortening the most basic usage of .style a new macro could be provided. But, IMHO, it would shadow the real mechanism which is very flexible and extensible.

Nevertheless, for personal usage one can add such a basic shortening quite easily, if needed:

\ProvideDocumentCommand{\tcbdefinestyle}{mm}{%
   \tcbset{#1./style={#2}}%
}
matteofg commented 4 months ago

Thank you for the explanation and the clarifications. Issue solved 👍

muzimuzhi commented 4 months ago

PS: Full list of pgfkeys key handlers which can be used to define and modify key styles: https://tikz.dev/pgfkeys#sec-87.4.4.

matteofg commented 4 months ago

@muzimuzhi Thank you