MAJOR modifications to accomodate natbib
[latex-mlastyle.git] / mlastyle.dtx
index 252e96ac7a64a5f3777130c1f79d20a37501be74..44a745eebd6d0039c4bbc7b74556a1d2e0c6b461 100644 (file)
@@ -69,8 +69,14 @@ Schlegl",
   \addtolength{\textwidth}{-1in}
   \addtolength{\headwidth}{-1in}
 \else
+  \IfFileExists{natbib.sty}{
+    \usepackage{natbib}
+    \citeindextrue
+    \bibpunct{[}{]}{,}{n}{}{,}%{
+    \bibliographystyle{plainnat}}
+    {\bibliographystyle{plain}}
+  \IfFileExists{url.sty}{\usepackage{url}}{}
   \usepackage[compat]{mlastyle}
-  \bibliographystyle{plain}
   %\addtolength{\headsep}{-5pt}
   %\addtolength{\headheight}{-12pt}
   %\addtolength{\topmargin}{-17pt}
@@ -81,6 +87,8 @@ Schlegl",
 {\newcommand{\examp}[2][]{{\let\emph\uline\fontfamily{ptm}\selectfont##2}##1}}%
 {\newcommand{\examp}[2][]{``##2##1''}}
 
+{\makeatletter\gdef\NAT@MLA#1{#1}\gdef\NAT@idxtxt
+{\expandafter\NAT@MLA\NAT@name\ \NAT@open\NAT@num\NAT@close}}
 \EnableCrossrefs
 \CodelineIndex
 \RecordChanges
@@ -151,8 +159,10 @@ Schlegl",
 % \DoNotIndex{\addtolength}
 % \DoNotIndex{\advance}
 % \DoNotIndex{\baselineskip}
+% \DoNotIndex{\bibpreamble,\bibpunct,\bibsep}
 % \DoNotIndex{\begin}
 % \DoNotIndex{\bfseries}
+% \DoNotIndex{\bgroup}
 % \DoNotIndex{\c@enumiv}
 % \DoNotIndex{\catcode}
 % \DoNotIndex{\centering}
@@ -187,6 +197,7 @@ Schlegl",
 % \DoNotIndex{\ifcase}
 % \DoNotIndex{\ifmlastyle@bibstyle}
 % \DoNotIndex{\ifmlastyle@format}
+% \DoNotIndex{\ifmlastyle@pages}
 % \DoNotIndex{\ifmlastyle@papersize}
 % \DoNotIndex{\ifmlastyle@style}
 % \DoNotIndex{\ifmlastyle@times}
@@ -208,6 +219,7 @@ Schlegl",
 % \DoNotIndex{\listparindent}
 % \DoNotIndex{\makeenmark}
 % \DoNotIndex{\mbox}
+% \DoNotIndex{\ml@}
 % \DoNotIndex{\mlastyle@bibstylefalse}
 % \DoNotIndex{\mlastyle@bibstyletrue}
 % \DoNotIndex{\mlastyle@cite}
@@ -216,6 +228,8 @@ Schlegl",
 % \DoNotIndex{\mlastyle@formattrue}
 % \DoNotIndex{\mlastyle@instructor}
 % \DoNotIndex{\mlastyle@intbib}
+% \DoNotIndex{\mlastyle@pagesfalse}
+% \DoNotIndex{\mlastyle@pagestrue}
 % \DoNotIndex{\mlastyle@papersizefalse}
 % \DoNotIndex{\mlastyle@papersizetrue}
 % \DoNotIndex{\mlastyle@qspread}
@@ -261,12 +275,12 @@ Schlegl",
 % \DoNotIndex{\sloppy}
 % \DoNotIndex{\space}
 % \DoNotIndex{\string}
-% \DoNotIndex{\sw@llow}
 % \DoNotIndex{\the}
 % \DoNotIndex{\thebibliography}
 % \DoNotIndex{\thepage}
 % \DoNotIndex{\topsep}
 % \DoNotIndex{\usecounter}
+% \DoNotIndex{\unskip}
 % \DoNotIndex{\vskip}
 % \DoNotIndex{\write}
 % \DoNotIndex{\year}
@@ -451,7 +465,7 @@ Schlegl",
 % |\cite|\oarg{pages}|{|\meta{marker
 % 1}\texttt{,}\penalty\exhyphenpenalty\meta{marker 2}\ldots|}|; however, page
 % numbers can currently be specified only for the last referenced source.
-% To work around this limitation, use |\citealt|, explained below.
+% To work around this limitation, use |\citealp|, explained below.
 %
 % Three additional citation commands are provided, all of which take the
 % same arguments as |\cite|.  To omit the author information from the
@@ -459,10 +473,10 @@ Schlegl",
 % citations---those of the format \examp{(qtd. in Pope
 % \pageref{sec:italics})}---can be
 % created with \DescribeMacro{\citeindirect}|\citeindirect|.  Finally, the
-% parentheses are omitted by \DescribeMacro{\citealt}|\citealt|.  This was
+% parentheses are omitted by \DescribeMacro{\citealp}|\citealp|.  This was
 % intended for use in cross references, but it can also help in citing
 % multiple works.  The result of
-% |(\citealt[42]{texbook}|\texttt{; }|\citealt[69]{latexdps})|
+% |(\citealp[42]{texbook}|\texttt{; }|\citealp[69]{latexdps})|
 % would be something like \examp[.]{(Knuth 42; Lamport 69)}
 %
 % \subsubsection{Using {\rm \BibTeX}} \label{sec:bibtex}
@@ -614,20 +628,22 @@ Schlegl",
 % Define the surname, along with an obsolete synonym.
 %    \begin{macrocode}
 \def\surname#1{\gdef\mlastyle@surname{#1}}
-\def\mlastyle@surname{\def\sw@llow##1 {}\expandafter\sw@llow\@author}
+\def\mlastyle@surname{\def\ml@##1 ##2,##3@@{##2}%
+  \expandafter\ml@\@author, ,@@}
 \let\lastname\surname
 %    \end{macrocode}
 % \end{macro}
 % \subsection{Formatting}
 % Formatting is done if the \Lopt{mla} or \Lopt{format} option is set.
+%    \begin{macrocode}
+\ifmlastyle@format
+%    \end{macrocode}
 % \begin{macro}{\mlastyle@i}
+% This is the standard MLA format indent.
 %    \begin{macrocode}
   \newdimen\mlastyle@i \mlastyle@i=.5in
 %    \end{macrocode}
 % \end{macro}
-%    \begin{macrocode}
-\ifmlastyle@format
-%    \end{macrocode}
 % \subsubsection{Macros}
 % \begin{macro}{\maketitle}
 % |\maketitle| generates a heading in MLA format.
@@ -772,6 +788,12 @@ Schlegl",
   \def\@listvi{\leftmargin\leftmarginvi
   \parsep\z@\itemsep\z@\topsep -3\p@\relax}
 %    \end{macrocode}
+% Only one space after colons.
+%    \begin{macrocode}
+\ifnum\the\sfcode`\:=2000
+  \sfcode`\:=1999
+\fi
+%    \end{macrocode}
 % \subsubsection{Header}
 % The last name and page number appear on every page, including the first.
 %    \begin{macrocode}
@@ -815,6 +837,12 @@ Schlegl",
 % The definition of |\thebibliography| varies depending on the document
 % class.
 %    \begin{macrocode}
+\ifx\@undefined\url{
+  \catcode`/=13
+    \gdef\url{\bgroup\catcode`/=13
+    \let/\slash\mlastyle@url}
+    \gdef\mlastyle@url#1{#1\egroup}
+}\fi
 \ifx\@undefined\citet
   \@ifundefined{chapter}
 %    \end{macrocode}
@@ -828,7 +856,6 @@ Schlegl",
         \itemindent-\leftmargin
         \def\newblock{}
         \usecounter{enumiv}
-        %\catcode`/=13\global\let/=\mlastyle@slash
         \sloppy%\sfcode`\.=\@m
       }}
 %    \end{macrocode}
@@ -842,7 +869,6 @@ Schlegl",
         \itemindent-\leftmargin
         \def\newblock{}
         \usecounter{enumiv}
-        %\catcode`/=13\let/=\mlastyle@slash
         \sloppy%\sfcode`\.=\@m
       }}
 %    \end{macrocode}
@@ -859,21 +885,39 @@ Schlegl",
 \fi % \ifmlastyle@format
 %    \end{macrocode}
 % \subsection{Style}
+% \begin{macro}{\bibstyle@mlastyle}
 % This first block is the beginnings of an implementation for
 % \package{natbib}.
 %    \begin{macrocode}
-\newcommand{\bibstyle@mlastyle}{\bibpunct[ ]{(}{)}{;}{a}{,}{;}
-\@ifundefined{chapter}
-{\gdef\refname{Works Cited}}
-{\gdef\bibname{Works Cited}}}
+\def\mlastyle@notitle
+  { \ \ \ \ \unskip\unskip\unskip\unskip\unskip\unskip}
+\newif\ifmlastyle@pages
+\renewcommand\NAT@citetp
+{\@ifnextchar[{\mlastyle@pagestrue\NAT@@citetp}%
+  {\mlastyle@pagesfalse\NAT@@citetp[]}}
+\newcommand{\bibstyle@mlastyle}{%
+  \bibpunct[\mlastyle@space]{\mlastyle@brack(}{\mlastyle@brack)}%
+    {;}{a}{\mlastyle@comma}{,}
+  \gdef\mlastyle@brack##1{\ifx\NAT@date\mlastyle@notitle
+    \ifmlastyle@pages ##1\else\ifNAT@swa\ifnum
+    \NAT@ctype=0 ##1\else\unskip\fi\else\unskip\fi\fi\else ##1\fi}
+  \gdef\mlastyle@comma{\ifx\NAT@date\mlastyle@notitle\else,\fi}
+  \gdef\mlastyle@space{\ifx\NAT@date\mlastyle@notitle{}\else{} \fi}
+  \gdef\mlastyle@space{\ifx\NAT@date\mlastyle@notitle
+    \ifnum\NAT@ctype<2
+      \ifNAT@par\ifNAT@swa{} \fi\else{} \fi\fi\else{} \fi}
+  \@ifundefined{chapter}
+  {\gdef\refname{Works Cited}}
+  {\gdef\bibname{Works Cited}}}
 %    \end{macrocode}
+%\end{macro}
 % \begin{macro}{\cite}
-% \begin{macro}{\citealt}
+% \begin{macro}{\citealp}
 % ^^A\begin{macro}{\citepage}
 % ^^A\begin{macro}{\citequote}
 % The following macros, combined with \file{mlastyle.bst}, provide
 % for a bibliography in MLA style.  Note that the definition of |\cite|,
-% |\citealt|, etc.\ vary depending on the options passed to
+% |\citealp|, etc.\ vary depending on the options passed to
 % \package{mlastyle}.
 %
 % \begin{macro}{\mlastyle@intcite}
@@ -887,7 +931,7 @@ Schlegl",
 % This macro does nothing.  Depending on the options, either |\citeC| or
 % |\citeM| and its ilk will utilize it.
 %    \begin{macrocode}
-\newcommand{\mlastyle@relax}[2][]{}
+\newcommand{\mlastyle@relax}[2][]{\unskip}
 %    \end{macrocode}
 % \end{macro}
 % \subsubsection{MLA Style}
@@ -901,9 +945,9 @@ Schlegl",
   \def\@cite#1#2{(#1\if@tempswa{} #2\fi)}
   \def\cite{\def\@cite##1##2{(##1\if@tempswa{}
     ##2\fi)}\mlastyle@intcite}
-  \def\citealt{\def\@cite##1##2{##1\if@tempswa{}
+  \def\citealp{\def\@cite##1##2{##1\if@tempswa{}
     ##2\fi}\mlastyle@intcite}
-  \let\citeN\citealt
+  \let\citeN\citealp
   \def\citeM{\def\@cite##1##2{ (##1\if@tempswa{}
     ##2\fi)}\mlastyle@intcite}
   \def\citepage{\def\@cite##1##2{\if@tempswa(##2)\fi}\mlastyle@intcite}
@@ -970,10 +1014,11 @@ Schlegl",
   {\renewcommand\bibname{Works Cited}}
 \else
   \let\cite\citep
-  \newcommand\citepage[2][]{\citetext{#2}}
+  \newcommand\citepage[2][]{\citeyearpar[#1]{#2}}
   \newcommand\citepageM[2][]{ \citetext{#2}}
-  \newcommand\citeindirect[2][]{\citep[#1][qtd. in]{#2}}
-  \newcommand\citeindirectM[2][]{ \citep[#1][qtd. in]{#2}}
+  \newcommand\citeindirect[2][]{\citep[qtd.\ in][#1]{#2}}
+  \newcommand\citeindirectM[2][]{ \citep[qtd.\ in][#1]{#2}}
+  \let\citeN\citealp
   \let\citeC\mlastyle@relax
 \fi
 %    \end{macrocode}
@@ -998,11 +1043,16 @@ Schlegl",
 % set.
 %    \begin{macrocode}
 \else
-  \newcommand{\mlastyle@cite}[2][]{\@tempswafalse\@citex[]{#2}}
+  \ifx\@undefined\citet
+    \newcommand{\mlastyle@cite}[2][]{\@tempswafalse\@citex[]{#2}}
+    \newcommand{\citeC}[2][]{~\@tempswafalse\@citex[]{#2}}
+  \else
+    \newcommand{\mlastyle@cite}[2][]{\citep[]{#2}}
+    \def\citeC{ \citep}
+  \fi
   \let\cite\mlastyle@cite
   \let\citepage\mlastyle@cite
   \let\citeindirect\mlastyle@cite
-  \newcommand{\citeC}[2][]{~\@tempswafalse\@citex[]{#2}}
   \let\citeM\mlastyle@relax
   \let\citepageM\mlastyle@relax
   \let\citeindirectM\mlastyle@relax