%        File: refs.sty
%      Author: H.A.Trujillo
%     Created: Tue Aug 11 09:00 PM 2015 E
% Last Change:      2 May 2016

\ProvidesPackage{refs} [2016/05/02 v2.6  Facilitates formatting of references]

%     This package formats references for footnotes.  It provides a
%     quick-and-dirty formatting tool -- simple but not particularly
%     flexible.
%
% COMMANDS:
% 
%   Five commands are defined,
%
%	  \jr		for journal references
%	  \book		for books
%	  \monogr	for monographs within a collection
%
%	  \book*	for works with >1 editor
%	  \monogr*	idem
%
%	
%
%     which take the following arguments:
%
%	 \jr  {auths} [title]  {journal} {year} {vol} {pp}.   
%
%       \book {auth}  
%             {BookTitle} [edition]  {Editor}   
%             {press}{city}{yr}{volpp}.
%
%     \monogr {auth}  
%             {MonographTitle}   
%             {CompilationTitle}[edition]{Editor} 
%             {press}{city}{yr}{volpp}.
%
%   If a required argument (ie "{...}") is left blank, the subsequent
%   punctuation will also be omitted.
%
%   The [title] and [edition number] arguments are optional.
%
%   The starred version of the \book and \monogr commands (\book* and
%   \monogr*) will print "Eds" rather than "Ed", for references with >1
%   editor.  The actual text may be changed within the option definitions.
%
%
% OPTIONS:
%
%   none:	My personal preferences.  These may not be considered sensible.
%   acs:	The formatting recommended by the ACS Style Guide.
%   old: 	1950-ish ACS styling.
%   chicago	
%   apa		
%   mla
%
%
% EXAMPLES:
%
%    \jr {Auber, J.}  {J. Edibl. Rsch.} {1994} {10} {25--27}.
%
%    \jr {Auber, J.} [The Riddle of the Babaghanoush]  
%    	  {J. Eggpl. Rsch.} {1994} {10} {25--27}.
%
%    \book {Hu, A.C.}    
%	  {Pepper: a sneezer's guide} [2nd] {}
%	  {Improbable press}{Toledo, OH}{1997}{vol 7, pp10--12}.
%
%    \monogr {Calvin} {Bats: the scourge of the universe}  
%	  {Calvin's School Years} [3rd] {Watterson, B.}
%	  {syndicated comics}{Calvinville, MO}{1990}{p20}.
%
%    \monogr* {Calvin} {Bats: the scourge of the universe}  
%	  {Calvin's School Years} [3rd] {Watterson, B.; Rosalyn}
%	  {syndicated comics}{Calvinville, MO}{1990}{p20}.
%
%
% NOTE:
%    If the xspace package is used, it should be loaded after refs.
%

%%%%% Global Defs %%%%%	<<<
\newcommand{\jr} [1] {\@ifnextchar[ {\@jr{#1}} {\@jr{#1}[]}}


\newcommand{\book}	 {%	Should "editor" be plural?
    \@ifstar 
      {\let \@Ed \@@Eds \@book}
      {\let \@Ed \@@Ed  \@book}
}
% book = monograph without an article-title
\newcommand{\@book}	[2]{%  Create a null [edition] field if omitted.
    \@ifnextchar[{\monogr@i{#1}{}{#2}} {\monogr@i{#1}{}{#2}[]}
}


\newcommand{\monogr}	 {%	Should "editor" be plural?
    \@ifstar 
      {\let \@Ed \@@Eds \@monogr}
      {\let \@Ed \@@Ed  \@monogr}
}
\newcommand{\@monogr} 	[3]{%	Create a null [edition] if field omitted.
  \@ifnextchar[{\monogr@i{#1}{#2}{#3}} {\monogr@i{#1}{#2}{#3}[]}
}

% The next two shorthands are intended to make the formatting
% statements more tidy.
\let\@f \frenchspacing
\let\@u	\unskip


% test if argument is empty; print with decoration if it is not.
%				 fields:  {item}  {format}  {before}{after}
\newcommand{\mt@test}	[4] {\ifx \relax #1\relax \else {#2{#3#1#4}}\fi}


% cooperate with \xspace (for \st, \nd, ...)
\@ifpackageloaded{xspace}{\xspaceaddexceptions{\,}}
%>>>

%%%%%  Default formatting  %%%%% <<<

  \def\@@Ed{Ed.}	\def\@@Eds{Eds.}	% Abbreviations for Editor field

  \def\@jr#1[#2]#3#4#5#6{%
    \mt@test{#1}{}	{}{\ \ }%	authors
    \mt@test{#2}{}	{}{. }%		article title
    \mt@test{#3}{\@f\emph}{}{ }%	journal
    \mt@test{#4}{\textbf}	{}{, }%	year
    \mt@test{#5}{\emph}	{}{, }%		volume
    \mt@test{#6}{}	{}{}%		pages
  }
  \def\monogr@i#1#2#3[#4]#5#6#7#8#9{%
    \mt@test{#1}{}	{} {\ \ }%		authors
    \mt@test{#2}{}	{\@f``}{'' in }%	monograph title
    \mt@test{#3}{\emph}	{\@f}{ }%		book/collection title
    \mt@test{#4}{}	{\@u, }{ edn.}%		edition number
    \mt@test{#5}{}	{\@u\ (}{, \@Ed)}\@u; %	collection editor
    \mt@test{#6}{}	{} {: }%		publisher
    \mt@test{#7}{}	{} {, }%		location
    \mt@test{#8}{}	{} {, }%		year
    \mt@test{#9}{}	{} {}%			vol, pp
  }%>>>

%%%%%  ACS formatting  %%%%% <<<
\DeclareOption{acs}{

  % \jr unchanged from default

  \def\monogr@i#1#2#3[#4]#5#6#7#8#9{%
    \mt@test{#1}{}	{} {\ \ }%		authors
    \mt@test{#2}{}	{\@f} {.\ In }%		monograph title
    \mt@test{#3}{\emph}	{\@f}{ }%		book/collection title
    \mt@test{#4}{}	{\@u\emph, }{\,ed.}%	edition number
    \mt@test{#5}{}	{\@u; }{, \@Ed}\@u; %	collection editor
    \mt@test{#6}{}	{} {: }%		publisher
    \mt@test{#7}{}	{} {, }%		location
    \mt@test{#8}{}	{} {}%			year
    \mt@test{#9}{}	{; } {}%		vol, pp
  }
}%>>>

%%%%%  Chicago  %%%%% <<<
\DeclareOption{chicago}{

  \def\@@Ed{ed.}	\def\@@Eds{eds.}	% Abbreviations for Editor field

  \def\@jr#1[#2]#3#4#5#6{%
    \mt@test{#1}{}		{}{, }%		authors
    \mt@test{#2}{}		{``}{'' }%	article title
    \mt@test{#3}{\@f\emph}	{}{, }% 	journal
    \mt@test{#5}{\emph}		{}{}%		volume
    \mt@test{#4}{}		{(}{)}: %	year
    \mt@test{#6}{}		{}{}%		pages
  }
  \def\monogr@i#1#2#3[#4]#5#6#7#8#9{%
    \mt@test{#1}{}	{} {, }%		authors
    \mt@test{#2}{}	{\@f``} {'' in }%	monograph title
    \mt@test{#3}{\emph}	{\@f}{ }%		collection title
    \mt@test{#4}{}	{\@u\emph, }{ ed.\ }%	edition number
    \mt@test{#5}{}	{\@Ed~}{ }%		collection editor
    \mt@test{#6}{}	{(} {: }%		publisher
    \mt@test{#7}{}	{} {, }%		location
    \mt@test{#8}{}	{} {), }%		year
    \mt@test{#9}{}	{} {}%			vol, pp
  }
}%>>>

%%%%%  APA (sort of)  %%%%% <<<
\DeclareOption{apa}{

  \def\@jr#1[#2]#3#4#5#6{%
    \mt@test{#1}{}		{}{ }%		authors
    \mt@test{#4}{}		{(}{)}. %	year
    \mt@test{#2}{}		{}{. }%		article title
    \mt@test{#3}{\@f\emph}	{}{, }% 	journal
    \mt@test{#5}{\emph}		{}{, }%		volume
    \mt@test{#6}{}		{}{}%		pages
  }

  \def\monogr@i#1#2#3[#4]#5#6#7#8#9{%
    \mt@test{#1}{}	{} { }%			authors
    \mt@test{#8}{}	{(} {) }%		year
    \mt@test{#2}{}	{``}{'' in }%		monograph title
    \mt@test{#3}{\emph}	{\@f}{}%		collection title
    \mt@test{#4}{}	{ (}{ ed.)}%		edition
    \mt@test{#5}{}	{ (}{, \@Ed)}.\ %	collection editor
    \mt@test{#9}{}	{ (}{).\ }%		vol, pp
    \mt@test{#7}{}	{} {: }%		location
    \mt@test{#6}{}	{} {}%			publisher
  }
}%>>>

%%%%%  MLA  %%%%% <<<
\DeclareOption{mla}{

  \def\@jr#1[#2]#3#4#5#6{%
    \mt@test{#1}{}		{}{ }%		authors
    \mt@test{#2}{}		{``}{.'' }%	article title
    \mt@test{#3}{\@f\emph}	{}{ }% 		journal
    \mt@test{#5}{\emph}		{}{}%		volume
    \mt@test{#4}{}		{(}{)}: %	year
    \mt@test{#6}{}		{}{}%		pages
  }
  \def\monogr@i#1#2#3[#4]#5#6#7#8#9{%
    \mt@test{#1}{}	{} { }%			authors
    \mt@test{#2}{}	{``}{.'' }%		monograph title
    \mt@test{#3}{\emph}	{\@f}{.\ }%		collection title
    \mt@test{#4}{}	{}{ ed.\ }%		edition number
    \mt@test{#5}{}	{\@Ed~}{, }%		collection editor
    \mt@test{#6}{}	{} {: }%		publisher
    \mt@test{#7}{}	{} {, }%		location
    \mt@test{#8}{}	{} {, }%		year
    \mt@test{#9}{}	{} {}%			vol, pp
  }
}%>>>

%%%%%  Old-Style formatting:  Nostalgia.  %%%%% <<<
\DeclareOption{old}{

  \def\@jr#1[#2]#3#4#5#6{%
    \mt@test{#1}{}		{}{; \ }%	authors
    \mt@test{#2}{}		{``}{'' }%	article title
    \mt@test{#3}{\@f\emph}	 {} {, }% 	journal
    \mt@test{#5}{\emph}		 {} {, }%	volume
    \mt@test{#6}{}		 {} { }%	pages
    \mt@test{#4}{}		 {(}{)}%	year
  }
  \def\monogr@i#1#2#3[#4]#5#6#7#8#9{%
    \mt@test{#1}{}	{} {\ \ }%		authors
    \mt@test{#2}{}	{\@f``} {'' in }%	monograph title
    \mt@test{#3}{\emph}	{\@f}{ }%		collection title
    \mt@test{#4}{}	{\@u, }{ edn.\ }%	edition number
    \mt@test{#5}{}	{(}{, \@Ed)}\@u; %	collection editor
    \mt@test{#6}{}	{} {: }%		publisher
    \mt@test{#7}{}	{} {, }%		location
    \mt@test{#8}{}	{(}{) }%		year
    \mt@test{#9}{}	{} {}%			vol, pp
  }
}%>>>

\DeclareOption{none}{} %<<<

%>>>
\ProcessOptions\relax

% v2.5	7sep15	tests whether xspace loaded
%		examples at top of file tidied somewhat
% v2.6	2may16	\mt@test now within a group, to limit scope of \frenchspacing.

% vim: sw=2

