# Use xkeyval to make a title page

This is a follow up to my last question, but since the question I'm asking is substantially different despite trying to solve the same problem, I figured I'd make a new thread.

Anyway, I am trying to make a common title page to use in my documents, where I can just call a package to make a commonly formatted title. I'm hoping to just be able to put something like this in the preamble:

\usepackage[course,title,date,name,id,school,department]{customTitle}


I know that I will need to use the form course={Viscous flow} type of input with the xkeyval package. However, I am having a lot of trouble passing in the values because the TeX language style is much different from the other codes in which I've written.

The limited information that I can find is in a post like this one, but I really don't understand what's going on in the answers section, or how I might be able to apply it to this. Additionally, it looks like I might need to do something different in passing in the values, considering multiple values are embedded in a single set of { } (for example, course, title, AND date all go inside the \title command).

Here is my current style file:

% This style file requires at least LaTeX version 2e.
\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{customTitle}[2020/07/29 Custom LaTeX title]

\RequirePackage{xkeyval}

\define@key{customTitle}{}

\title{ \normalsize \textsc{[[course]]}
\\ [2.0cm]
\rule{\linewidth}{1.0pt}
\\ [0.3cm]
\LARGE \textbf{\uppercase{[[title]]}}
\rule{\linewidth}{2.0pt}
\\ [0.5cm]
\normalsize [[date]] \vspace*{3\baselineskip}}

\author{
\Large\textbf{[[name]]} \\
\small Student ID [[id]] \\ [0.5cm]
\small [[school]]\\
\small [[department]]
}

\date{\vspace*{5\baselineskip}}

\endinput


I have no idea where to go from here. I also know that there's a way to set default values, but I haven't been able to find anything solid on that which will compile. If an option isn't specified in the package input, I'm just hoping to have it be blank.

Even just help getting the \title{ } tag with multiple values set up will be a great help, hopefully I'll be able to figure the rest out based on that. Thank you!

I have found a way around using xkeyval that I wanted to share.

In my efforts to create a title page that is easily modified from each document, but which does not have a lot of code inside each document, I have been helped to create this. It requires the use of two custom packages, one of which I was going to use anyway (in my standard preamble package), and the other which needs to be inserted after the declarations. Some sample code is below, all of would appear in the preamble of a document.

%Group 1: "variable" definitions - this will appear in a custom package if needed or in a standard preamble package which is called before everything else that follows.
\newcommand\mycourse[1]{\def\thecourse{#1}}
\newcommand\mytitle[1]{\def\thetitle{#1}}
\newcommand\mydate[1]{\def\thedate{#1}}
\newcommand\myauthor[1]{\def\theauthor{#1}}
\newcommand\myid[1]{\def\theid{#1}}
\newcommand\myschool[1]{\def\theschool{#1}}
\newcommand\mydepartment[1]{\def\thedepartment{#1}}

%This section, also a part of Group 1, is optional -- it simply sets the default values if they are not specified later.
\mycourse{}
\mytitle{}
\mydate{\today}
\myauthor{}
\myid{}
\myschool{}
\mydepartment{}


For example, if I type \myauthor{Me!}, this declaration will store "Me!" as \theauthor.

This code segment I have left in my standard preamble package. The next part is specific to each document, and is where one would set the title, date, etc.:

\mytitle{Some title for the document}
\mydate{The date, or alternatively, \today}
\mycourse{the course}
\myauthor{the author's name}
\myid{author's ID}
\myschool{the university or school}
\mydepartment{the department of the author}


One would declare each of these things in their specific document. If default values are set, then these don't all have to be included, and the default values will be used without an error being thrown.

Finally, I included this last code block in a custom package called customTitle. It is what actually generates the title (so if you have another title page or the like that you prefer, this is where you'd change the style):

% This style file requires at least LaTeX version 2e.
\NeedsTeXFormat{LaTeX2e}

% Provide the name of your page, the date it was last updated, and a comment
\ProvidesPackage{customTitle}[2020/07/29 Generate custom LaTeX title]

\title{ \normalsize \textsc{\thecourse}
\\ [2.0cm]
\rule{\linewidth}{1.0pt}
\\ [0.3cm]
\LARGE \textbf{\uppercase{\thetitle}}
\rule{\linewidth}{2.0pt}
\\ [0.5cm]
\normalsize \thedate \vspace*{3\baselineskip}
}

\author{
\Large\textbf{\theauthor} \\
\small Student ID \theid \\ [0.5cm]
\small \theschool\\
\small \thedepartment
}

\date{\vspace*{5\baselineskip}}

% Use \endinput to indicate that LaTeX can stop reading this file (anything after this like will be ignored)
\endinput


Notice how the original variable declarations are utilized here in the form of \mytitle, etc.

Note These code segments, whether they are used in another package or all in the same document, must appear in the same order. The logical order follows "variable" declarations, (optional: default variable settings), setting the variables, and finally generating the title page off of the custom variable settings.

Hope this helps someone else out there.