我正在尝试编写一个基于 article.cls 的类,但在使用 \newcommand 时遇到了一些问题。以下是完整文件。
类文件
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{NITclsD}
[2013/09/06 v1.4h Standard LaTeX document class]
\newcommand\@ptsize{}
\newif\if@restonecol %sem muito sentido pois é single column
\newif\if@titlepage %tb não tem folha para titulo
\@titlepagefalse
\if@compatibility\else
\DeclareOption{a4paper}
{\setlength\paperheight {297mm}%
\setlength\paperwidth {210mm}}
\DeclareOption{a5paper}
{\setlength\paperheight {210mm}%
\setlength\paperwidth {148mm}}
\DeclareOption{letterpaper}
{\setlength\paperheight {11in}%
\setlength\paperwidth {8.5in}}
\DeclareOption{landscape}
{\setlength\@tempdima {\paperheight}%
\setlength\paperheight {\paperwidth}%
\setlength\paperwidth {\@tempdima}}
\fi
\if@compatibility
\renewcommand\@ptsize{0}
\else
\DeclareOption{10pt}{\renewcommand\@ptsize{0}}
\fi
\DeclareOption{11pt}{\renewcommand\@ptsize{1}}
\DeclareOption{12pt}{\renewcommand\@ptsize{2}}
\if@compatibility\else
\DeclareOption{oneside}{\@twosidefalse \@mparswitchfalse}
\fi
\DeclareOption{twoside}{\@twosidetrue \@mparswitchtrue}
\DeclareOption{draft}{\setlength\overfullrule{5pt}}
\if@compatibility\else
\DeclareOption{final}{\setlength\overfullrule{0pt}}
\fi
\if@compatibility\else
\DeclareOption{onecolumn}{\@twocolumnfalse}
\fi
\DeclareOption{twocolumn}{\@twocolumntrue}
\DeclareOption{leqno}{\input{leqno.clo}}
\DeclareOption{fleqn}{\input{fleqn.clo}}
\DeclareOption{openbib}{%
\AtEndOfPackage{%
\renewcommand\@openbib@code{%
\advance\leftmargin\bibindent
\itemindent -\bibindent
\listparindent \itemindent
\parsep \z@
}%
\renewcommand\newblock{\par}}%
}
\ExecuteOptions{a4paper,10pt,oneside,onecolumn,final} %mudei o tamanho da folha
\ProcessOptions
%______________________________________________________Inserindo os packages
\RequirePackage[english,brazil]{babel}
\RequirePackage[utf8]{inputenc} % Codificacao do arquivo
\RequirePackage{cmap} % Mapear caracteres especiais no PDF
\RequirePackage[T1]{fontenc} % Codificacao da fonte
\RequirePackage{amsmath,amssymb,amsfonts,textcomp}
\RequirePackage{setspace}
\RequirePackage{lastpage}
\RequirePackage{parskip}
%.............................Layout...........................
\RequirePackage[top=3 cm, bottom=3.3 cm, left=1.5 cm, right=1.5 cm, footskip=0.5 cm]{geometry}
%........................Figuras................................
\RequirePackage[]{graphicx} % Para incluir figuras (pacote extendido)
\RequirePackage{color} % Suporte a cores
\graphicspath{{Figuras/}}
\RequirePackage{caption}
\RequirePackage{multicol}
%...........................Tabelas...............................
\RequirePackage{array} % Elementos extras para formata\c c\~ao de tabelas
\RequirePackage{booktabs} % Tabelas com qualidade de publica\c c\~ao
\RequirePackage{longtable} % Para criar tabelas maiores que uma p\'agina
\RequirePackage{lscape} % adicionar tabelas e figuras como landscape
\RequirePackage{multirow}
%============================Cabeçalho e rodapé ===================
\RequirePackage{fancyhdr}
\LoadClass[a4paper]{article}
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\if@twoside
\def\ps@headings{%
\let\@oddfoot\@empty\let\@evenfoot\@empty
\def\@evenhead{\thepage\hfil\slshape\leftmark}%
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\markboth
\def\sectionmark##1{%
\markboth {\MakeUppercase{%
\ifnum \c@secnumdepth >\z@
\thesection\quad
\fi
##1}}{}}%
\def\subsectionmark##1{%
\markright {%
\ifnum \c@secnumdepth >\@ne
\thesubsection\quad
\fi
##1}}}
\else
\def\ps@headings{%
\let\@oddfoot\@empty
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\markboth
\def\sectionmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\thesection\quad
\fi
##1}}}}
\fi
\def\ps@myheadings{%
\let\@oddfoot\@empty\let\@evenfoot\@empty
\def\@evenhead{\thepage\hfil\slshape\leftmark}%
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\@gobbletwo
\let\sectionmark\@gobble
\let\subsectionmark\@gobble
}
%---------------------------------------------------------------
\if@titlepage
\newcommand\maketitle{\begin{titlepage}%
\let \footnote \thanks
\null\vfil
\vskip 60\p@
\begin{center}%
{\LARGE \@title \par}%
\vskip 3em%
{\large
\lineskip .75em%
\begin{tabular}[t]{c}%
\@author
\end{tabular}\par}%
\vskip 1.5em%
{\large \@date \par}% % Set date in \large size.
\end{center}\par
\@thanks
\vfil\null
\end{titlepage}%
}
\else
\newcommand\maketitle{\par
\begingroup
\renewcommand\thefootnote{\@fnsymbol\c@footnote}%
\def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
\long\def\@makefntext##1{\parindent 1em\noindent
\hb@[email protected]{%
\hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
\if@twocolumn
\ifnum \col@number=\@ne
\@maketitle
\else
\twocolumn[\@maketitle]%
\fi
\else
\newpage
\global\@topnum\z@ % Prevents figures from going at top of page.
\@maketitle
\fi
\thispagestyle{plain}\@thanks
\endgroup
\setcounter{footnote}{0}%
\setcounter{secnumdepth}{3}
\if@twocolumn
\setlength\leftmargini {2em}
\else
\setlength\leftmargini {2.5em}
\fi
\leftmargin \leftmargini
\setlength\leftmarginii {2.2em}
\setlength\leftmarginiii {1.87em}
\setlength\leftmarginiv {1.7em}
\if@twocolumn
\setlength\leftmarginv {.5em}
\setlength\leftmarginvi {.5em}
\else
\setlength\leftmarginv {1em}
\setlength\leftmarginvi {1em}
\fi
\setlength \labelsep {.5em}
\setlength \labelwidth{\leftmargini}
\addtolength\labelwidth{-\labelsep}
\@beginparpenalty -\@lowpenalty
\@endparpenalty -\@lowpenalty
\@itempenalty -\@lowpenalty
\setlength\arraycolsep{5\p@}
\setlength\tabcolsep{6\p@}
\setlength\arrayrulewidth{.4\p@}
\setlength\doublerulesep{2\p@}
\setlength\tabbingsep{\labelsep}
\skip\@mpfootins = \skip\footins
\setlength\fboxsep{3\p@}
\setlength\fboxrule{.4\p@}
\renewcommand \theequation {\@arabic\c@equation}
\renewcommand \thefigure {\@arabic\c@figure}
\def\fps@figure{tbp}
\def\ftype@figure{1}
\def\ext@figure{lof}
\def\fnum@figure{\figurename\nobreakspace\thefigure}
\def\fps@table{tbp}
\def\ftype@table{2}
\def\ext@table{lot}
\long\def\@makecaption#1#2{%
\vskip\abovecaptionskip
\sbox\@tempboxa{#1: #2}%
\ifdim \wd\@tempboxa >\hsize
#1: #2\par
\else
\global \@minipagefalse
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
\fi
\vskip\belowcaptionskip}
\DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm}
\DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf}
\DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt}
\DeclareOldFontCommand{\bf}{\normalfont\bfseries}{\mathbf}
\DeclareOldFontCommand{\it}{\normalfont\itshape}{\mathit}
\DeclareOldFontCommand{\sl}{\normalfont\slshape}{\@nomath\sl}
\DeclareOldFontCommand{\sc}{\normalfont\scshape}{\@nomath\sc}
\DeclareRobustCommand*\cal{\@fontswitch\relax\mathcal}
\DeclareRobustCommand*\mit{\@fontswitch\relax\mathnormal}
\setcounter{tocdepth}{3}
\let\l@table\l@figure
\newdimen\bibindent
\setlength\bibindent{1.5em}
\let\@openbib@code\@empty
\renewcommand\footnoterule{%
\kern-3\p@
\hrule\@width.4\columnwidth
\kern2.6\p@}
%++++++++++++++++++++++++++++++++++++++++Definindo meus comandos
% Definindo tamanho de fonte de se\c c\~oes e subse\c c\ões
%v. documento www.latex-project.org/guides/fntguide.pdf
\titleformat{\section}{\normalfont\small\bfseries\uppercase}{\thesection}{1em}{}
\titleformat{\subsection}{\normalfont\small\bfseries}{\thesubsection}{1em}{}
\titleformat*{\subsubsection}{\normalfont\small\bfseries}
\titlespacing*{\section}{0pt}{18pt}{10pt}[1pc] %espa\c cos para os titulos
%----------------------------------------------Comandos necessarios para o documento
\newcommand*{\@divisao}{}
\newcommand*{\divisao}[1]{\renewcommand*{\@divisao}{#1}}
\newcommand*{\@nonorma}{}
\newcommand*{\nonorma}[1]{\renewcommand*{\@nonorma}{#1}}
\newcommand*{\@dataaprov}{}
\newcommand*{\dataaprov}[1]{\renewcommand*{\@dataaprov}{#1}}
\newcommand*{\@nrevisao}{}
\newcommand*{\nrevisao}[1]{\renewcommand*{\@nrevisao}{#1}}
\newcommand*{\@titulonit}{}
\newcommand*{\titulonit}[1]{\renewcommand*{\@titulonit}{#1}}
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\def\today{\ifcase\month\or
January\or February\or March\or April\or May\or June\or
July\or August\or September\or October\or November\or December\fi
\space\number\day, \number\year}
\setlength\columnsep{10\p@}
\setlength\columnseprule{0\p@}
\pagestyle{plain}
\pagenumbering{arabic}
\if@twoside
\else
\raggedbottom
\fi
\if@twocolumn
\twocolumn
\sloppy
\flushbottom
\else
\onecolumn
\fi
\endinput
%
% End of file `NITclsD.cls'.
tex 文件(我想将所有这些“usepackages”放在 .cls 文件中),
\documentclass{NITclsD}
\usepackage{enumitem} % Cria listas numeradas
\usepackage[compact]{titlesec} % Formato dos titulos
\usepackage{subfig} % Criar figura dividida em subfiguras
\usepackage{natbib} % Bibliografia
%---------------------------------------------------
\begin{document}
\divisao{DIVISAO}
\nonorma{001} %tres digitos
\dataaprov{08/2013} % formato MM/AAAA
\nrevisao{00} %dois digitos
\titulonit{T\'ITULO}
%:::::::::::::::::::::::
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.4pt}
%%redefinindo o espa\c camento entre linhas do sum\'ario: sem espa\c co
\newcommand*{\noaddvspace}{\renewcommand*{\addvspace}[1]{}}
\addtocontents{toc}{\protect\noaddvspace}
%
\renewcommand*\contentsname{SUM\'ARIO}
%
\small\tableofcontents
\vspace{1em}
%-----------------testezinho
\addtocontents{toc}{\addvspace{10pt}}
%
\section{Objetivo}
\label{1}
%
%Here comes the text.
\bibliography{referencias}
\end{document}
我仍有一些与原始 article.cls 相关的错误,但我想消除与 \newcommand 相关的“未定义的控制序列”。我该如何修复它?
答案1
在我看来,你首先定义了很多通常在 中定义的东西article.cls
,例如\@ptsize
,然后你\LoadClass{article}
。我得到的是LaTeX Error: Command \@ptsize already defined
,我认为这是合理的。
我同意@egreg的观点,你的类写得很糟糕。你可能需要参考egacmconf.cls
来了解如何article.cls
在类中进行自定义。