In the attempt of reproducing the layout of a book, I need to use the title of the book in one of the headings. Specifically, using fancyhdr, I'd do something like this
\fancyhead[CE]{\scshape \lowercase{the title of the book}}
However, even though I could hardcode the title of the book in there, I'd rather avoid it, because most likely I'll use that title elsewhere (in the cover, which I'd do with LaTeX as well, but also in first page, or whatever).
So my inclination is to do something like this,
\title{the title of the book}
and then use \thetitle or something whenever I needed it. However, I'm not sure what is the proper way of doing it.
I've found this question on StackOverflow, which has answers of various ages. The most recent answer suggests to \usepackage{authoraftertitle}+\MyTitle, while another suggests to \renewcommand{\title} so that \title also defines \thetitle.
The suggested existing question gives an answer, but I can't seem to apply it directly to my usecase.
For instance, this doesn't work (I'm not reporting the errors, because I'm sure expert readers know why it's wrong, even if I don't),
\fancyhead[CE]{\scshape \lowercase{\makeatletter\@title\makeatother}}
whereas this only partially works, as \lowercase seems to be ineffective,
\makeatletter
\fancyhead[CE]{\scshape \lowercase{\@title}}
\makeatother
It turns out that this works
\makeatletter
\fancyhead[CE]{\scshape \MakeLowercase{\@title}}
\makeatother
but I don't know why. Maybe an explanation or at least a hint about why this works woud be nice.
\makeatletterand\makeatotherwork is that they make the @ character a normal character if the commands are executed when the code is loaded and all the commands are 'tokenized' as it is called. This means the first variant does not work because\@titleis encountered when the file is loaded, but\makeatletteris not executed at that point because it is inside of the\fancyheaddeclaration. As a rule of thumb\makeatletterand\makeatothershould always be at the 'main' level of the code and never inside a command or environment. – Marijn Dec 25 '22 at 15:19\lowercaseand\MakeLowercaseis exactly what you have encountered, i.e., one is a low-level command that tries to change case of the input directly, while the other is a more complex ('expandable') macro that can be used inside of other complex macros. – Marijn Dec 25 '22 at 15:24