Defining commands of commands

If you have prior programming experience, it may help to think of it this way (although that’s not actually what’s happening):

\thechapterimage is a variable (which stores the image path), and to assign a new value to this variable, you need to write \renewcommand\thechapterimage{some value}.

Now, this is obviously very cumbersome when done repeatedly so we define a shortcut for this “assignment.” The shortcut corresponds to a method (more precisely, a setter method): it gets one parameter and sets the value:

\newcommand\chapterimage[1]{\renewcommand\thechapterimage{#1}}

Clearly, this “setter” is executing the same assignment as above. Strictly speaking, you don’t need the \chapterimage macro but it makes the code simpler and clearer.


You probably mean "why not using directly \renewcommand\thechapterimage{image} in the document instead of the detour with \chapterimage". That is possible too, but it is

  1. longer and
  2. means that a user has to use \renewcommand regularly. Package writer write in such cases often a wrapper command which hides the \def/\renewcommand from the user. Other examples for such wrapper commands are \title and \author.

\chapterimage (re)defines \thechapterimage which is used inside \chapter.