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 try to redefine the \maketitle command as shown below.

If I use an optional argument in the redefinition I get the TeX capacity exceeded error.

Any suggestion why?

MNWE:

\documentclass{scrreprt}

\title{My Title}
\author{My Name}

\let\oldmaketitle\maketitle

\renewcommand{\maketitle}[1][]{%
  \oldmaketitle
  \rule{\textwidth}{1pt}
}

\begin{document}

\maketitle

\end{document}
share|improve this question
    
Instead of messing around with maketitle, I'd rather use the titlepage environment to design it! –  Keks Dose Sep 12 '12 at 8:35
    
Yes, but it is for supporting different maketitle versions in a package that adds a custom background style ;) –  ejoerns Sep 12 '12 at 13:17
add comment

2 Answers

up vote 7 down vote accepted

\let with commands with optional arguments (and in the KOMA classes \maketitle is defined with one optional argument) can produce undesired effects: you can use \LetLtxMacro from the letltxmacro package instead:

\documentclass{scrreprt}
\usepackage{letltxmacro}
\title{My Title}
\author{My Name}

\LetLtxMacro\oldmaketitle\maketitle

\renewcommand{\maketitle}[1][]{%
  \oldmaketitle
  \rule{\textwidth}{1pt}
}

\begin{document}

\maketitle

\end{document}

Your example code doesn't show the usage of the optional argument.

share|improve this answer
add comment

The \maketitle command in scrreprt has an optional argument, so redefining it with \let\oldmaketitle\maketitle and \renewcommand\maketitle exposes you to a very big problem, which is well described in the documentation of letltxmacro.

If all you need is to add something at the end of what \maketitle is doing, then a safe way is to use xpatch (or regexpatch):

\usepackage{xpatch} % or \usepackage{regexpatch}
\xapptocmd{\maketitle}{\noindent\rule{\textwidth}{1pt}}{}{}

However this won't add a rule below the date. The reason is that with the default options \maketitle prints a page by itself and the rule will go on the next page; if titlepage=false is specified in the options, then the \@maketitle internal command is used.

So, in order to get a rule below the date, a better trick is to patch the commands and add the rule exactly after the printing of the date, which is done by \@date:

\documentclass{scrreprt}

\usepackage{xpatch} % or \usepackage{regexpatch}

\makeatletter
%% the following patch is for the `titlepage=true` option
\xpatchcmd{\maketitle}{\@date}{\@date\par\rule{\textwidth}{1pt}}{}{}
%% the following patch is for the `titlepage=false` option
\xpatchcmd{\@maketitle}{\@date}{\@date\par\rule{\textwidth}{1pt}}{}{}
\makeatother

\begin{document}

\title{My Title}
\author{My Name}

\maketitle

\end{document}

enter image description here

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.