I've written a package that introduces a new environment:
\newfloat{foo}{htb}{bar}[chapter]
The package however can be used for articles, books, ... Since not all of these environments have the concept of chapter, on gets a No counter 'chapter' defined. exception.
How can I check if the chapter counter is defined?

\newcommand\ifcounter[3]{\@ifundefined{c@#1}{#3}{#2}}– egreg Jan 24 '14 at 15:08\ifcsnamea tiny bit better since it doesn't leave the command as\relaxif it isn't defined – cgnieder Jan 24 '14 at 15:10\expandafters needed? I figured that the conditional would expand to\@firstoftwo(or\@secondoftwo), and we'd be left with\@firstoftwo{exists}{doesn't exist}. – Beelzebielsk Dec 21 '18 at 17:29\relaxanymore (http://www.texfaq.org/FAQ-isdef). – Daniel Oct 31 '20 at 09:21