3

I wrote a small package that I used to typeset a book. Now, I'd like to reuse it for smaller documents. The package uses tcolorbox and defines a box like this:

\newtcblisting[auto counter,
               number within=chapter,
               crefname={Lis.}{Lis.},
               ...

The only thing I need to change when writing shorter documents is to remove the line number within=chapter.

I'm not sure how to achieve that. What's the best way:

  • Use an if to somehow test if counter chapter is defined?
  • Use an if to somehow test the document class (e.g., book vs article)?
  • Add an option to the package and test it to include/exclude number within?

I have very little experience developing packages, and I'll welcome any help on this question.

Thanks in advance.

1 Answer 1

6

you can check for document class, by name but more general is to check for \chapter

\@ifundefined{chapter}
  {no chapter version}
   {chapter version}
3
  • Thanks, but I'm still stuck. At this point, this is more a tcolorbox/pgfkeys question. I tried "number within=\@ifundefined{chapter}{???}{chapter}," but I don't know what to use for ??? to leave the key unset. I also tried to rely on tcbset, but "\tcbset{new/number within=chapter}" doesn't seem to have any effect. Nov 8, 2022 at 18:36
  • maybe ask a new question about that I haven't used tcolorbox keys too much myself. @MichelCharpentier Nov 8, 2022 at 18:52
  • Just did. See tex.stackexchange.com/q/664528. Thanks. Nov 8, 2022 at 19:04

You must log in to answer this question.

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