Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
possible duplicate of How to use the content of \title{} as a reference? –  Mico Oct 6 '11 at 17:45
1  
The objective of this question, how to obtain the value of the \title{} command, appears to have already been addressed in tex.stackexchange.com/questions/15804/…. –  Mico Oct 6 '11 at 17:46
add comment

1 Answer

up vote 10 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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