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}
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}
  • 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 '15 at 19:37
  • I've updated my answer – musicman Nov 21 '15 at 20:16
  • That is perfect!!! Thanks, I see what I was doing wrong now. – Bart Snapp Nov 22 '15 at 14:13

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.