[Tex/LaTex] Create a Function that Generates a Title Page

titles

Suppose you have a title page layout that you like and want to use it for many different projects.

Thus the only change you will make to it will be the project name, subtitle, date, author, … etc

How would I create a function that generates a title page layout from some variables and then inputs it into my project file?

Thanks!!

Best Answer

One possibility is to write a little package, say titlepage.sty; in this package you can define some commands to provide the information that you will use for the titlepage and define a command to effectively produce the titlepage.

A little example: since standard LaTeX provides \author, \title, and \date, in the folowing example I only defined \subtitle and \institute in a way completley analogous to the definition of \author.

Once all the preparations have been done, you define your command to produce the titlepage, using the desired formatting for the elements that will be used.

Here's a very simple version of mytitlepage.sty:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mytitlepage}

\def\subtitle#1{\gdef\@subtitle{#1}}
\def\@subtitle{\@latex@warning@no@line{No \noexpand\subtitle given}}
\def\institute#1{\gdef\@institute{#1}}
\def\@institute{\@latex@warning@no@line{No \noexpand\institute given}}

\newcommand\mytitlepage{%
\clearpage
\thispagestyle{empty}
{\noindent\huge\bfseries\@author\par}
\vspace*{.25\textheight}
{\raggedleft\Huge\itshape\@title\par
\large\normalfont\@subtitle\par}
\vfill
{\Large\noindent\@institute\par\medskip
\noindent\large\@date\par}
\clearpage
}

\endinput

You can save this file in your local tree and then all you have to do is to load the package in the preamble of your document, use the commands to provide the fields and invoke \mytitlepage:

\documentclass{book}
\usepackage{mytitlepage}

\title{The Title}
\subtitle{The Subtitle}
\author{The Author}
\institute{The Institute}
\date{The date}

\begin{document}

\mytitlepage

\end{document}