为什么我的变量被删除了?

为什么我的变量被删除了?

我正在制作一个自定义文档类,我注意到我的自定义变量在标题页上排版后,不知何故被重置为空。它们显示在标题页上,但我的页眉不起作用。

别在意作业部分了——我还没改。它应该是讲座。

在此处输入图片描述

这是我制作这个简单文档的代码:

\documentclass{notes}

\coursenumber{Course 101}
\semester{Winter 2013}
\lecture{1}
\studentname{My Name}
\studentid{My ID}

\begin{document}
    \maketitle

    asdf
\end{document}

这是我的 notes.cls 文件:

\ProvidesClass{notes}

\LoadClass[10pt,letterpaper]{article}

\RequirePackage{ifthen}
\RequirePackage[left=1.25in,right=1.25in,top=1.25in,bottom=1.25in]{geometry}
\RequirePackage{setspace}
\RequirePackage{amsmath}
\RequirePackage{titling}
\RequirePackage{fancyhdr}
\RequirePackage{amsfonts}

\newcommand{\@coursenumber}{{\em No \textbackslash coursenumber specified}}
\newcommand{\@semester}{{\em No \textbackslash semester specified}}
\newcommand{\@studentname}{{\em \textbackslash studentname unknown}}
\newcommand{\@studentid}{{\em \textbackslash studentid unknown}}
\newcommand{\@school}{{\em \textbackslash school unknown}}
\newcommand{\@department}{{\em \textbackslash department unknown}}
\newcommand{\@lecture}{\textbackslash lecture}
\newcommand{\solutionstext}{\bfseries (Solutions)}
\newcommand{\coursenumber}[1]{\renewcommand{\@coursenumber}{#1}}
\newcommand{\semester}[1]{\renewcommand{\@semester}{#1}}
\newcommand{\studentname}[1]{\renewcommand{\@studentname}{#1}}
\newcommand{\studentid}[1]{\renewcommand{\@studentid}{#1}}
\newcommand{\school}[1]{\renewcommand{\@school}{#1}}
\newcommand{\department}[1]{\renewcommand{\@department}{#1}}
\newcommand{\lecture}[1]{\renewcommand{\@lecture}{#1}}

\renewcommand{\maketitle}{
  \begin{titlepage}
    \newcommand{\HRule}{\rule{\linewidth}{0.5mm}} % Defines a new command for the horizontal lines, change thickness here
    \center
    \leavevmode\\[4cm] % Center everything on the page
    \HRule \\[0.4cm]
    { \huge \bfseries \@coursenumber}\\[0.0cm] % Title of your document
    \HRule \\[1.5cm]
    \textsc{\Large \@semester}\\[0.5cm] % Semester
    \textsc{\Large \today}\\[0.5cm] % Date
    \textsc{\Large Lecture \#\@lecture}\\[1.0cm] % Lecture
    \HRule \\[1.0cm]
    \Large \emph{Author:} \\ \@studentname \\ 
    \@studentid \\[3cm]
    \vfill % Fill the rest of the page with whitespace
  \end{titlepage}
}

\makeatletter
% These commands follow the titling package format for titles
% They define user commands to format the subtitle
\newcommand\presubtitle[1]{\gdef\@presubtitle{#1}}
\newcommand\postsubtitle[1]{\gdef\@postsubtitle{#1}}
% This command takes the subtitle as its argument, and uses the titling command
% \maketitlehookb plus the previously defined formatting commands to insert
% the subtitle into the titlepage. It also generates \thesubtitle for subsequent use
\newcommand\subtitle[1]{%
  \renewcommand{\maketitlehookb}{\@presubtitle#1\@postsubtitle}
  \newcommand\thesubtitle{#1}}
\makeatother
% Now we define the formatting for the subtitle
\presubtitle{\begin{center}\Large} % change this as needed
\postsubtitle{\end{center}}

% These commands set up the headers. They are set up for even and odd pages the same
% Check the fancyhdr documentation for information on how to set them differently
% for odd and even pages
\lhead{\begin{tabular}{@{}l}\@coursenumber\ (\@semester)\\\@studentname\ (\@studentid)\end{tabular}}
\chead{}
\rhead{\begin{tabular}{r@{}}Assignment \#\@assignment\\\today\end{tabular}}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
% Set the width of the header rule. Make 0pt to remove the rule.
\renewcommand{\headrulewidth}{.5pt}
\renewcommand{\footrulewidth}{0pt}
% Make the head height match the size of the header
\setlength{\headheight}{24pt}
\pagestyle{fancy}
% Remove "Chapter" from the marks
%\renewcommand{\chaptermark}[1]{%
%  \markboth{\thechapter.\ #1}{}}

答案1

\makeatletter虽然在样式 ( .sty) 或类 ( .cls) 文件中使用是无害的,但\makeatother会不必要地将的类别代码更改@为其他 (12)(请参阅类别代码是什么?),这导致后续在控制序列中使用@会出现问题。因此,删除 (对\makeatletterand) \makeatother

作为参考,请参阅在包或类文件中使用\makeatletter和真的很糟糕吗?\makeatother

相关内容