% \iffalse meta-comment
%
% Copyright 2019 Seth M. Price.
% 
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3 of this license or any later version.
% The latest version of this license is in:
% 
%   https://www.latex-project.org/lppl/lppl-1-3c/
% 
% and version 1.3c or later is part of all distributions
% of LaTeX version 2008/05/04 or later.
%
% \fi
%
% \iffalse
%
% \section*{Documentation driver}
% \addcontentsline{toc}{section}{Documentation driver}
%
%    \begin{macrocode}
%<*driver>
\ProvidesFile{mla.dtx}
%</driver>

%<mla>\NeedsTeXFormat{LaTeX2e}
%<mla>\ProvidesClass{mla}
%<*mla>
    [2024/09/13 v1.1 MLA Paper Class]
%</mla>

%<*driver>
\documentclass{ltxdoc}
\AtBeginDocument{\RecordChanges\CodelineIndex\EnableCrossrefs}

%% These bits are some common shorthand I picked up:
\newcommand*{\Dfile}[1]{\texttt{#1}}
\newcommand*{\Dopt}[1]{\textsf{\small #1}}
\newcommand*{\Dctr}[1]{\textsl{\small #1}}
\newcommand*{\Dlst}[1]{\texttt{#1}}
\newcommand*{\Denv}[1]{\texttt{#1}}
\newcommand*{\Dcls}[1]{\textsf{#1}}
\newcommand*{\Dpkg}[1]{\textsf{#1}}

%% Needed for the appendix
\usepackage{verbatim}

%% A couple things are cited in the docs
\begin{filecontents}{mla.bib}
@book{mlahb,
	author = {{Modern Language Association of America}},
	shortauthor = {{Modern Language Association}},
	title = {The {MLA} Handbook for Writers of Research Papers},
	shorttitle = {Handbook},
	edition = {8},
	year = {2016},
	publisher = {{Modern Language Association of America}},
	howpublished = {Print},
	isbn = {9781603292627}
}
@online{owlmla,
	title = {{MLA} General Format},
	journaltitle = {{P}urdue Online Writing Lab},
	institution = {Purdue University},
	howpublished = {Web},
	urldate = {2019-05-06},
	url = {https://owl.purdue.edu/owl/research_and_citation/mla_style/mla_formatting_and_style_guide/mla_general_format.html}
}
@online{owlendnotes,
	title = {{MLA} Endnotes and Footnotes},
	journaltitle = {{P}urdue Online Writing Lab},
	institution = {Purdue University},
	howpublished = {Web},
	urldate = {2019-05-06},
	url = {https://owl.purdue.edu/owl/research_and_citation/mla_style/mla_formatting_and_style_guide/mla_endnotes_and_footnotes.html}
}
\end{filecontents}
\usepackage[backend=biber]{biblatex}
\addbibresource{mla.bib}

%% Just thought it'd be cool to use `acro'
%% (though v3.6 seems to have broken everything)
\ExplSyntaxOn
\prop_new:N \l__acro_foreign_format_prop
\ExplSyntaxOff
\usepackage{acro2}
\DeclareAcronym{US}{short=US,long=United States}
\DeclareAcronym{MLA}{short=MLA,long=Modern Language Association}
\DeclareAcronym{CTAN}{short=CTAN,
                      long=Comprehensive \TeX\ Archive Network}
\DeclareAcronym{OWL}{short=OWL,long=Purdue Online Writing Lab}
\DeclareAcronym{PDF}{short=PDF,long=Portable Document Format}
\DeclareAcronym{LPPL}{short=LPPL,long=\LaTeX\ Project Public License}
\DeclareAcronym{SE}{short=SE,long=Stack Exchange}

%% For a few different things
\usepackage{semantic-markup}

%% Reset footnotes per page
\usepackage[perpage]{footmisc}

%% Keep footnotes from breaking across pages
\interfootnotelinepenalty=10000

%% Technical info
\def\myemail{sprice623@aol.com}

%% For the sake of consistency, I guess
\GlossaryPrologue{\section{Change history}}

%% Everything just looks better, in my opinion
\usepackage{microtype}

%% Fancy PDF
\usepackage[numbered]{hypdoc}
\hypersetup{
    hidelinks,
    pdfinfo={
        Title=The MLA class,
        Author=Seth M. Price,
        Creator=LaTeX
    }
}

%% Comment this if you don't want to produce a changelog
\AtEndDocument{\PrintChanges}

\GetFileInfo{mla.dtx}

\begin{document}
\DocInput{mla.dtx}
\end{document}
%</driver>
%    \end{macrocode}
%
% \fi
%
% \CheckSum{430}
%
% \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 \Dcls{mla} class\thanks{This document corresponds to
%        \Dcls{mla}~\fileversion, dated \filedate.}}
% \author{Seth M.\ Price \\ \href{mailto:\myemail}{\texttt{\myemail}}}
% \date{\today}
%
% \maketitle
%
% \begin{abstract}
% In the \acl{US}, secondary and undergraduate students
% are generally expected to adhere to the format prescribed by
% the \ac{MLA} for typewritten essays, research papers and writings.
% Sadly, the tool of choice is usually Microsoft Word,
% even amongst those fluent with \TeX .
%
% Though there \emph{are} some templates and tools to aid in
% writing in the \ac{MLA} format using \LaTeX ,
% none fully met the expectations of the author.
% So \foreign{voil\`a}, there now exists an \Dfile{mla.cls} proper:
% a simple, straightforward class for composing papers
% almost perfectly adherent to the
% \ac{MLA} style guide\footfullcite{mlahb}.
% \end{abstract}
%
% \section*{Licensing}
% \label{sec:licensing}
%
% The files contained in this package
% may be distributed and/or modified under the
% conditions of the \ac{LPPL}, either
% version 1.3 of this license or any later version.
% The latest version of this license is in
% \url{https://www.latex-project.org/lppl/lppl-1-3c/},
% and version 1.3c or later is part of all distributions
% of \LaTeX\ version 2008/05/04 or later.
%
% \microtypesetup{protrusion=false}
% \tableofcontents
% \microtypesetup{protrusion=true}
%
% \StopEventually{} ^^A
%
% \section{Initial code}
% \label{sec:initial_code}
%
% The \Dcls{mla} class uses the \Dcls{article} class as its base.
% Thanks to this, macros such as \cs{textit} or \cs{textsuperscript}
% work as expected and won't have to be re-defined.
%    \begin{macrocode}
\LoadClass[letterpaper,12pt]{article}
%    \end{macrocode}
%
% \begin{macro}{\mladate}
% The \citetitle{mlahb} requires use of the \term{day month year}
% date format, not \TeX 's standard \term{month day, year}.
% The macro \cs{mladate} will format \cs{today} accordingly
% to be used as the default value for \cs{date}
% (see section~\ref{sec:the_header}).
%
% \changes{v0.2}{2019/05/02}{Added macro}
% \changes{v0.7}{2019/08/30}{Added August to month list}
%    \begin{macrocode}
\newcommand{\mladate}{%
    \the\day\ 
    \ifcase\the\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
    \the\year
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MLA@seven}
% \begin{macro}{\MLA@eight}
% \begin{macro}{\MLA@eightalt}
% \begin{macro}{\MLA@figures}
% \begin{macro}{\MLA@notes}
% \begin{macro}{\MLA@microtype}
% \begin{macro}{\MLA@paperheader}
% \begin{macro}{\MLA@pageheader}
% \begin{macro}{\MLA@plainheadings}
% \begin{macro}{\MLA@fullpage}
% \begin{macro}{\MLA@times}
% The following are true/false switches to toggle certain features.
%
%    \begin{macrocode}
\newif\ifMLA@seven
\newif\ifMLA@eight
\newif\ifMLA@eightalt
\newif\ifMLA@figures
\newif\ifMLA@notes
\newif\ifMLA@microtype
\newif\ifMLA@paperheader
\newif\ifMLA@pageheader
\newif\ifMLA@plainheadings
\newif\ifMLA@fullpage
\newif\ifMLA@times
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \section{Options}
% \label{sec:options}
%
% Some teachers and professors might still require using
% the seventh edition of the \citetitle{mlahb},
% while others will likely use the eighth edition.
% Which edition to implement can be explicitly specified
% with the \Dopt{mla7} and \Dopt{mla8} class options.
% The only difference this makes within the \Dcls{mla} class itself
% is the citation format used by \Dpkg{biblatex}.
%
% \changes{v0.3}{2019/05/06}{Improved options parsing to avoid
%	contradiction and undefined behavior}
% \changes{v0.5}{2019/05/21}{Changed options parser to use
%	toggle-switch commands in the style of default \LaTeX\ classes}
% \changes{v0.7}{2019/05/30}{Changed options parser to use
%	\cs{ifMLA@\ldots} toggle format seen in other classes}
%    \begin{macrocode}
\DeclareOption{mla7}{\MLA@seventrue\MLA@eightfalse\MLA@eightaltfalse}
\DeclareOption{mla8}{\MLA@sevenfalse\MLA@eighttrue\MLA@eightaltfalse}
%    \end{macrocode}
%
% \changes{v0.3}{2019/05/07}{Added \Dopt{mla8alt} option}
% Some versions of \Dpkg{biblatex-mla} might not recognize
% the \Dopt{style=mla-new} option for the eighth edition.
% In this case, one can specify \Dopt{mla8alt}
% to the \Dcls{mla} class.
%    \begin{macrocode}
\DeclareOption{mla8alt}{\MLA@sevenfalse\MLA@eightfalse\MLA@eightalttrue}
%    \end{macrocode}
%
% For those who do not plan on using figures and/or endnotes,
% some time (and dependency disk space) might be saved by using the
% \Dopt{nofigures} and/or \Dopt{nonotes} options, as they are enabled
% by default.
%    \begin{macrocode}
\MLA@figurestrue
\MLA@notestrue
\DeclareOption{nofigures}{\MLA@figuresfalse}
\DeclareOption{nonotes}{\MLA@notesfalse}
%    \end{macrocode}
%
% The \Dpkg{microtype} package can be optionally included
% with the \Dopt{microtype} option to offset the pain of using
% the Times typeface.
%    \begin{macrocode}
\DeclareOption{microtype}{\MLA@microtypetrue}
%    \end{macrocode}
%
% \changes{v0.9}{2020/10/05}{Added \Dopt{nopaperheader},
%	\Dopt{nopageheader} and \Dopt{noheaders} options to enable
%	omission of paper headers, page headers or both paper
%	and page headers respectively}
% For rare cases in which the paper and page headers are omitted
% or must be custom, the options \Dopt{nopaperheader} and
% \Dopt{nopageheader} may be used respectively, or
% \Dopt{noheaders} to omit both.
%    \begin{macrocode}
\MLA@paperheadertrue
\MLA@pageheadertrue
\DeclareOption{nopaperheader}{\MLA@paperheaderfalse}
\DeclareOption{nopageheader}{\MLA@pageheaderfalse}
\DeclareOption{noheaders}{\MLA@paperheaderfalse\MLA@pageheaderfalse}
%    \end{macrocode}
%
% \changes{v0.9}{2020/10/05}{Added \Dopt{plainheadings} option to
%	forego small-caps and auto-numbering in section headings}
% For professors and/or writers who desire to format the section
% headings manually and individually (and forego \cs{titleformat\{\}},
% the \Dopt{plainheadings} option may be used.
%    \begin{macrocode}
\MLA@plainheadingsfalse
\DeclareOption{plainheadings}{\MLA@plainheadingstrue}
%    \end{macrocode}
%
% \changes{v0.9}{2020/11/07}{Added \Dopt{fullpage} option to explicitly
%	allow widows and orphans}
% Another edge case is in which a professor may require strict 24-line
% papers, i.\,e.\ explicitly allowing orphans and widows, enabled using
% the \Dopt{fullpage} option\footnote{In versions of \Dcls{mlacls}
% prior to v0.9, disallowing widows and orphans was default behavior.}.
%    \begin{macrocode}
\MLA@fullpagefalse
\DeclareOption{fullpage}{\MLA@fullpagetrue}
%    \end{macrocode}
%
% \changes{v1.1}{2024/02/04}{Added \Dopt{notimes} option to not set Times New
%	Roman as the font}
% For professors that do not require Times New Roman as the font, the
% \Dopt{notimes} option may be used to keep the default font. This allows
% maintaining \LaTeX{}'s default font if desired.
% \begin{macrocode}
\MLA@timestrue
\DeclareOption{notimes}{\MLA@timesfalse}
% \end{macrocode}
%
% \subsection{Processing}
% \label{sec:processing}
%
% A friendly warning will be provided when an unknown option
% is provided.
%
%    \begin{macrocode}
\DeclareOption*{%
    \ClassWarning{mla}{Unknown option `\CurrentOption'; ignoring}
}
%    \end{macrocode}
%
% By default, the eighth edition of the \citetitle{mlahb} is used.
% To future-proof your documents for upcoming editions, however,
% it may be wise to explicitly specify \Dopt{mla8}.
%
%    \begin{macrocode}
\ExecuteOptions{mla8}
\ProcessOptions\relax
%    \end{macrocode}
%
% \section{Loading packages}
% \label{sec:loading_packages}
%
% The \Dcls{mla} class requires the following packages\footnote{All
% of the required packages are available for download
% on the \ac{CTAN} if unavailable on your system:
% \url{https://www.ctan.org/}.}:
%
% \changes{v0.3}{2019/05/07}{Replaced obsolete \Dpkg{times} package
%	with \Dpkg{newtxtext}}
% \changes{v0.4}{2019/05/11}{Added \Dpkg{microtype} package}
% \changes{v0.4}{2019/05/12}{Added \Dpkg{enumitem} package}
% \changes{v0.6}{2019/05/29}{Added \Dpkg{caption} package}
% \changes{v0.6}{2019/05/29}{Added \Dpkg{graphicx} package}
% \changes{v0.6}{2019/05/29}{Added \Dpkg{float} package}
% \changes{v0.7}{2019/06/01}{Changed \Dpkg{microtype} package
%	to only load through \Dopt{microtype} class option}
% \changes{v0.9}{2020/08/20}{Added \Dopt{nofigures} and \Dopt{nonotes}
%	options to prevent loading unused dependencies}
%    \begin{macrocode}
\RequirePackage{enumitem}
\RequirePackage{fancyhdr}
\RequirePackage{fullpage}
\RequirePackage{ragged2e}
\RequirePackage{titlesec}
\RequirePackage{xstring}
%    \end{macrocode}
%
% The following consists of prerequisites for \Dpkg{biblatex-mla}:
%
% \changes{v0.2}{2019/05/02}{Hid hyperlink boxes in \acs{PDF} output}
% \changes{v0.2}{2019/05/02}{Added support for \acs{PDF} metadata}
%    \begin{macrocode}
\RequirePackage[american]{babel}
\RequirePackage{csquotes}
\RequirePackage{hanging}
%    \end{macrocode}
%
% And finally, \Dpkg{biblatex}.
% The \Dcls{mla} class options dictate what options are passed to
% \Dpkg{biblatex}, hence the \term{if-then} clauses.
%
% \changes{v1.0}{2021/09/14}{Fixed bug which caused class to fail
%	with \ac{MLA} 8 citations}
%    \begin{macrocode}
\ifMLA@seven
    \RequirePackage[style=mla7,noremoteinfo=false,
                    backend=biber]{biblatex}
\fi
\ifMLA@eight
    \RequirePackage[style=mla-new,noremoteinfo=false,
                    backend=biber]{biblatex}
\fi
\ifMLA@eightalt
    \RequirePackage[style=mla,noremoteinfo=false,
                    backend=biber]{biblatex}
\fi
%    \end{macrocode}
%
% The \Dpkg{caption}, \Dpkg{float} and \Dpkg{graphicx} packages
% are loaded by default, but can be disabled using the
% \Dopt{nofigures} option.
%
%    \begin{macrocode}
\ifMLA@figures
    \RequirePackage{caption}
    \RequirePackage{float}
    \RequirePackage{graphicx}
\fi
%    \end{macrocode}
%
% Likewise, the \Dpkg{enotez} package can be disabled with
% \Dopt{nonotes}.
%
%    \begin{macrocode}
\ifMLA@notes
    \RequirePackage{enotez}
\fi
%    \end{macrocode}
%
% And the \Dpkg{newtxtext} package can be disabled with \Dopt{notimes}.
%
%    \begin{macrocode}
\ifMLA@times
    \RequirePackage{newtxtext}
\fi
%    \end{macrocode}
%
% The \Dpkg{microtype} package is loaded if the \Dopt{microtype}
% option is specified.
% 
%    \begin{macrocode}
\ifMLA@microtype
    \RequirePackage{microtype}
\fi
%    \end{macrocode}
%
% For some reason, common practice is to load \Dpkg{hyperref} last
% of all packages.
%
%    \begin{macrocode}
\RequirePackage{hyperref}
\hypersetup{hidelinks,pdfusetitle}
%    \end{macrocode}
%
% \section{Document layout}
% \label{sec:document_layout}
%
% \subsection{Font}
% \label{sec:font}
%
% The font size was set to 12pt when loading the \Dcls{article} class
% in section~\ref{sec:initial_code}.
% Unless the option \Dopt{notimes} was specified,
% the \Dpkg{newtxtext} package will have been loaded in
% section~\ref{sec:loading_packages},
% which should be metric-compatible with the infamous Times New Roman,
% the \foreign{de facto} standard of the
% \ac{MLA} format\footnote{According to the popular, oft-referenced
% \ac{OWL}: \citeurl{owlmla}.}.
%
% \subsubsection{Microtype}
% \label{sec:microtype}
%
% The \Dpkg{microtype} package (if loaded as in
% section~\ref{sec:loading_packages})
% will marginally offset the burden of using Times
% by correcting its ugly kerning and tracking.
% The vague \Dopt{activate=false} below simply disables
% protrusion, maintaining original line and page breaks.
%
% \changes{v0.4}{2019/05/12}{Disabled \Dpkg{microtype} protrusion}
%    \begin{macrocode}
\ifMLA@microtype
    \microtypesetup{activate=false}
\fi
%    \end{macrocode}
%
% \subsection{Line breaking and spacing}
% \label{sec:line_breaking}
%
% The \citetitle{mlahb} prescribes exact double-spacing,
% the definition of which varies between typesetters.
% With these parameters exact, \LaTeX\ produces 23 lines of text
% whereas the \soCalled{industry standard}
% Microsoft Word\footnote{Microsoft Word 97 through 2016,
% and likely following versions as well.} produces 24.
% To compensate, line spacing is set to \emph{just enough}:
%
% \changes{v0.4}{2019/05/08}{Changed \cs{linespacing} to
%	print 24 lines per page}
%    \begin{macrocode}
\linespread{1.905}
%    \end{macrocode}
%
% Though not explicitly denounced in the \citetitle{mlahb},
% most \ac{MLA}-style papers don't hyphenate or adjust spacing
% for pretty typesetting.
%
%    \begin{macrocode}
\hyphenpenalty=10000
\pretolerance=10000
%    \end{macrocode}
%
% \subsection{Paragraphing}
% \label{sec:paragraphing}
%
% The \citetitle{mlahb} specifies half-inch first-line indentation
% for every paragraph and no extra spacing in between.
%
% \changes{v0.6}{2019-05-29}{Explicitly set \cs{partopset} to 0pt}
%    \begin{macrocode}
\setlength{\parindent}{0.5in}
\setlength{\RaggedRightParindent}{\parindent}
\setlength{\parskip}{0em}
\setlength{\topsep}{0em}
\setlength{\partopsep}{0em}
%    \end{macrocode}
%
% \TeX\ does not indent the first paragraph after headings by default.
% Thankfully, the fix for this is simple.
%
% \changes{v0.7}{2019/05/31}{Copied code from \Dpkg{indentfirst}
%	to reduce dependency count}
%    \begin{macrocode}
\let\@afterindentfalse\@afterindenttrue
\@afterindenttrue
%    \end{macrocode}
%
% Orphans and widows are explicitly banned\footnote{According to the
% \ac{MLA} itself: \url{https://style.mla.org/orphaned-words/}}.
% For the odd case in which papers must be consistently 24 lines
% (i.\,e.\ explicitly allowing orphans and widows), the
% \Dopt{fullpage} option may be used (see section~\ref{sec:options}).
%
%    \begin{macrocode}
\ifMLA@fullpage
    \widowpenalty=0
    \clubpenalty=0
    \interlinepenalty=0
\else
    \widowpenalty=10000
    \clubpenalty=10000
\fi
%    \end{macrocode}
%
% As a heinous crime against the art of typesetting,
% the \citetitle{mlahb} advises flush-left/ragged-right alignment.
% (This is acheived with the \Dpkg{ragged2e} package.)
%
%    \begin{macrocode}
\RaggedRight
%    \end{macrocode}
%
% \begin{environment}{noindent}
% The \Denv{noindent} environment doesn't work as expected
% in conjunction with \Dpkg{ragged2e}, hence the re-definition.
%
%    \begin{macrocode}
\renewenvironment{noindent}{%
    \edef\tmpind{\parindent}
    \setlength{\parindent}{0pt}
}{%
    \setlength{\parindent}{\tmpind}
    \undef{\tmpind}
}
%    \end{macrocode}
% \end{environment}
%
% \subsection{Page layout}
% \label{sec:page_layout}
%
% With few exceptions, the \ac{US} uses \soCalled{letter-size} paper.
% The paper size was already set when loading the \Dcls{article} class
% in section~\ref{sec:initial_code}.
%
% Furthermore, the \citetitle{mlahb} dictates uniform one-inch margins
% on said paper.
% This was already set by the \Dpkg{fullpage} package as loaded
% in section~\ref{sec:loading_packages}.
% The \cs{textheight} and \cs{textwidth} definitions are here
% just for good measure.
%
%    \begin{macrocode}
\setlength{\textheight}{9in}
\setlength{\textwidth}{6.5in}
%    \end{macrocode}
% 
% \subsection{Running head}
% \label{sec:running_head}
%
% The running head in \ac{MLA} style is simply the author's surname
% (if defined) followed by the current page number, right-aligned,
% unless specified otherwise using the \Dopt{nopageheader} option
% (see section~\ref{sec:options}).
% This is managed using the \Dpkg{fancyhdr} and \Dpkg{xstring} packages.
%
%    \begin{macrocode}
\fancypagestyle{norule}{%
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
}
\fancyhf{}
\pagestyle{headings}
\pagestyle{norule}
\ifMLA@pageheader
    \ifx\@author\@empty
        \fancyhead[RO]{\thepage}
    \else
        \fancyhead[RO]{{\StrBehind{\@author}{ }[\last]\last} \thepage}
    \fi
\fi
%    \end{macrocode}
%
% The following code is largely a hack to align the header
% in the middle of the one-inch margin above the body text.
%
%    \begin{macrocode}
\setlength{\headheight}{18pt}
\setlength{\headsep}{12pt}
\setlength{\voffset}{-34pt}
%    \end{macrocode}
%
% \section{Document markup}
% \label{sec:document_markup}
%
% \subsection{The header}
% \label{sec:the_header}
%
% \begin{macro}{\title}
% \begin{macro}{\author}
% \begin{macro}{\date}
% The \cs{title}, \cs{author} and \cs{date} macros work as expected.
% However, if your surname contains a space, you must contain the
% surname in braces as such:
% {\small |\author{Ludwig {van Beethoven}}|}.
% This keeps the full surname in the running head (see
% section~\ref{sec:running_head}).
% \end{macro}
% \end{macro}
% \end{macro}
%
% The following header commands are unique to the \Dcls{mla} class.
%
% \begin{macro}{\professor}
% The instructor who assigned the paper, i.e.
% \mentioned{Dr.\ Marjorie Stewart}.
%
%    \begin{macrocode}
\newcommand*{\professor}[1]{\gdef\@professor{#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\course}
% The course for which this paper was assigned, i.e.
% \mentioned{ENGL 101-02}.
%
%    \begin{macrocode}
\newcommand*{\course}[1]{\gdef\@course{#1}}
%    \end{macrocode}
% \end{macro}
%
% To prevent undefined behavior, the internal macros used
% to store the above information are set empty, except for \cs{date}.
% (Note the use of \cs{mladate}; see section~\ref{sec:initial_code}.)
%
%    \begin{macrocode}
\title{}
\author{}
\professor{}
\course{}
\date{\mladate}
%    \end{macrocode}
% 
% \begin{macro}{\makemlaheader}
% This command finally prints out the standard four-line
% \ac{MLA} header, as well as the title.
%
% \changes{v0.2}{2019/05/02}{Changed date format to
%	\term{day month year}}
% \changes{v0.4.1}{2019/05/15}{Changed date format back to whatever
%	is inside \cs{@date}}
% \changes{v0.9}{2020/10/05}{Changed to ignore (not print) undefined
%	header macros}
% \changes{v0.9}{2020/10/05}{Fix weird bug where paragraph immediately
%	after \cs{begin\{paper\}} (with no newline) is not indented}
%    \begin{macrocode}
\newcommand{\makemlaheader}{%
    \begin{noindent}
	\ifx\@author\@empty\else\@author\\\fi
	\ifx\@professor\@empty\else\@professor\\\fi
	\ifx\@course\@empty\else\@course\\\fi
	\ifx\@date\@empty\else\@date\\\fi
        \ifx\@title\@empty\else\begin{center}\@title\end{center}\fi
    \end{noindent}
    % for some reason, this blank line is necessary
}
%    \end{macrocode}
% \end{macro}
%
% For simplicity's sake, \cs{maketitle} is directly aliased
% to \cs{makemlaheader}.
%
%    \begin{macrocode}
\renewcommand{\maketitle}{\makemlaheader}
%    \end{macrocode}
%
% Finally, the header will print at the beginning of every document
% unless specified otherwise using the \Dopt{nopaperheader} option
% (see section~\ref{sec:options}).
%
% \changes{v0.5}{2019/05/18}{Moved header-printing process to
%	\cs{AtBeginDocument}}
%    \begin{macrocode}
\ifMLA@paperheader
    \AtBeginDocument{\maketitle}
\fi
%    \end{macrocode}
%
% \subsection{Sectioning}
% \label{sec:sectioning}
%
% \changes{v0.7}{2019/08/30}{Replaced regular space after dot
%	in section headings with \cs{enspace}}
% \changes{v0.8}{2020/08/16}{Removed extraneous spacing and newlines
%	in section headings}
% \begin{macro}{\section}
% \changes{v0.2}{2019/05/02}{Changed heading to small-caps}
% \begin{macro}{\subsection}
% \changes{v0.2}{2019/04/27}{Properly formatted}
% \changes{v0.2}{2019/05/02}{Changed heading to small-caps}
% \begin{macro}{\subsubsection}
% \changes{v0.2}{2019/04/27}{Properly formatted}
% \changes{v0.2}{2019/05/02}{Changed heading to small-caps}
% Section headings are neither defined nor discouraged
% in the \citetitle{mlahb}, though commonly used in longer papers.
% Customary section headings are rather straightforward,
% consisting of the section number in Arabic numerals, a space,
% and the section name with no special decoration\footnote{According to
% the popular, oft-referenced \ac{OWL}: \citeurl{owlmla}.}.
%
% However, for the sake of clarity, the section headings in this class
% will be set in small-caps by default.
% Plain, unnumbered and entirely unformatted section headings can
% be acheived using the \Dopt{plainheadings} option
% (see section~\ref{sec:options}).
% For custom headings other than these, refer to the
% \Dpkg{fancyhdr} package documentation.
%
%    \begin{macrocode}
\renewcommand{\thesection}{\@arabic\c@section}
\renewcommand{\thesubsection}{\thesection.\@arabic\c@subsection}
\renewcommand{\thesubsubsection}{\thesubsection.\@arabic\c@subsubsection}
%    \end{macrocode}
%
% Un-fancifying the headings is acheived using
% the \Dpkg{titlesec} package.
%
%    \begin{macrocode}
\ifMLA@plainheadings
    \titleformat{\section}[block]{\normalsize}{}{0pt}{}[]
    \titleformat{\subsection}[block]{\normalsize}{}{0pt}{}[]
    \titleformat{\subsubsection}[block]{\normalsize}{}{0pt}{}[]
\else
    \titleformat{\section}[block]{\normalsize\sc}{\thetitle.\enspace}{0pt}{}[]
    \titleformat{\subsection}[block]{\normalsize\sc}{\thetitle.\enspace}{0pt}{}[]
    \titleformat{\subsubsection}[block]{\normalsize\sc}{\thetitle.\enspace}{0pt}{}[]
\fi
\titlespacing*{\section}{0pt}{0pt}{0pt}
\titlespacing*{\subsection}{0pt}{0pt}{0pt}
\titlespacing*{\subsubsection}{0pt}{0pt}{0pt}
\titlelabel{}
\patchcmd{\ttl@select}{\strut}{}{}{}
\patchcmd{\ttlh@hang}{\strut}{}{}{}
\patchcmd{\ttlh@hang}{\strut}{}{}{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Lists}
% \label{sec:lists}
%
% \begin{environment}{itemize}
% \changes{v0.4}{2019/05/12}{Added list type}
% \begin{environment}{enumerate}
% \changes{v0.4}{2019/05/12}{Added list type}
% To the user, \Dlst{itemize} and \Dlst{enumerate} lists
% will function exactly as expected.
% However, the formatting of the lists must be modified as to
% preserve double-spacing and adhere to
% common practice\footnote{According to the \ac{MLA} itself:
% \url{https://style.mla.org/vertical-lists-in-mla-style/}.};
% these changes are acheived using the \Dpkg{enumitem} package.
%
%    \begin{macrocode}
\setlist[itemize]{%
    parsep=0pt,
    itemsep=0pt,
    topsep=0pt,
    leftmargin=\parindent
}
\setlist[enumerate]{%
    parsep=0pt,
    itemsep=0pt,
    topsep=0pt,
    leftmargin=\parindent
}
%    \end{macrocode}
% \end{environment}
% \end{environment}
%
% \changes{v1.1}{2024/09/12}{Modify footnotes to be more in-style}
% \subsection{Footnotes}
% \label{sec:footnotes}
%
% Footnotes are styled similarly to endnotes (see section \ref{sec:endnotes}),
% but in smaller text, and glued to the bottom of the page.
%
%    \begin{macrocode}
\addtolength{\skip\footins}{1pc}
\renewcommand{\footnoterule}{%
    \vfill
    \kern -3pt\hrule width 0.4\columnwidth
    \vskip 6pt
}
\renewcommand{\@makefnmark}{\@thefnmark}
\renewcommand{\@makefntext}[1]{%
    \leftskip 0.5in
    \parindent -0.5in
    \@makefnmark.~#1
}
%    \end{macrocode}
%
% \subsection{Block quotation}
% \label{sec:block_quoatation}
%
% \begin{environment}{blockquote}
% The \citetitle{mlahb} dictates blockquotes be set flush a half-inch
% from the left margin with no extra space on the right.
% The existing \Denv{blockquote} environment is re-defined
% for this purpose.
%
% \changes{v0.2}{2019/04/28}{Countered unexplained vertical space
%	after environment}
%    \begin{macrocode}
\renewenvironment{blockquote}{%
    \list{}{\leftmargin 0.5in}
    \item[]
    \setlength{\parindent}{0.5in}
    \vspace{-\topsep}
}{%
    \endlist
    \vspace{-\topsep}
}
%    \end{macrocode}
% \end{environment}
%
% \subsection{Figures and tables}
% \label{sec:figures}
%
% The \citetitle{mlahb} doesn't specify much of anything about
% the actual formatting of figures or tables or their captions,
% so the following is mostly based on the package author's
% personal preference and observations.
%
% \begin{environment}{figure}
% \changes{v0.6}{2019/05/29}{Properly formatted}
% \begin{environment}{table}
% \changes{v0.6}{2019/05/29}{Properly formatted}
%
% Centered figures with margins the equivalent of one line of text
% seems customary and logical.
%
%    \begin{macrocode}
\ifMLA@figures
    \setlength{\floatsep}{\baselineskip}
    \setlength{\intextsep}{\baselineskip}
    \setlength{\textfloatsep}{\baselineskip}
    \g@addto@macro\@floatboxreset\centering
\fi
%    \end{macrocode}
%
% Thanks to a bug inherited from the \Dpkg{here} package
% which has remained unfixed since 1987\footnote{See the \cs{par}
% on p.\ 11, line 249 of \Dfile{ltfloat.dtx} from the \LaTeX\ kernel.},
% there is not only extra space after the figure but the inability to
% insert a figure within a paragraph.
% Miraculously, there is a fix for this\footnote{See David Carlisle's
% answer on \TeX\ \acs{SE}:
% \url{https://tex.stackexchange.com/a/310793}}.
%
%    \begin{macrocode}
\ifMLA@figures
    \renewcommand{\float@endH}{%
        \vspace{-12pt}
        \@endfloatbox\vskip\intextsep
        \if@flstyle\setbox\@currbox\float@makebox\columnwidth\fi
        \box\@currbox\vskip\intextsep\relax\@doendpe
    }
\fi
%    \end{macrocode}
%
% \end{environment}
% \end{environment}
% 
% \begin{environment}{caption}
% \changes{v0.6}{2019/05/29}{Properly formatted}
%
% Un-fancifying the caption is acheived using the
% \Dpkg{caption} package.
%
%    \begin{macrocode}
\ifMLA@figures
    \captionsetup{%
        font={normalfont},
        labelformat=simple,
        labelsep=period,
        position=bottom,
        aboveskip=6pt,
        belowskip=-10pt
    }
\fi
%    \end{macrocode}
%
% In the author's personal experience, most \ac{MLA}-style papers
% use \mentioned{Fig.} and not \mentioned{Figure}.
%
%    \begin{macrocode}
\ifMLA@figures
    \captionsetup[figure]{name=Fig.}
\fi
%    \end{macrocode}
%
% \end{environment}
%
% \subsection{Paper sections}
% \label{sec:paper_sections}
%
% \subsubsection{Paper}
% \label{sec:paper_env}
%
% \begin{environment}{paper}
% The main content; the body.
% This environment exists only for a logical division and does
% nothing special.
%
% \changes{v0.5}{2019/05/18}{Removed \cs{newpage}}
%    \begin{macrocode}
\newenvironment{paper}{}{}
%    \end{macrocode}
% \end{environment}
%
% \subsubsection{Endnotes}
% \label{sec:endnotes}
%
% \begin{environment}{notes}
% Endnotes can be typeset manually or with the supported
% \Dpkg{enotez} package\footnote{Refer to the \Dpkg{enotez}
% documentation for instructions.}.
%
% \changes{v0.2}{2019/04/28}{Added environment}
% \changes{v0.2}{2019/04/28}{Countered unexplained vertical space
%	after heading}
% \changes{v0.4}{2019/05/12}{Changed endnotes list type to
%	custom \Dlst{mlaendnotes} list}
% \changes{v0.4}{2019/05/12}{Changed default endnotes format
%	to \Dlst{mla}}
% \changes{v0.4}{2019/05/12}{Removed extra \cs{vspace}}
% \changes{v0.5}{2019/05/18}{Moved \cs{newpage} to beginning of environment}
%    \begin{macrocode}
\newenvironment{notes}{%
    \newpage
    \begin{noindent}
        \pdfbookmark[0]{Notes}{notes}
        \begin{center}Notes\end{center}
    \end{noindent}
}{}
%    \end{macrocode}
% \end{environment}
%
% To correctly format endnotes per common practice\footnote{According
% to the popular, oft-referenced \ac{OWL}: \citeurl{owlendnotes}.},
% a custom \Dlst{mlanotes} list type will be created.
% This is acheived with the \Dpkg{enumitem} package.
%
%    \begin{macrocode}
\ifMLA@notes
    \newlist{mlanotes}{description}{1}
    \setlist[mlanotes]{%
        parsep=0pt,
        itemsep=0pt,
        topsep=0pt,
        leftmargin=\parindent
    }
\fi
%    \end{macrocode}
%
% The following initializes the \Dpkg{enotez} package to use
% the \Dlst{mlanotes} list format.
%
%    \begin{macrocode}
\ifMLA@notes
    \DeclareInstance{enotez-list}{mla}{list}{%
        heading = {},
        format = \normalsize\normalfont,
        list-type = mlanotes
    }
    \setenotez{list-name={},list-style=mla,backref}
\fi
%    \end{macrocode}
%
% See section \ref{sec:footnotes} for footnotes.
%
% \subsubsection{Bibliography}
% \label{sec:bibliography}
%
% \begin{environment}{workscited}
% The bibliography can be typeset manually or with the supported
% \Dpkg{biblatex} package\footnote{Refer to the \Dpkg{biblatex}
% documentation for instructions.}.
%
% \changes{v0.2}{2019/04/28}{Countered unexplained vertical space
%	after heading}
% \changes{v0.5}{2019/05/18}{Moved \cs{newpage} to beginning of environment}
% \changes{v0.7}{2019/08/30}{Changed correction spacing from 16pt to 10pt}
%    \begin{macrocode}
\newenvironment{workscited}{%
    \newpage
    \begin{noindent}
        \pdfbookmark[0]{Works Cited}{workscited}
        \begin{center}Works Cited\end{center}
    \end{noindent}
    \vspace{-10pt} % XXX to counter unexplained space
}{}
%    \end{macrocode}
% \end{environment}
%
% The \citetitle{mlahb} prescribes a half-inch hanging indent
% on all bibliography entries.
% This is achieved by setting the \cs{bibhang} length
% defined by the \Dpkg{biblatex} package.
%
%    \begin{macrocode}
\setlength{\bibhang}{\parindent}
%    \end{macrocode}
%
% \appendix
% \section{Example usage}
% \label{sec:example_usage}
%
% Following is a basic \LaTeX\ document using the \Dcls{mla} class.
% The document is composed of a text file, \Dfile{mla-example.tex},
% and a \Dpkg{biblatex} bibliography file, \Dfile{mla-example.bib}.
%
% \subsection{\Dfile{mla-example.tex}}
% \label{sec:mla-example.tex}
%
% \verbatiminput{mla-example.tex}
%
% \subsection{\Dfile{mla-example.bib}}
% \label{sec:mla-example.bib}
%
% \verbatiminput{mla-example.bib}
%
% \Finale
\endinput
