3

I have a document with multiple \maketitle tags. I would like macros that will allow me to redefine the title with a single command. While the code below produces the output I want,

\documentclass{article}
\usepackage{titling}

\begin{document}

\makeatletter
\def\maketitle{%
\par\textbf{\@title}%
\par{\@author}%
\par}
\makeatother

\title{First title}
\maketitle

\makeatletter
\def\maketitle{%
\par\textit{\@title}%
\par{\@author}%
\par}
\makeatother

\title{Second title}
\maketitle

\end{document}

I really need to have macros that encapsulate the redefining of \maketitle. I would like something like this to work:

\documentclass{article}
\usepackage{titling}

\newcommand{\mytitleOne}{\makeatletter
\def\maketitle{%
\par\textbf{\@title}%
\par{\@author}% 
\par}
\makeatother}

\newcommand{\mytitleTwo}{\makeatletter
\def\maketitle{%
\par\textit{\@title}%
\par{\@author}%
\par}
\makeatother}


\begin{document}

\mytitleOne
\title{First title}
\maketitle


\mytitleTwo
\title{Second title}
\maketitle

\end{document}
2

1 Answer 1

5
\documentclass{article}
\usepackage{titling}

\makeatletter
\newcommand\settitlebf{%
\def\maketitle{%
    \par\textbf{\@title}%
    \par\@author%
    \par}
}

\newcommand\settitleit{%
\def\maketitle{%
    \par\textit{\@title}%
    \par\@author%
    \par}
}
\makeatother

\begin{document}

\settitlebf
\title{Title One}
\maketitle

\settitleit
\title{Title Two}
\maketitle

\end{document}
3
  • Unfortunately this isn't going to work for me. All of my documents use the syntax: \title{My title} \maketitlle and I cannot really change this. I can only redefine before this happens
    – Bart Snapp
    Nov 21, 2015 at 19:37
  • I've updated my answer
    – musicman
    Nov 21, 2015 at 20:16
  • That is perfect!!! Thanks, I see what I was doing wrong now.
    – Bart Snapp
    Nov 22, 2015 at 14:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .