# Problem with making a custom class

I am trying to make a custom class file for a SOP. I think I am running into issues when using fancyhdr package but I'm not sure why.

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sop}[10/10/2014 article class for standard operating procedures]

% Passes and class options to the underlying article class
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions

% Redefine the page margins
\RequirePackage[left=1in,right=1in,top=.75in,bottom=.75in]{geometry}

% Modifications to the section titles
\renewcommand*\thesection{\arabic{section}.0}
\renewcommand*\thesubsection{\arabic{section}.\arabic{subsection}}
\renewcommand*\thesubsubsection{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}}

% Modification of title block
\RequirePackage{titling}
\newcommand{\sopchaptertitle}[1]{\def\@sopchaptertitle{#1}}
\newcommand{\sopchapternumber}[1]{\def\@sopchapternumber{#1}}

%%% Drop before title
\setlength\droptitle{12cm}

%%% Define the internal variable \@title to be the supplied data
\renewcommand\maketitlehooka{%
\def\@title{\@sopchaptertitle\ \@sopchapternumber}}

%%% No author field, so \maketitlehookb gobbles what comes after it
\renewcommand\maketitlehookb[1]{}

%%% No date field, so \maketitlehookc gobbles what comes after it
\renewcommand\maketitlehookc[1]{}

%%% Formatting the title
\pretitle{\centering\sffamily\LARGE}

%%% Space after the title
\posttitle{\par\vspace{3cm}}

%%% The rest of the class

% For "Page N of M" and header/footer constructioe
\RequirePackage{lastpage}

% For easier construction of page headers/footers
\RequirePackage{fancyhdr}
\newcommand{\revision}[1]{\def\@revision{#1}}
\newcommand{\revisionMMYY}[1]{\def\@revisionMMYY{#1}}
\newcommand{\tcn}[1]{\def\@tcn{#1}}

\fancypagestyle{plain}{ % for first page
\fancyhf{}
SOP- \thesopchapternumber \ Page \thepage{} of \pageref*{LastPage}
}

\fancyfoot[R]{%
REV \therevision,\ \therevisionMMYY
}
\renewcommand{\footrulewidth}{0pt}
}

\pagestyle{fancy} % for other pages
\fancyhf{}
SOP-\thesopchapternumber \ Page \thepage{} of \pageref*{LastPage}
}

\fancyfoot[R]{%
REV \therevision,\ \therevisionMMYY
}
\renewcommand{\footrulewidth}{0pt}

% For easier customization of itemized, enumerated, and other lists
\RequirePackage{enumitem}
\RequirePackage{hyperref}
% Ensure first page is correct style
\RequirePackage{appendix}
\RequirePackage{makebox}
\RequirePackage{nextpage}
\thispagestyle{plain}

\endinput

Here is a basic Tex file I'm trying to compile with it just to try and get it to work.

\documentclass[10pt]{sop}
%
% SOP Standard Form Data
\sopchaptertitle{john doe PROCEDURE}
\sopchapternumber{D.1}

\date{11/13/14}
\author{johndoe}
%...more of the above
%Here begins the actual document
\begin{document}

\maketitle

\section{Main Title}

\section{Approval}
Approval1....\makebox[1.5in]{\hrulefill}\\\vspace{1.5in}
Approval2....\makebox[1.5in]{\hrulefill}

\newpage

\section{Purpose and Discussion}
%...more of the above...
\end{document}

edit: Here is my log file. https://www.dropbox.com/s/qebydr5p1xt9ozq/text.log?dl=0

• Could you describe the "issues"? – Werner Nov 13 '14 at 21:07
• 10/10/2014 should be 2014/10/10 – David Carlisle Nov 13 '14 at 21:09
• Related: Template for Standard Operating Procedures? (apparently the class code started from my answer there -- didn't notice at first). – Mike Renfro Nov 13 '14 at 21:42
• \thesopchapternumber is not defined. If you want to use it like this, sopchapternumber needs to be a counter defined with \newcounter. Similarly for \therevision etc. They all need to be counters if you plan to access them this way. Not the problem, but consider using the updated alternative for lastpage. You'll see warnings about the use of lastpage in your compilation output, with recommendations for updating. – cfr Nov 13 '14 at 22:26
• \fancyhead[R]{% SOP- \@sopchapternumber \ Page \thepage{} of \pageref*{LastPage} }. Use the @versions you are defing when using \sopchapternumber{my number}. The \the construct doesn't work here (it doesen't in the linked answer as well <-- @mikerenfro) – Johannes_B Nov 16 '14 at 15:45

There were several things to fix in your MWE:

1. In the main document, you omitted \revision and \revisionMMYY commands. Your class file has no default values for these, so they cause errors when referenced.

2. You misunderstand the use of \thesomething constructs sometimes found in class or package code. Most of the time, these are used to print the formatted value of counters defined with the \newcounter{} command (see the LaTeX Wikibook: Counters). As @cfr mentioned, if you had used \newcounter{sopchapternumber}, then macros including \thesopchapternumber, \value{sopchapternumber}, \arabic{sopchapternumber}, etc. become available. In my previous example, the titling package also added \thetitle and \theauthor commands that aren't counters, but these are exceptions to the rule, and were explicitly added by the package code.

Additionally, if these SOPs are chapter-based, I'd consider basing the class off of book or report where chapters are built in, instead of article.

Corrected MWE:

\documentclass[10pt]{sop}
\sopchaptertitle{john doe PROCEDURE}
\sopchapternumber{D.1}
\revision{Some Revision}
\revisionMMYY{Some Month, Some Year}
\date{11/13/14}
\author{johndoe}
\begin{document}
\maketitle
\section{Main Title}
\section{Approval}
Approval1....\makebox[1.5in]{\hrulefill}\\\vspace{1.5in}
Approval2....\makebox[1.5in]{\hrulefill}
\newpage
\section{Purpose and Discussion}
\end{document}

Class:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sop}[2014/10/10 article class for standard operating procedures]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions

% Redefine the page margins
\RequirePackage[left=1in,right=1in,top=.75in,bottom=.75in]{geometry}

% Modifications to the section titles
\renewcommand*\thesection{\arabic{section}.0}
\renewcommand*\thesubsection{\arabic{section}.\arabic{subsection}}
\renewcommand*\thesubsubsection{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}}

% Modification of title block
\RequirePackage{titling}
\newcommand{\sopchaptertitle}[1]{\def\@sopchaptertitle{#1}}
\newcommand{\sopchapternumber}[1]{\def\@sopchapternumber{#1}}

%%% Drop before title
\setlength\droptitle{12cm}

%%% Define the internal variable \@title to be the supplied data
\renewcommand\maketitlehooka{%
\def\@title{\@sopchaptertitle\ \@sopchapternumber}}

%%% No author field, so \maketitlehookb gobbles what comes after it
\renewcommand\maketitlehookb[1]{}

%%% No date field, so \maketitlehookc gobbles what comes after it
\renewcommand\maketitlehookc[1]{}

%%% Formatting the title
\pretitle{\centering\sffamily\LARGE}

%%% Space after the title
\posttitle{\par\vspace{3cm}}

%%% The rest of the class

% For "Page N of M" and header/footer constructioe
\RequirePackage{lastpage}

% For easier construction of page headers/footers
\RequirePackage{fancyhdr}
\newcommand{\revision}[1]{\def\@revision{#1}}
\newcommand{\revisionMMYY}[1]{\def\@revisionMMYY{#1}}
\newcommand{\tcn}[1]{\def\@tcn{#1}}

\fancypagestyle{plain}{ % for first page
\fancyhf{}
SOP- \@sopchapternumber \ Page \thepage{} of \pageref*{LastPage}
}

\fancyfoot[R]{%
REV \@revision{},\ \@revisionMMYY
}
\renewcommand{\footrulewidth}{0pt}
}

\pagestyle{fancy} % for other pages
\fancyhf{}
SOP-\@sopchapternumber \ Page \thepage{} of \pageref*{LastPage}
}

\fancyfoot[R]{%
REV \@revision{},\ \@revisionMMYY
}
\renewcommand{\footrulewidth}{0pt}

% For easier customization of itemized, enumerated, and other lists
\RequirePackage{enumitem}