% \iffalse
% Title pages for Navy technical reports.
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is file `navydocs.dtx', the documentation file for the `navydocs'
% package.
%
% Copyright (C) 2016 Peter Andrew Rochford.
%
% The navydocs package may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, version 1.3c
% (LPPL, 2008-05-04) of this license or (at your option) any later version. 
% The latest version of this license can be found at:
%     https://latex-project.org/lppl/
%
% The navydocs package is distributed in the hope that it will be
% useful, but `as is', WITHOUT WARRANTY OF ANY KIND, either expressed 
% or implied, including, but not limited to, the implied warranties of
% MERCHANTABILITY and FITNESS FOR A PARTICULAR PURPOSE.  See the LaTeX
% Project Public License for more details.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% @LaTeX-style-file{
%    Author     = "Peter A. Rochford",
%    Version    = "1.1",
%    Date       = "2017/7/1",
%    Time       = "22:51:25",
%    Filename   = "navydocs.sty",
%    Address    = "Acorn Science & Innovation, Inc.
%                      1616 Anderson Road, Suite 213
%                      McLean, VA 22102, USA",
%    Telephone  = "+1 703-995-9872",
%    Email      = "prochford@acornsi.com",
%    CodeTable  = "ISO/ASCII",
%    Keywords   = "LaTeX, standard forms, navydocs, report documentation",
%    Supported  = "yes",
%    Abstract   = "LaTeX package for generating title pages and other leading
%                  pages as prescribed for Navy technical reports, for instance,
%                  as part of a document delivered on a U.S. Government
%                  contract.''
% }
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{navydocs.dtx}
\documentclass[letterpaper]{ltxdoc}
\usepackage{navydocs}
\usepackage{afterpage}
\advance\textheight2\baselineskip
\setlength\hfuzz{26pt}
\newcounter{savepage}
%</driver>
%
%<*ltxdoc>
\AtBeginDocument{
  \EnableCrossrefs
  \RecordChanges
  \CodelineIndex}
\AtEndDocument{
  \PrintChanges
  \PrintIndex}
\begin{document}
  \DocInput{navydocs.dtx}
\end{document}
%</ltxdoc>
%
% \fi
%
% \newcommand*{\Lopt}[1]{\textsf{#1}}
% \newcommand*{\Lfile}[1]{\texttt{#1}}
% \newcommand*{\Lpack}[1]{\textsf{#1}}
%
% \changes{v1.0}{11 Jan 2000}{Initial revision.}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \DoNotIndex{\ ,\(,\),\@car,\@date,\@empty,\@gobble,\@ifnextchar}
% \DoNotIndex{\@ifundefined,\@nil,\@tempa,\@tempboxa,\@tempskipa}
% \DoNotIndex{\@viiipt,\@vpt,\@vipt,\@xipt,\@xivpt,\@warning,\@xpt,\\}
% \DoNotIndex{\2,\AtEndDocument,\addtocounter,\advance,\arabic}
% \DoNotIndex{\baselineskip,\baselinestretch,\begin,\bf,\c@page}
% \DoNotIndex{\cleardoublepage,\csname,\date,\day,\DeclareFixedFont}
% \DoNotIndex{\def,\documentclass,\documentpackage,\edef,\else,\end}
% \DoNotIndex{\endcsname,\evensidemargin,\ExecuteOptions,\expandafter}
% \DoNotIndex{\fi,\font,\fontdimen,\footnote,\framebox,\global,\hbox}
% \DoNotIndex{\headheight,\headsep,\hrule,\hskip,\hss,\if,\if@twoside}
% \DoNotIndex{\ifdim,\IfFileExists,\ifodd,\ifx,\InputIfFileExists,\LARGE}
% \DoNotIndex{\large,\leftskip,\let,\line,\lineskip,\linethickness}
% \DoNotIndex{\linewidth,\makeatletter,\makeatother,\makebox,\maketitle}
% \DoNotIndex{\month,\NeedsTeXFormat,\newcommand,\newcounter,\newif}
% \DoNotIndex{\newpage,\noindent,\normalbaselineskip,\null,\number}
% \DoNotIndex{\oddsidemargin,\pagenumbering,\pagestyle,\par,\parbox,\phantom}
% \DoNotIndex{\ProvidesPackage,\put,\r@TotPages,\raggedright,\relax}
% \DoNotIndex{\renewcommand,\rightskip,\rule,\section,\setcounter}
% \DoNotIndex{\setbox,\setlength,\shortstack,\space,\spaceskip,\string}
% \DoNotIndex{\tableofcontents,\textheight,\textwidth,\thispagestyle}
% \DoNotIndex{\topmargin,\tt,\typeout,\unitlength,\usepackage,\value}
% \DoNotIndex{\vbox,\vfil,\voffset,\vskip,\vss,\wd,\xspaceskip,\year}
%
% \newcommand{\ie}{{\it i.e.\/}}
%
% \def\filename{navydocs.dtx}
% \def\fileversion{1.1}
% \def\filedate{2016/7/1}
% \def\docdate {2016/7/1}
% \makeatletter
%   \def\@oddfoot{%
%     \rm
%     \hfil
%     \@ifundefined{r@fig:form}%
%       {\thepage}%
%       {\@tempcnta\pageref{fig:form}
%        \ifnum \c@page=\@tempcnta \else
%          \thepage
%        \fi}%
%     \hfil}
%   \let\@evenfoot\@oddfoot
% \makeatother
%
% \CheckSum{0}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \title{The \Lpack{navydocs} Package\footnote{This paper documents
%        the \Lpack{navydocs} package v\fileversion, last revised \filedate.}}
% \author{
%         Peter Andrew Rochford\\[5pt]
%         Acorn Science \& Innovation, Inc. \\
%         1616 Anderson Road, Suite 213 \\
%         McLean, VA 22102, USA\\[5pt]
%         \texttt{prochford@acornsi.com}
%         }
% \date{\docdate}
% \maketitle
% \vspace{-20pt}
% \begin{abstract}
% \noindent
% This article documents the \LaTeX\ package for generating the title 
% page and other leading pages as prescribed for Navy technical reports.  
% For example, as part of a document delivered on a U.S. Government
% contract.
%
%\end{abstract}
% 
% \setcounter{tocdepth}{2}
% \tableofcontents
%
% \section{Introduction}
%
% The \Lpack{navydocs} package provides an easy means for 
% creating title pages and the following supplementary material pages used 
% in technical reports by United States Navy organizations. These pages are
% generated by specifying the page content via a set of commands and then 
% calling a macro to create the page at its occurence in the document. The 
% package in its current form provides a title page and a technical components 
% page as used by the Carderock Division at the Naval  Surface Warfare Center 
% (Carderock/NSWC). The macros provided within the package can be easily 
% copied and modified to support formats used by other Navy organizations. 
% The \Lpack{navydocs} package is provided in the hope that it proves 
% useful to other Navy organizations, with users contributing macros for their
% organizations. Please email to the author any new macros for title pages or
% supplementary material so they can be added to the \Lpack{navydocs} 
% package.
%
% In the current version of the \Lpack{navydocs} package, the macro
% \cmd{\NavyTitlePage} will produce a title page for a technical report
% released by Carderock/NSWC. The macro \cmd{\MakeCarderockDivPage}
% will create a Technical Components page that lists the major Carderock 
% Division technical components of the organization along with the three 
% types of reports issued by this division. This is typically inserted after the 
% title page.
%
% A sample of the Carderock/NSWC title and technical components pages 
% is given in section~\ref{sec:sample} for one example of how to use the 
% \Lpack{navydocs} package.
% 
% \section{The Individual Fields}
% 
% There are 10 fields for producing the title pages. The following macros, each 
% having a single argument, define the data to be included in each field.  Usually 
% only a few fields will apply to a given report.  Table~\ref{tab:attributes} notes which
% fields are required and which have default values. The best approach to insure that 
% the form is properly filled-in is to preview the page and adjust any
% fields that appear to have a problem. Note that in many cases you can use 
% ``|\\|'' (newline) to spread the text over several lines.
% 
% \begin{table}[h]
% \null\vspace{-.1in}
% \def\n{\hfill{\bf ---}\hfill\null}
% \def\d#1#2{\smash{\lower#1\hbox{#2}}}
% \def\p{\phantom{0}}
% \def\s#1{{\footnotesize (#1)}}
% \def\S#1{%
%   \ifnum#1<10
%     {\footnotesize \phantom{0}(#1)}%
%   \else
%     \s{#1}%
%   \fi}
% \doublerulesep.5pt
% \arrayrulewidth.5pt
% \caption{Field Attributes and Approximate Maximum Size.}
% \label{tab:attributes}
% \vspace{10pt}
% \DeleteShortVerb{\|}
% \hbox to \textwidth{%
% \begin{tabular}{lcccccc}
%   \hline\hline
%   \multicolumn{1}{c}{\rule{0pt}{14pt}\d{1ex}{\bf Macro Name}}
%                                                 & \multicolumn{1}{c}{\d{1ex}{\bf Required}}
%                                                       & \multicolumn{1}{l}{\bf Default}
%                                                             & \multicolumn{1}{c}{\bf Max}
%                                                                  & \multicolumn{1}{c}{{\bf Chars.}\d{-2.5pt}{\s{3}}}
%                                                                                         \\ 
%                                        &     & \multicolumn{1}{l}{{\bf Value}}
%                                                             & \multicolumn{1}{c}{\bf Lines}
%                                                                   & \multicolumn{1}{c}{\bf per Line}
%                                                                                         \\ \hline\rule{0pt}{14pt}
%   \cmd{\NavyDivision}               & Yes &\n& \p1 &  \p58  \\
%    \cmd{\NavyDivisionLocation}    & Yes & \n  & \p1 &  \p70  \\
%    \cmd{\NavyReportNumber}     & Yes & \n  & \p1 &  \p57  \\
%    \cmd{\NavyReportDate}          & \n & \s{1} & \p1 &  \p12  \\
%    \cmd{\NavyReportType}         & Yes  & \n  & \p2 &  \p75 \\
%    \cmd{\NavyReportTitle}          & Yes  & \n  & \p3 &  \p45 \\
%    \cmd{\NavyAuthor}               & Yes & \n  & \p19 &  \p75  \\
%   \cmd{\NavyDistributionStatement} & \n  &\s{2}& \p1 & \p55 \\
%    \cmd{\NavyMarginTitle}                   & \n  & \n  & \p2 &  \p85 \\ \hline\hline
%   \multicolumn{5}{l}{\rule{0pt}{14pt}{\bf Notes:}}                                \\
%   \multicolumn{5}{l}{\quad\S{1} Defaults to the current date in ``dd~Month~yyyy'' 
%                      format (\eg} \\
%   \multicolumn{5}{l}{\quad\phantom{\S{1}} 26~June~2016).}  \\
%   \multicolumn{5}{l}{\quad\S{2} Defaults to ``Approved for public release; 
%                      distribution is unlimited''}. \\
%   \multicolumn{5}{l}{\quad\S{3} The number of characters is approximate and for
%                      the Computer} \\
%   \multicolumn{5}{l}{\quad\phantom{\S{3}} Modern Roman font family only.}
% \end{tabular}%
% }
% \vspace{.1in}
% \MakeShortVerb{\|}
% \end{table}
%
% \newpage
% \paragraph{1. DIVISION}
% \DescribeMacro{\NavyDivision}
%
% \noindent
% The full specification of the Navy division producing the technical report as
% it should appear at the top of the title page, \eg Carderock Division, 
% Naval Surface Warface Center. This field is required.
%
% \paragraph{2. DIVISION LOCATION}
% \DescribeMacro{\NavyDivisionLocation}
%
% \noindent
% The city, state, and zip code of the Navy division producing the technical report
% as it should appear at the top of the title page, \eg West Bethesda, Maryland 
% 20817-5700. This field is required.
% 
% \paragraph{3. REPORT NUMBER}
% \DescribeMacro{\NavyReportNumber}
%
% \noindent
% Enter the unique alphanumeric report number(s) assigned by the Navy 
% performing organization, \eg
% \par\null\noindent
% \begin{tabular}{llll}
%   ~~ & \multicolumn{3}{l}{\tt \cmd{\POReportNumber}\{CRDKNSWC/HD-1427-02; 
%      AFWL-TR-85-4017-Vol21-PT-2\}} \\ 
%      & \hspace{1in} & $\rightarrow$ & BRL-1234; AFWL-TR-85-4017-Vol21-PT-2
% \end{tabular}
%
% \paragraph{4. REPORT DATE}
% \DescribeMacro{\NavyReportDate}
%
% \noindent
% Publication date , which is typically in the format of month and year, \eg
% October 1996.
%
% \paragraph{5. REPORT TYPE}
% \DescribeMacro{\NavyReportType}
%
% \noindent
% State the type of report as stipulated by the Navy organization. You can 
% use ``|\\|'' (newline) to specify the report type across multiple lines, such 
% as
%
% \cmd{\NavyReportType}\{Hydromechanics Directorate \\
%                     Research and Development Report \}
% 
% This field is required.
%
% \paragraph{6. REPORT TITLE}
% \DescribeMacro{\NavyReportTitle}
%
% \noindent
% The title for the report. This should be taken from the part of 
% the report that provides the most meaningful and complete information. 
% You can use ``|\\|'' (newline) to specify the report type across multiple 
% lines, such as
%
% \cmd{\NavyReportTitle}\{Mathematical Model for MANSIM Version 2:\\
%                                  A Surface Ship Maneuvering, Stationkeeping, \\
%                                  and Seakeeping Simulator Computer Program \}
% 
% On classified documents enter the title classification in parentheses. 
% This field is required.
% 
% \paragraph{7. AUTHOR(S)}
% \DescribeMacro{\NavyAuthor}
%
% \noindent
% Enter name(s) of the person(s) responsible for writing the report,
% performing the research, or credited with the content of the report.
% You can use ``|\\|'' (newline) to specify the report type across multiple 
% lines. If editor or compiler, this should follow the name(s).
%
% \paragraph{8. DISTRIBUTION/AVAILABILITY STATEMENT}
% \DescribeMacro{\NavyDistributionStatement}
%
% \noindent
% Use agency-mandated availability statements to indicated the public
% availability or distribution limitations of the report.  If additional
% limitations/restrictions or special markings are indicated follow
% agency authorization procedures, \eg, RD/FRD, PROPIN, ITAR.
% This field is {\bf not} required, but will default to the first of the following examples:
% \par\null\noindent
% ``Approved for public release; distribution is unlimited.''
% \par\null\noindent
% ``Distribution authorized to DoD only; (reason and date).  Other
% requests shall be referred to (controlling DoD office).''
% \par\null\noindent
% ``Further dissemination only as directed by (controlling DoD office
% and date) or higher DoD authority.''
% \par\null\noindent
% \hbox to \textwidth{%
%   \begin{tabular}{l@{\space---\space}l}
%     For DoD  & \parbox[t]{0.75\textwidth}{See DoDD 5230.24, 
%              ``Distribution Statements on Technical Documents.''}\\
%     For DoE  & See authorities.\\
%     For NASA & See Handbook NHB 2200.2.\\
%     For NTIS & Leave blank.
%   \end{tabular}%
%   \hss}
%
% \paragraph{9. MARGIN TITLE}
% \DescribeMacro{\NavyMarginTitle}
%
% \noindent
% Title to appear in the left margin of the title page, oriented in a vertical 
% position. The title is typically the same as that used with \cmd{\NavyReportTitle} 
% but may differ because the title has to be shortened due to space limitations or 
% line breaks. Hence a separate command is used to provide the title. 
%
% A margin title will only appear if this command is called with an argument. The title
% will appear in the margin according to the formatting commands provided for the
% title, for example using a``|\\|'' (newline) to have the title split across more than 
% one line or a \cmd{\hphantom} to control placement of text 
% (cf. Section~\ref{sec:sample}).
%
% \cmd{\NavyMarginTitle\{Title for margin\}}
%
% By default the margin title will be placed at the margin paragraph width and the 
% bottom of the text height area. To allow user control over the exact placement 
% of the margin title, the command accepts two optional arguments 
% (xmargin, ymargin) that define the horizontal (xmargin) and vertical (ymargin)
% position of the bottom left placement. 
%
% \cmd{\NavyMarginTitle[xmargin][ymargin]\{Title for margin\}}
%
% To provide guidance on suitable values for [xmargin][ymargin] , the default 
% values are [40][70], while the values used to place the margin title as it appears 
% in Section~\ref{sec:titlepage} are [140][95]. 
%
% \iffalse
% Save current page number because \titlepage sets it to 1 later. 
%\fi
% \setcounter{savepage}{\thepage}
% \section{Title Page}
% \label{sec:titlepage}
% 
% The macro \cmd{\NavyTitlePage} will produce a title page for the Navy
% technical report on a separate page at the location where it appears. This will 
% produce the title page as shown on the following page.
%
% \NavyDivision{Division, Center}
% \NavyDivisionLocation{City, State Zip Code}
% \NavyReportNumber{Report No.}
% \NavyReportDate{Month Year}
% \NavyReportType{Directorate \\
%                     Research and Development Report}
% \NavyReportTitle{Report Title}
% \NavyAuthor{Author}
% \NavyMarginTitle{Report Title for margin}
%
% \newpage
% \NavyMarginTitle[140][95]{\NavyReportNumber{} Report Title}
% \NavyTitlePage
%
% \iffalse
% Reset page number because \titlepage sets it to 1. 
%\fi
% \setcounter{page}{\thesavepage}
% \addtocounter{page}{2}
%
% \section{Supplementary Material Page}
%
% Some Navy organizations require that additional pages follow the title page.
% For example, Carderock/NSWC requires that a Technical Components page follow the 
% title page. The latter page can be produced by using the macro 
% \cmd{\MakeCarderockDivPage} included with this \LaTeX\  package. You can 
% easily define a macro customized for other Navy organziations by copying 
% and modifying this one.
%
% \DescribeMacro{\MakeCarderockDivPage}
% \noindent
% The macro \cmd{\MakeCarderockDivPage} makes use of one field that 
% identifies the form at the bottom of the page, namely 
% \cmd{\NavyFormID\{FormID\}} where FormID is the form identifier, e.g
% ``NDW-DTRC 5602/51 (Rev. 7-93)''. This field is required.
% 
% The\cmd{\MakeCarderockDivPage} command need simply be inserted into your 
% \LaTeX\  document after the \cmd{\MakeNavyCoverPage} command. This will
% result in the following page appearing in the document.
%
% \newpage
% \NavyFormID{NDW-DTRC 5602/51 (Rev. 7-93)}
% \MakeCarderockDivPage
%
% \section{Configuration}
% \enlargethispage{24pt}
% 
% In order to make the use of the report documentation page as easy as
% possible, several aspects of the package are automated or can be easily
% configured.
% 
% \subsection{Fonts}
% \label{sec:configfont}
% 
% When the package is loaded it defines the fonts that are used by
% basing them on the font families \cmd{\sfdefault} for the field labels and
% \cmd{\rmdefault} for the text entries.  By default, they will be based on
% the Computer Modern font family.  If you are changing the base font
% families for your paper and you want the fonts used on the |navydocs| to
% change also, then you must change the font families before loading the
% \Lpack{navydocs} package.  See \cite[pages 229,236]{Kopk-Daly93} for more 
% information about the default font families.
% 
% For any specific field, you can override the default font by 
% declaring your preferred value along with your entry, \eg
% \par\null\noindent 
% \begin{tabular}{llll}
%   ~~ & {\tt \cmd{\Title}\{\cmd{\Huge} A Huge Title\}} & $\rightarrow$ & \smash{\Huge\lower.5ex\hbox{A Huge Title}}
% \end{tabular}
%
% \section{An Example of Use with the \Lpack{article} Class}
% \label{sec:sample}
% \iffalse
%<*sample>
% \fi%
% 
% This sample program demonstrates how the \Lpack{navydocs} package may 
% be used and integrated with an existing class.  Here we redefine 
% \cmd{\@makefile} so that we can create a titlepage and report
% documentation page that share a common set of fields, such as the
% report title, the performing organization title and address and the
% report abstract.
% 
% First we have to start the paper as an \Lpack{article} with twosided
% pages and using the \Lpack{navydocs} package.
% 
%    \begin{macrocode}
\documentclass[twoside]{article}
\usepackage[margin=0.75in]{geometry} % set margins to 0.75 in
\usepackage{lipsum} % required to produce dummy text
\usepackage{navydocs}
%    \end{macrocode}
%
% Set some page specifications so the margin title will appear properly using the defaults. 
% Otherwise we'll need to explicitly specify where the margin title is to be placed.
%
%    \begin{macrocode}

\setlength{\marginparwidth}{64pt}
\setlength{\parindent}{5ex}
\setlength{\paperwidth}{8.5in}
\setlength{\textwidth}{6.5in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
%    \end{macrocode}
%
% Now we fill in the fields needed for the title page.  For reference as a template, 
% we have entered all of the \Lpack{navydocs} block macros below. 
% \newpage
%    \begin{macrocode}

\begin{document}

\NavyDivision{Navy Division, Navy Center}
\NavyDivisionLocation{City, State Zip-Code}
\NavyReportNumber{XXXXXXXX/XX-0123-45}
\NavyReportDate{Month Year}
\NavyReportType{Navy Directorate \\
                     Research and Development Report}
\NavyReportTitle{Mathematical Model Version 2:\\
                       A Long Detailed Title \\
                       Spanning Multiple Lines (if desired)}
\NavyAuthor{Author Name}

% Note that we explicitly shifted the margin title horizontally for 
% better visual effect because of the smaller default font used 
% in the two-sided page option for article.
\NavyMarginTitle{
    \NavyReportNumber{} Mathematical Model Version 2: \\
    \hphantom{\NavyReportNumber{}} A Long Detailed Title Spanning Multiple Lines (if desired)
}

\NavyFormID{NDW-DTRC 5602/51 (Rev. 7-93)}
%    \end{macrocode}
% 
% Finally we produce a very simple report that contains a title page 
% and the technical components page as used by Carderock/NSWC. 
% First we print the title page. Next the technical components page is 
% written. Following these two pages, the table of contents is output, 
% followed by the very short report.
% 
%    \begin{macrocode}

\NavyTitlePage

\pagenumbering{roman}

\MakeCarderockDivPage

\tableofcontents
\cleardoublepage
\pagenumbering{arabic}
\setcounter{page}{1}

\section{Introduction}

\lipsum[1]

\section{Conclusion}

\lipsum[2]

\end{document}
%    \end{macrocode}
% \iffalse
%</sample>
% \fi%
%
% \StopEventually{%
% \section{Acknowledgments}
% 
% I would like to acknowledge Steven Douglas Cochran for authoring the
% \Lpack{sf298} Package, which was used as a template for writing this 
% \Lpack{navydocs} Package.
%
% \begin{thebibliography}{6}%
% \bibitem{Kopk-Daly93}%
%   Michel Goossens, Framk Mittelbach, and Alexander Samarin,
%   \emph{A Guide to \LaTeXe},
%   1993,  2$^{nd}$ edition (revised 1995).
% \end{thebibliography}}
%
% \section{The {\tt DOCSTRIP} Modules}
% The following modules are used in the implementation to direct
% {\tt DOCSCRIPT} in generating the external files:
% \begin{tabular}[t]{ll}
%   driver    & produces a documentation driver file.\\
%   package   & produces the package navydocs.sty.\\
%   sample    & produces a sample \LaTeX\ template and test file.
% \end{tabular}
%
% \newpage
% \section{The code}
% \iffalse
%<*package>
% \fi%
% \subsection{Identification}
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
% Note that the YYYY/MM/DD format must be respected or an error will
% be generated.
\ProvidesPackage{navydocs}[2016/06/22 Navy Documents]
\typeout{Package: navydocs 2016/07/01 v1.1)}
%    \end{macrocode}
%
% Define some commands for the abbreviation ``\eg'' and to retrieve the
% current month as a name.
%
%    \begin{macrocode}
\providecommand{\eg}{{\it e.g.\/\ }}
\newcommand{\MONTH}{%
  \ifcase\the\month
  \or January% 1
  \or February% 2
  \or March% 3
  \or April% 4
  \or May% 5
  \or June% 6
  \or July% 7
  \or August% 8
  \or September% 9
  \or October% 10
  \or November% 11
  \or December% 12
  \fi}
%    \end{macrocode}
%
% \subsection{Load the \Lpack{eso-pic} Package}
%
% Check to see if the \Lpack{eso-pic} package is present.  If it is,
% then load the package so we can put vertical text in the
% left margin per Carderock/NSWC style requirement. If not, then 
% generate a package error.
%
%    \begin{macrocode}
\IfFileExists{eso-pic.sty}{%
  \usepackage{eso-pic, rotating}}
  {\PackageError {navydocs}{The eso-pic package was not found.}
  {Install the eso-pic package on your system.}}
%    \end{macrocode}
%
% \subsection{Load the \Lpack{mdframed} Package}
%
% Check to see if the \Lpack{mdframed} package is present.  If it is,
% then load the package so a vertical line can be drawn to indicate the
% left margin per Carderock/NSWC style requirement. If not, then 
% generate a package error.
%
%    \begin{macrocode}
\IfFileExists{mdframed.sty}{%
\usepackage[
linewidth=4pt,
middlelinecolor= black,
middlelinewidth=0.4pt,
roundcorner=1pt,
topline = false,
rightline = false,
bottomline = false,
rightmargin=0pt,
skipabove=0pt,
skipbelow=0pt,
leftmargin=0cm,
innerleftmargin=1cm,
innerrightmargin=0pt,
innertopmargin=0pt,
innerbottommargin=0pt,
]{mdframed}}
  {\PackageError {mdframed}{The mdframed package was not found.}
  {Install the mdframed package on your system.}}
%    \end{macrocode}
%
% \subsection{Load the \Lpack{fancyhdr} Package}
%
% Check to see if the \Lpack{fancyhdr} package is present.  If it is, then load the package to 
% define a custom footer. If it is not present then report error and terminate. This package 
% is needed to define a custom footer where the form identifier appears on the Technical 
% Components page produced by \cmd{\MakeCarderockDivPage}.
%
%    \begin{macrocode}
\IfFileExists{fancyhdr.sty}{%
  \usepackage{fancyhdr}}
  {\PackageError {navydocs}{The fancyhdr package was not found.}
  {Install the fancyhdr package on your system.}}
%    \end{macrocode}
%
% \subsection{Load the \Lpack{relsize} Package}
%
% Check to see if the \Lpack{relsize} package is present.  If it is, then load the package to 
% allow the font in the margin title to be one size down from whatever is currently being used
% by default.
%
%    \begin{macrocode}
\IfFileExists{relsize.sty}{%
  \usepackage{relsize}}
  {\PackageError {navydocs}{The relsize package was not found.}
  {Install the relsize package on your system.}}
%    \end{macrocode}
%
% \subsection{Load the \Lpack{setspace} Package}
%
% Check to see if the \Lpack{setspace} package is present.  If it is, then load the package to 
% allow  line spacing to be controlled in sections of the document such as those generated
% by \cmd{\MakeCarderockDivPage}.
%
%    \begin{macrocode}
\IfFileExists{setspace.sty}{%
  \usepackage{setspace}}
  {\PackageError {navydocs}{The setspace package was not found.}
  {Install the setspace package on your system.}}
%    \end{macrocode}
%
% \subsection{Load the \Lpack{xparse} Package}
%
% Check to see if the \Lpack{xparse} package is present.  If it is, then load the package to 
% allow a command to be defined with more than one option. This package is used to define
% the \cmd{\NavyMarginTitle} command with two optional arguments for placement of the
% margin title.
%
%    \begin{macrocode}
\IfFileExists{xparse.sty}{%
  \usepackage{xparse}}
  {\PackageError {navydocs}{The xparse package was not found.}
  {Install the xparse package on your system.}}
%    \end{macrocode}
%
% \subsection{The User Interface}
% 
% The following macros define the external and internal portions of the
% user interface.  These macros are used to fill the various items on the 
% title page. All the macros have the same pattern: a public version which 
% sets the internal value, both based on the item name.
%
% \begin{macro}{\NavyDivision}
% \begin{macro}{\navy@Division}
%    \begin{macrocode}
\newcommand\NavyDivision[1]{\renewcommand\navy@Division{#1\hfill}}
\newcommand\navy@Division{\relax}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NavyDivisionLocation}
% \begin{macro}{\navy@Location}
%    \begin{macrocode}
\newcommand\NavyDivisionLocation[1]{\renewcommand\navy@Location{#1\hfill}}
\newcommand\navy@Location{\relax}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% The \cmd{\NavyReportNumber} command is defined so the user 
% can use it to both specify and retrieve the report number. Use
% of the command with an argument will specify the report number,
% while call it will return the currently save report number. The latter
% feature is useful when wishing to have the report number appear in 
% the cover page such as the margin title as shown in the example 
% given in Section~\ref{sec:sample} above.
%
% \begin{macro}{\NavyReportNumber}
% \begin{macro}{\navy@ReportNumber}
%    \begin{macrocode}
\newcommand\NavyReportNumber[1]{
  \ifx&#1&%
     % Empty argument so use existing report number
     \navy@ReportNumber
  \else
     % Use argument for report number
     \renewcommand\navy@ReportNumber{#1}
  \fi
}
\newcommand\navy@ReportNumber{\relax}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NavyReportDate}
% \begin{macro}{\navy@ReportDate}
%    \begin{macrocode}
\newcommand\NavyReportDate[1]{\renewcommand\navy@ReportDate{#1\hfill}}
\newcommand\navy@ReportDate{\number\day~\MONTH~\number\year}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NavyReportType}
% \begin{macro}{\navy@ReportType}
%    \begin{macrocode}
\newcommand\NavyReportType[1]{\renewcommand\navy@ReportType{#1\hfill}}
\newcommand\navy@ReportType{\relax}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NavyReportTitle}
% \begin{macro}{\navy@ReportTitle}
%    \begin{macrocode}
\newcommand\NavyReportTitle[1]{\renewcommand\navy@ReportTitle{#1\hfill}}
\newcommand\navy@ReportTitle{\relax}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NavyAuthor}
% \begin{macro}{\navy@Author}
%    \begin{macrocode}
\newcommand\NavyAuthor[1]{\renewcommand\navy@Author{#1\hfill}}
\newcommand\navy@Author{\relax}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NavyDistributionStatement}
% \begin{macro}{\navy@DistributionStatement}
%    \begin{macrocode}
\newcommand\NavyDistributionStatement[1]
{\renewcommand\navy@DistributionStatement{#1\hfill}}
\newcommand\navy@DistributionStatement{
Approved for public release; distribution is unlimited.\hfill
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% 
% The macro \cmd{\NavyMarginTitle} is defined so an optional title can 
% appear in the left hand margin of the cover page, oriented in a vertical 
% position. It accepts two optional arguments that define the bottom left 
% placement of the margin title in order to allow the user control over its 
% exact placement, if needed. This is achieved by defining two variables 
% (xmargin,ymargin) that are used later in the \cmd{\AddToShipoutPicture} 
% command. By default, the margin title will be placed at the margin paragraph
% width and the bottom of the text height area. Two helper functions are
% defined to properly account for the offset depending on whether the
% margin text occupies 1 or 2 lines.
%
% \begin{macro}{\countlines}
%
% The macro \cmd{\countlines} is a helper function that counts the 
% number of lines in a text block so the offset for the margin title
% can be properly determined.
%
%    \begin{macrocode}
\newcommand\countlines[1]{
   {\setbox0\vbox{\noindent{#1}\par
   \count@\z@
   \loop
   \unskip\unpenalty\unskip\unpenalty\unskip
   \setbox0\lastbox
   \ifvoid0
       \xdef\numlines{\the\count@}
   \else
       \advance\count@\@ne
   \repeat}}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\countlines}
%
% The macro \cmd{\getmargintextheight} is a helper function that 
% calculates the height of a line in a text block so the offset for the
% margin title can be properly calculated.
%
%    \begin{macrocode}
\newcommand\getmargintextheight[1]{
  \newdimen\margintextheight
  \setbox0=\vbox{#1}
  \margintextheight=\ht0 \advance\margintextheight by \dp0
  % count number of lines so height of each line can be found
  \countlines{#1}
  % now determine height of each line
  \margintextheight=\the\dimexpr \margintextheight / \numlines
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NavyMarginTitle}
% \begin{macro}{\navy@MarginTitle}
% \begin{macro}{\marginoffset}
%
% The \cmd{\NavyMarginTitle} command is now defined for two optional
% arguments using the \cmd{\DeclareDocumentCommand} from the usepackage
% xparse. No margin title will appear if \cmd{\NavyMarginTitle} is called with an
% empty argument. The \cmd{\marginoffset} command calculates the 
% default offset for the margin title when it contains 2 lines in the text block. 
%
%    \begin{macrocode}
\newif\ifmargin
\margintrue

\def\marginoffset{\the\dimexpr -\margintextheight*(\numlines - 1)  + 
\margintextheight*(\numlines - 1)/2}

\def\navy@xmargin{
\LenToUnit{\leftmargin - \oddsidemargin + \marginparwidth/2 
+ \marginoffset}}
\def\navy@ymargin{\LenToUnit{\paperheight - \textheight + \topmargin}}
\newcommand\xmargin{\navy@xmargin}
\newcommand\ymargin{\navy@ymargin}

\DeclareDocumentCommand{\NavyMarginTitle}
{
O{ \LenToUnit{\leftmargin - \oddsidemargin + \marginparwidth/2 
+ \marginoffset} }
O{ \LenToUnit{\paperheight - \textheight + \topmargin} } m }{
  \renewcommand\xmargin{#1}
  \renewcommand\ymargin{#2}
  \ifx&#3&%
     % Empty argument so suppress margin title
     \marginfalse
  \else
     % Use mandatory argument for margin title
     
     % get height of each line for margin offset calculation
     \getmargintextheight{#3}

     \renewcommand\navy@MarginTitle{#3}
  \fi
}
\newcommand\navy@MarginTitle{\relax}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NavyFormID}
% 
% The macro \cmd{\NavyFormID\{FormID\}} is defined so a form
% identifier can be placed at the bottom of a page. It is currently used
% by the macro \cmd{\MakeCarderockDivPage} when producing the
% Technical Components page used by the Carderock Divison/NSWC. An
% example FormID for the latter is ``NDW-DTRC 5602/51 (Rev. 7-93)''.
% This macro can be used in new macros that are created for other 
% Supplementary Material pages required by Navy organizations. It
% can also easily be copied and modified for a different \cmd{\fancypagestyle}
% as supported by the\Lpack{fancyhdr} Package.
% 
%    \begin{macrocode}
\newcommand\NavyFormID[1]{
\fancypagestyle{NavyFormIDStyle}
{\fancyhf{}\renewcommand{\headrulewidth}{0pt}
\fancyfoot[L]{\scriptsize #1}} }
%    \end{macrocode}
% \end{macro}
%
% \subsection{Error checking and reporting}
%
% \begin{macro}{\ifnavy@undef}
% \begin{macro}{\navy@undeftrue}
% \begin{macro}{\navy@undeffalse}
% 
% This switch is used by the error reporting at the end of the document
% to generate a general message that there was an undefined required
% field.
% 
%    \begin{macrocode}
\newif\ifnavy@undef
\navy@undeffalse
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\navy@undefined}
% 
% The \cmd{\navy@undefined} macro is executed with the optional argument for
% each required field and without the optional argument at the end of
% the document.
%
%    \begin{macrocode}
\newcommand{\navy@undefined}[1][\@empty]{%
  \ifx \@empty#1\relax
    \ifnavy@undef
       \typeout{^^J%
                navydocs Warning: There are required fields that are 
                undefined.%
                ^^J}%
     \fi
  \else
    \navy@undeftrue
    \typeout{^^J%
             navydocs Warning: \expandafter\string\csname #1
             \endcsname\space is undefined.%
             ^^J}%
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\navy@checkfield}
% 
% This macro does the actual checking for undefined required fields.
% Because of the different sorts of field definitions that could be
% created, it was easier to just fill a box with whatever the user
% defined and check to see if the box has a non-zero width.  You could
% defeat this if you really wanted to, but it should work for reasonable
% field values.
%
%    \begin{macrocode}
\newcommand{\navy@checkfield}[1]{%
  \setbox\@tempboxa\vbox{\csname navy@#1\endcsname}%
  \ifdim \wd\@tempboxa =0pt
    \navy@undefined[#1]
  \fi}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\AtEndDocument{\navy@undefined}
%    \end{macrocode}
%
% \subsection{Page layout}
% 
% This is the part of the code that actually produces the title page and
% any supplementary material pages. After the pages are produced, most 
% of the macros are set to \cmd{\relax} in order to recover as much 
% pool space as possible.
%
% \subsubsection{Form setup and cleanup}
%
% \begin{macro}{\NavyTitlePage}
% 
% At the end of the \cmd{\titlepage} command, the \cmd{\thanks} macro is
% redefined to be \cmd{\relax}.  If we want to define the title once and
% also want to be able to have a \cmd{\thanks} message associated with the
% title on the titlepage, and want to use that same title text on the
% report documentation page, then we need to redefine the \cmd{\thanks}
% macro to eat it's argument.  This is done by setting \cmd{\thanks} to
% \cmd{\@gobble} while printing the report title page.
% 
%    \begin{macrocode}
\newcommand{\NavyTitlePage}{%
   \global\let\thanks\@gobble
   \MakeNavyTitlePage
   \global\let\thanks\relax}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MakeNavyTitlePage}
% 
% The \cmd{\MakeNavyTitlePage} command creates the Report Title Page
% using the information defined by the associated field macros. This
% should be used at the beginning of a deliverable report.
%
%    \begin{macrocode}
\newcommand\MakeNavyTitlePage{%
%    \end{macrocode}
% 
% If the \Lpack{twoside} option is specified in the \cmd{\documentclass}, then
% it is printed as a separate page with a blank back. This page is treated
% as page `{\it i}' (if the documentclass \Lpack{twoside} option is
% specified, then the back treated as page `{\it ii}'.
%
%    \begin{macrocode}
  \newpage
  \if@twoside\ifodd\c@page\else
    \null
    \thispagestyle{empty}%
    \newpage
  \fi\fi
%    \end{macrocode}
%
% Check for missing required fields.  If the field value is missing, then
% print a warning.  In the case of the number of pages, if the 
% \Lpack{totpages} package was loaded, then calculate the value, else if 
% the total pages is not given, then give a warning.
%
%    \begin{macrocode}
  \navy@checkfield{Division}
  \navy@checkfield{Location}
  \navy@checkfield{ReportNumber}
  \navy@checkfield{ReportDate}
  \navy@checkfield{ReportType}
  \navy@checkfield{ReportTitle}
  \navy@checkfield{Author}
  \navy@checkfield{DistributionStatement}
%    \end{macrocode}
%
% Next define a picture that contains the report title oriented vertically
% to be put in the left margin of the title page. This is done to conform
% to Carderock/NSWC title page format requirements.
%
%    \begin{macrocode}
\ifmargin
\AddToShipoutPicture*{\put(\xmargin,\ymargin)
 {\rotatebox{90}
 {\scalebox{1}{\parbox[t]{\textheight}
 {\textbf{\small \navy@MarginTitle}}
 }}}}
 \fi
%    \end{macrocode}
%
% The set up is now done, so start the title page and use the {\it mdframed} 
% environment to create a vertical rule along the left margin. 
%
%    \begin{macrocode}
 \begin{titlepage}

 \noindent
 \begin{minipage}[t]{\textwidth}
 \begin{mdframed}
%    \end{macrocode}
%
% Next put the Navy division and location at the top of the page followed
% by a thick and then thin line that runs horizontally across the page.
%
%    \begin{macrocode}
 \parbox[t][0.98\textheight][t]{\textwidth}{
 \noindent\textbf{\large \navy@Division} 
 \vskip3mm
 \noindent\textbf{\small \navy@Location}
 \vskip3mm
 \noindent\rule{\textwidth}{4pt} % thick line across page
 \vskip-8pt
 \noindent\rule{\textwidth}{2pt} % thinner line across page
%    \end{macrocode}
%
% Vertically skip 4\,mm and state the report number, report date, and report type.
%
%    \begin{macrocode}
\vspace{4mm}\\
\noindent
\navy@ReportNumber \ \navy@ReportDate \\ \navy@ReportType \\
%    \end{macrocode}
%
% Vertically skip 1.7\,cm and insert the report tiltle and author(s). Note that the
% blank lines are needed in order for the \cmd{\vspace} to work properly.
%
%    \begin{macrocode}
\vspace{1.7cm}\\
{\Large \textbf{\navy@ReportTitle}
\vspace{1cm}\\
\normalsize
\noindent 
by \\ \navy@Author
}\\
%    \end{macrocode}
%
% Finish adding the content to the page by placing the Navy logo and the Distribution 
% Statement at the bottom, closing off the page with a horizontal rule. Note that the
% Distribution Statement outlined by horizontal lines is produced within a {\it minipage}
% environment.
%
%    \begin{macrocode}
\vfill
\noindent
\includegraphics[width=21mm]{graphics/navy-logo-102.png} 
\hspace{0.6in}
\begin{minipage}{0.75\textwidth}
\vspace{-0.8cm}
\hrule height 4pt
\vspace{4pt}
\noindent
\parbox[c]{\textwidth}{
\vspace{4pt}
\textbf{\small \navy@DistributionStatement}
\vspace{4pt}
}
\hrule height 4pt
\end{minipage}}
%    \end{macrocode}
%
% Finish up the tiitle page.
% 
%    \begin{macrocode}
 \end{mdframed}
 \end{minipage}
 \end{titlepage}
%    \end{macrocode}
% 
% Finally, the last step is to set all of the now unused definitions to
% \cmd{\relax}, thereby freeing some space.
%
%    \begin{macrocode}
%  \thispagestyle{empty}

  \global\let\NavyDivision\relax
  \global\let\navy@Division\relax
  \global\let\Location\relax
  \global\let\navy@Location\relax
  \global\let\ReportNumber\relax
  \global\let\navy@ReportNumber\relax
  \global\let\NavyReportDate\relax
  \global\let\navy@ReportDate\relax
  \global\let\NavyReportType\relax
  \global\let\navy@ReportType\relax
  \global\let\ReportTitle\relax
  \global\let\navy@ReportTitle\relax
  \global\let\NavyAuthor\relax
  \global\let\navy@Author\relax
  \global\let\NavyRelease\relax
  \global\let\navy@DistributionStatement\relax
  \global\let\MarginTitle\relax
  \global\let\navy@MarginTitle\relax

  \global\let\MakeNavyCoverPage\relax} % end of \MakeNavyCoverPage
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MakeCarderockDivPage}
% 
% The \cmd{\MakeCarderockDivPage} command creates the Technical Components
% page for the Carderock Division/NSWC. The text for the page is explicitly included
% in this initial release of the package, rather than passed into the macro via a user 
% interface, because it is not known at the time of writing what are the requirements
% of other Navy organizations. This is subject to change in future if there is a need
% and demand to do so.
% 
% The Technical Components page is produced using the fancy page style defined
% via the \cmd{\NavyFormID} described above so the document code appears
% in the footer.
%
%    \begin{macrocode}
\newcommand\MakeCarderockDivPage{%
  \thispagestyle{NavyFormIDStyle} % insert document code in footer
%    \end{macrocode}
%
% Insert page title at the top in reverse image followed by the list of Navy codes
% residing at Carderock/NSWC.
%
%    \begin{macrocode}
  \section*{ \sffamily\colorbox{black}{\bfseries\textcolor{white}
  {\large MAJOR CARDEROCK DIVISION TECHNICAL COMPONENTS}} }
  \vspace{8ex}

  \doublespace
  \begin{tabular}{lrl}
  CODE & 011 & Director of Technology \\
  & 10 & Machinery Systems/Programs and Logistics Directorate \\
  & 20 & Ship Systems \& Programs Directorate \\
  & 50 & Hydromechanics Directorate \\
  & 60 & Survivability, Structures and Materials Directorate \\
  & 70 & Signatures Directorate \\
  & 80 & Machinery Research \& Development Directorate \\
  & 90 & Machinery In-Service Engineering Directorate
  \end{tabular}
  \singlespace
%    \end{macrocode}
%
% State types of reports produced by the division at the bottom of the page in a framed box.
%
%    \begin{macrocode}
  \vfill % push minipage to bottom of page

  \noindent
  \fbox{\begin{minipage}{\textwidth}
  \vspace{2ex}
  \begin{center}
  CARDEROCK DIVISION, NSWC, ISSUES THREE TYPES OF REPORTS:
  \end{center}

  \parbox{0.97\textwidth}{
  \begin{enumerate}
  \item \textbf{CARDEROCKDIV reports, a formal series,} contain information 
  of permanent technical value. They carry a consecutive numerical 
  identification regardless of their classification or the originating 
  directorate. 
  \item \textbf{Directorate reports, a semiformal series,} contain 
  information of a preliminary, temporary, or proprietary nature or of 
  limited interest or significance. They carry an alpha numeric 
  identification issued by the originating directorate. 
  \item \textbf{Technical memoranda, an informal series,} contain 
  technical documentation of limited use and interest. They are primarily 
  working papers intended for internal use. They carry an identifying 
  number which indicates their type and the numerical code of the 
  originating directorate. Any distribution outside CARDEROCKDIV must be 
  approved by the head of the originating directorate on a case-by-case 
  basis.
  \end{enumerate}
  }
  \vspace{1ex}

  \end{minipage}}
%    \end{macrocode}
%
% Force new page and close the \cmd{\MakeCarderockDivPage} macro.
%
%    \begin{macrocode}
  \newpage
  \global\let\MakeCarderockDivPage\relax} % end of \MakeCarderockDivPage
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%</package>
% \fi%
%
% \Finale
%
