Skip to content

Instantly share code, notes, and snippets.

@wget
Created August 28, 2017 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wget/e8da2f2fb35aa741b8ddf497c827941d to your computer and use it in GitHub Desktop.
Save wget/e8da2f2fb35aa741b8ddf497c827941d to your computer and use it in GitHub Desktop.
\documentclass{report}
\makeatletter
\usepackage{pgfopts}
% This is what we do here. We define commands like \@wgetdoc@title@maintitle
% that we need to call manually to execute their content.
\newif\if@wgetdoc@title@ownpage
\pgfkeys{
/wgetdoc/title/.cd,
% maintitle/.code={\ifx#1\@empty\else\edef\@wgetdoc@title@maintitle{#1}\fi},
maintitle/.store in=\@wgetdoc@title@maintitle,
maintitle/.value required,
subtitle/.store in=\@wgetdoc@title@subtitle,
author/.store in=\@wgetdoc@title@author,
filename/.store in=\@wgetdoc@title@filename,
ownpage/.is if=@wgetdoc@title@ownpage
}
\renewcommand{\title}[1][]{%
% The following command is a shortcut and marginally quicker than
% \pgfkeys{/wgetdoc/title/.cd, #1}
% The command cannot end with the trailing / though.
\pgfqkeys{/wgetdoc/title}{#1}
\@ifundefined{@wgetdoc@title@filename}{
% Do not use the following check. This macro is only available in
% xkeyval and allows just checking if a key is defined in a family from
% a list of families.
\@ifundefined{@wgetdoc@title@maintitle}{
\ClassError{wgetdoc}{You did not specify a main title}{}
}{}
% Check if maintitle is empty as it: maintitle=,subtitle=lorem
% or maintitle={},subtitle=lorem
% No need to check further as pgfkeys trims white spaces and
% checks performed either by \ifblank (etoolbox) or
% \@ifmtarg (ifmtarg) are lost
\ifx\@wgetdoc@title@maintitle\@empty
\ClassError{wgetdoc}{The main title you specified is empty}{}
\fi
% Custom horizontale rule only local to this environment
\newcommand{\@wgetdoc@title@hrule}{\rule{\linewidth}{1mm}}
% If this boolean key is absent of the title command, this will return
% false. If it is only present, it will return true. Any
% value other than 'true' or 'false' is non accepted and will make the
% compilation crash.
\if@wgetdoc@title@ownpage
\begin{titlepage}
\begin{center}
\@wgetdoc@title@hrule%
\vspace{0.4cm}
% We always need to define \par in scope for a font size
% change, otherwise, if the title is ever longer than a
% line, it will wrap to the next line with huge characters
% on a normal baseline.
{\Huge\textbf{\@wgetdoc@title@maintitle}\par}%
\vspace{0.4cm}%
\@wgetdoc@title@hrule
\@ifundefined{@wgetdoc@title@subtitle}{}{
\vspace{1.5cm}
{\Large{\@wgetdoc@title@subtitle}\par}%
}
\@ifundefined{@wgetdoc@title@author}{}{
% Adds vertical space which will not be suppressed at the
% beginning or end of a page. Text following that statement
% will be at the bottom of the page.
\vspace*{\fill}
{\emph{Author: \@wgetdoc@title@author}\par}%
}
\end{center}
\end{titlepage}%
\else
\begin{center}
{\huge\textbf{\@wgetdoc@title@maintitle}\par}
\@ifundefined{@wgetdoc@title@subtitle}{}{
{\large{\@wgetdoc@title@subtitle}\par}%
}
\end{center}
\@ifundefined{@wgetdoc@title@author}{}{
{\emph{Author: \@wgetdoc@title@author}\par}%
}
\@wgetdoc@title@hrule%
\fi
}{
}
}
\usepackage{fancyhdr}
\newcommand{\@wgetdoc@header@centervalue}{}
\fancypagestyle{plain}{
\fancyhf{}
\@ifundefined{@wgetdoc@title@subtitle}{}{
\renewcommand{\@wgetdoc@header@centervalue}{\@wgetdoc@title@subtitle}
}
\fancyhead[C]{\@wgetdoc@header@centervalue}
}
\pagestyle{plain}
\usepackage{lipsum}
\makeatother
\begin{document}
\title[maintitle=Some title,
subtitle=\textsc{some sub},
author=This is me,ownpage=true]
\chapter{My chapter name}
\section{My section name}
\lipsum[4-57]
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment