Hamza Abbad Hamza Abbad - 4 months ago 9
LaTeX Question

How can I redefine a starred LaTeX command that take parameters?

I am trying to redefine

\chapter
command like this

\let\oldchapter\chapter
\renewcommand\chapter[1]{{\color{green!30!blue!80}\oldchapter{#1}}}


These instructions were working before I start using the starred version
\chapter*
, but now I get compilation errors. I have searched a lot and found some guides (like this one) and answers but I can't get my code to work. Please tell me how I can edit this code to make it work, I have seen a lot of examples but I couldn't figure the right way to redefine starred commands.

Answer

Finally, I have found the solution from this old topic. My working code is now :

\newcommand{\@chapterstar}[1]{{\color{green!30!blue!80}\oldchapter*{#1}}}
\newcommand{\@chapternostar}[1]{{\color{green!30!blue!80}\oldchapter{#1}}}
\renewcommand{\chapter}{\@ifstar{\@chapterstar}{\@chapternostar}}