我正在为我的教职员工开发一个自定义文档类。创建首页时,我想添加一些自定义变量。例如标题、作者、主管等。我可以在单个文档中完成这些操作,但在创建自定义类时却无法完成。
这是我的自定义类代码:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{iseg-general}[General template for written work at ISEG]
\LoadClass [12pt,a4paper,oneside]{article}
% Set font type to 'Times New Roman'.
\usepackage{times}
% Portuguese accents just in case.
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[style=authoryear,backend=biber]{biblatex}
\addbibresource{bibliography.bib}% Syntax for version >= 1.2
% English language.
\usepackage[english]{babel}
% appendix
\usepackage[titletoc,toc,title]{appendix}
\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
\makeatletter
\def\@biblabel#1{\hspace*{-\labelsep}}
\makeatother
% Set margins to 3cm.
\usepackage[top=3cm, bottom=3cm, left=3cm, right=3cm]{geometry}
% Change margins command.
\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist
% Paragraph indentation.
\usepackage{indentfirst}
% Set vertical spacing to 1.5 lines.
\usepackage{setspace}
\onehalfspacing
\makeatletter
% Page headers and footers customisation.
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
% Set left header to footnotesize (10pt) and upper cases.
\lhead{\textsf{\scriptsize \textsc{\@author}}}
% Set left header to footnotesize (10pt) and upper cases.
\rhead{\textsf{\scriptsize \textsc{\@title}}}
% Set centred footer to page number.
\cfoot{\thepage}
\makeatother
% Customise chapters, sections, subsections, and subsubsections.
\usepackage{titlesec}
% Set chapters' titles to upper cases and centred.
\titleformat{\chapter}[display]
{\scshape\center}
{}
{0pt}
{\thechapter.\ }
\usepackage{etoolbox}% Stop chapters from starting at new page.
\makeatletter
\patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}
\makeatother
% Set sections' titles to upper cases and centred.
\titleformat{\section}
{\scshape\center}{\thesection}{1em}{}
% Set subsections' titles to italic and centred.
\titleformat{\subsection}
{\itshape\center}{\thesubsection}{1em}{}
% Idem for subsubsections' titles.
\titleformat{\subsubsection}
{\itshape\center}{\thesubsection}{1em}{}
% Link objects (e.g. tables, figures, pages) in the body of text.
\usepackage{hyperref}
% Build a glossary.
%\usepackage{glossaries}
%\makeglossaries
% Define, e.g. acronyms (\newacronym{<label>}{<abbrv>}{<full>}).
% Use \gls{<label>} command to call the acronym in the text. On first use the \gls command will display "<full> (<abbrv>)". On subsequent uses only the abbreviation will be displayed.
% Customize table of contents.
\usepackage{tocloft}
\setlength{\cftbeforetoctitleskip}{0pt}
% \addto\captionsenglish{%
% \renewcommand{\contentsname}{\hfill\normalfont\scshape\normalsize Table of Contents\hfill}
%\renewcommand{\cftaftertoctitle}{\hfill}
% }
%\addto\captionsenglish{%
% \renewcommand{\contentsname}%
% {\scshape Table of Contents}%
%}
\setlength{\cftbeforeloftitleskip}{0pt}
\setlength{\cftbeforelottitleskip}{0pt}
%Customise tables.
\renewcommand*\thetable{\Roman{table}}% Roman Numerals Tables
\addto\captionsenglish{\renewcommand{\tablename}{\textsc{Table}}}% Full Caps Tables
\addto\captionsenglish{\renewcommand{\figurename}{\textsc{Figure}}}% Full Caps Figures
%%%%%%%%%%%Tables
\usepackage{booktabs}
\usepackage{adjustbox}
\setlength\heavyrulewidth{0.3ex}
\usepackage{tabularx}
\usepackage{array}
\usepackage{threeparttable}
%Quotes
\usepackage{csquotes}
\renewcommand*{\maketitle}{%
\begin{titlepage}
\pagestyle{empty}
\centering
\begin{flushleft}
\includegraphics[width=0.3\linewidth]{graphics/Logotipo_ISEG.png}
\end{flushleft}
\vspace{3cm}
{\textsf{\Large Macroeconomics}} \\ [1cm]
{\textsf{\Large 2018/2020}} \\ [3cm]
{\textsf{\Large \@title }} \\ [2cm] % <- delete the irrelevant parts
\begin{flushleft}
{\uppercase{\Large \@title }} \\ [1.5cm] % <- write here the title of your thesis
{\uppercase{\Large \@author }} \\ [2cm]% <- write here the title of your thesis
\end{flushleft}
\textsf{
\underline{Author:} \\
\@author}
\vfill
%Date
{\textsf{\Large ISEG, 29th December 2018}} % <- write here the date
\clearpage
\end{titlepage}
}
在 \begin{titlepage} 范围内,我希望能够打印我的自定义变量,并使其中一些具有条件,例如,如果未定义某些变量,TeX 不应抛出任何错误。