7

I am currently writing a custom class that inherits from a standard class (article), and I would like to redefine the \title command, so that the end user can call it, and I would be able to get the result of that command, modify it a tiny bit, and input it to the \title command of the base class.

Actually, when writing this question, I have found a way of doing this. Here is a MWE, with the class file Test.cls:

\ProvidesClass{Test}
\LoadClass{article}

\title{\@testTitle, isn't it?}
\renewcommand*{\title}[1]{\def\@testTitle{#1}}

\endinput

And the user file:

\documentclass{Test}

\title{A great article}

\begin{document}
\maketitle
\end{document}

So in the end, the user chooses a title, but the results outputs an article with the modified title.

Is it the standard way of doing? How would you improve it?

10

Similar to this question, you can use etoolbox's \patchcmd to modify the \maketitle command:

enter image description here

\documentclass{Test}  
\title{A great article}  
\begin{document}  
\maketitle  
\end{document}

Test.cls

\ProvidesClass{Test}  
\LoadClass{article}  
\RequirePackage{etoolbox}
\patchcmd{\@maketitle}{\@title}{\@title{}, isn't it?}{}{}
\endinput  

In general, you can use \show\somecommand to see what the definition of \somecommand is, and then find the part you want to patch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.