# defining commands of commands

if you want to include an image in your chapter title, what follows may be an option:

\newcommand{\thechapterimage}{}
\def\thechapter{\Roman{chapter}}
{\centering \normalfont\sffamily
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\vspace*{-3.9cm}\hspace*{-3.1cm}% to position the figure
\includegraphics[width=\paperwidth]{\thechapterimage}\par
\rput[lb](0,2){\sffamily\bfseries\thechapter}}\par
\vspace*{30\p@}%
}


then, in the main document, you would call the name of a figure just before the chapter command:

\chapterimage{image.eps}
\chapter{Title}


What is the exact role of the first two commands \thechapterimage and \chapterimage above?

-

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:



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.

-
my question to Will was: in what sense \thechapterimage is different from \chapterimage. \thechapterimage is a varaible that can store a path, and then \chapterimage is what? what's inside? –  pluton Sep 8 '10 at 13:11
why cannot we store a path in \chapterimage? –  pluton Sep 8 '10 at 13:12
@pluton: Actually, I had intended to describe precisely that. Well, try again: \chapterimage is not a variable, it’s a method. The code in your comment to Will’s post cannot work for obvious reasons: you declare \chapterimage to take one argument – but in your usage later you use it without specifying arguments. \chapterimage doesn’t “store” anything, as it were. It is just a shortcut for setting the variable. –  Konrad Rudolph Sep 8 '10 at 13:28
\chapterimage is a method, ok, but could it be possible to achieve the same result by using \chapterimage only (no call to \thechapterimage or so)? Thanks –  pluton Sep 8 '10 at 15:52
@pluton: there is none – The names are completely arbitrary (though convention). If it weren’t convention, clearer names might be \thevalueoffoo and \setfoo, respectively. But again, these are just names for the user, they don’t impart any semantics. –  Konrad Rudolph Sep 8 '10 at 17:51

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
-

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

-
and why not \newcommand{\chapterimage}[1]{#1} and then includegraphics[width=\paperwidth]{\chapterimage} ? –  pluton Sep 7 '10 at 23:57
That doesn't make sense. Try it and see. –  Will Robertson Sep 8 '10 at 1:53
yes, this is silly (see Konrad's comment) –  pluton Sep 8 '10 at 15:40