% \iffalse meta-comment
% 
% Copyright 2012 Chad Parry
% 
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
% 
% \fi
% 
% \iffalse
% 
%<code>
%<code>\NeedsTeXFormat{LaTeX2e}
%<code>\ProvidesPackage{bibleref-lds}[2012/02/26 v1.0 LDS Bible reference style]
%<code>
%<code>\RequirePackage{bibleref-mouth}[2012/02/26]
%<code>\RequirePackage{ifthen}
%<code>\RequirePackage{hyperref}
%<code>
% 
%<*driver>
\documentclass{ltxdoc}
\usepackage{bibleref-lds}
\usepackage{afterpage}
\usepackage{longtable}
\usepackage[protrusion]{microtype}
\usepackage{hyperref}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\frenchspacing
\sloppy
\begin{document}
\DocInput{bibleref-lds.dtx}
\end{document}
%</driver>
% \fi
% 
% \CheckSum{421}
% 
% \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         \~}
% 
% \changes{v1.0}{2012/02/26}{Initial version}
% 
% \GetFileInfo{bibleref-lds.sty}
% 
% \title{
%     The \textsf{bibleref-lds} package%
%     \thanks{This document corresponds to \textsf{bibleref-mouth}~\fileversion, dated~\filedate.}
% }
% \author{Chad Parry \\ \href{mailto:spam@chad.parry.org}{\nolinkurl{spam@chad.parry.org}}}
% 
% \maketitle
% 
% \begin{abstract}
%     The \textsf{bibleref-lds} package is an extension of the \textsf{bibleref-mouth} package that supports references for the scriptures of The Church of Jesus Christ of Latter-day Saints (LDS).
%     To write a reference, the document should use the command \verb|\bibleref|\marg{reference}, exactly as with the stock \textsf{bibleref-mouth} package.
% \end{abstract}
% 
% \StopEventually{
%     \PrintIndex
% }
% 
% \let\origverbatim\verbatim
% \let\origendverbatim\endverbatim
% \renewenvironment{verbatim}{%
%     \origverbatim%
%     \microtypesetup{protrusion=false}%
% }{%
%     \origendverbatim%
% }
% \newcommand*{\callback}{\meta{\textbackslash{}callback}}
% 
% \section{Usage}
% 
% The usage is identical to that of the \textsf{bibleref-mouth} package, and so readers should first familiarize themselves with that documentation.
% For example, a hypertext reference like the following can be produced by the command below:
% \bibleref{2 Ne 9:28-29}.
%
% \begin{verbatim}
%\bibleref{2 Ne 9:28-29}
% \end{verbatim}
% 
% This package supports the canonical LDS scriptures, as listed in Table~\ref{books}.
% It also adds new aliases for some Bible books, as listed in Table~\ref{biblebooks}.
% The ``short abbreviation'' in the table is the abbreviation used on the thumb index of many editions.
% The table uses boldface for books that are changed from the existing \textsf{bibleref-mouth} abbreviation.
% Numbered books can be specified with Arabic or Roman numerals.
% Abbreviations may have an optional trailing period.
% All spaces are optional.
% For example, it is equally acceptable to say
% \verb|IINephi|,
% \verb|IINe.|,
% \verb|IINe|,
% \verb|2Nephi|,
% \verb|2Ne.|,
% \verb|2Ne|,
% \verb|II Nephi|,
% \verb|II Ne.|,
% \verb|II Ne|,
% \verb|2 Nephi|,
% \verb|2 Ne.|, or
% \verb|2 Ne|.
% 
% This package defines two new styles: \texttt{lds} and \texttt{lds.org}.
% The former uses the standard abbreviations for books according to the practice in the LDS church.
% The latter uses the same abbreviations, and additionally creates a link to the scriptures on the official LDS website.
% The \texttt{lds.org} style is set as the current style, although it can be overridden by a user.
% Users can customize the link text using the \hyperlink{provideldsdotorgstyle}{\cs{provideldsdotorgstyle}} command.
% 
% This package also renames one Bible book from ``Song of Songs'' to ``Song of Solomon.''
% 
% \makeatletter
% \brl@foreachbook@abbrv{\providebiblebook{abbrvname}}{.}{}{ }{\&}{\brm@number@arabicspace}
% \brl@foreachbook@thumb{\providebiblebook{thumbname}}{.}{}{ }{\&}{\brm@number@arabicspace}
% \newcommand{\bookrow}[2]{#2 & \brm@bookname{abbrvname}{#1} & \brm@bookname{thumbname}{#1}\\}
% \begin{table}[tbh]
% \caption{Supported Books}\label{books}
% \begin{center}
% \begin{tabular}{lp{0.33\textwidth}p{0.33\textwidth}}
% \bfseries Book & \bfseries Standard Abbreviation & \bfseries Short Abbreviation\\
% \brl@foreachbook@full{\bookrow}{ }{-}{}{\brm@number@arabicspace}
% \end{tabular}
% \end{center}
% \end{table}
% \makeatother
% 
% \makeatletter
% \brm@foreachbook@altabbrv{\providebiblebook{altabbrvasciiname}}{.}{\ }{\brm@number@arabicspaceascii}{\brm@number@arabicspaceascii}
% \brm@foreachbook@altabbrv{\providebiblebook{ldsabbrvasciiname}}{.}{\ }{\brm@number@arabicspaceascii}{\brm@number@arabicspaceascii}
% \brl@foreachbook@bible@abbrv{\providebiblebook{ldsabbrvasciiname}}{.}{\brm@number@arabicspaceascii}
% \brm@foreachbook@altabbrv{\providebiblebook{ldsabbrvname}}{.}{\ }{\brm@number@arabicspace}{\brm@number@arabicspace}
% \brl@foreachbook@bible@abbrv{\providebiblebook{ldsabbrvname}}{.}{\brm@number@arabicspace}
% \brm@foreachbook@altabbrv{\providebiblebook{ldsthumbasciiname}}{.}{\ }{\brm@number@arabicspaceascii}{\brm@number@arabicspaceascii}
% \brl@foreachbook@bible@thumb{\providebiblebook{ldsthumbasciiname}}{.}{\ }{\brm@number@arabicspaceascii}{\brm@number@arabicspaceascii}
% \brm@foreachbook@altabbrv{\providebiblebook{ldsthumbname}}{.}{\ }{\brm@number@arabicspace}{\brm@number@arabicspace}
% \brl@foreachbook@bible@thumb{\providebiblebook{ldsthumbname}}{.}{\ }{\brm@number@arabicspace}{\brm@number@arabicspace}
% \newcommand*{\comparebooks}[2]{\brm@ifsamestr{#1}{#2}{}{\bfseries}}
% \newcommand{\biblebookrow}[2]{\brm@ifnameexists{\brm@bookref{lds.org}{#1}}{\brm@bookname{fullname}{#1} & \comparebooks{\brm@bookname{altabbrvasciiname}{#1}}{\brm@bookname{ldsabbrvasciiname}{#1}}\brm@bookname{ldsabbrvname}{#1} & \comparebooks{\brm@bookname{altabbrvasciiname}{#1}}{\brm@bookname{ldsthumbasciiname}{#1}}\brm@bookname{ldsthumbname}{#1}\\}{}}
% \afterpage{
% \clearpage
% \begin{center}
% \begin{longtable}{p{0.34\textwidth}p{0.33\textwidth}p{0.33\textwidth}}
% \caption{Additional Abbreviations}\label{biblebooks}\\
% \bfseries Book & \bfseries Standard Abbreviation & \bfseries Short Abbreviation\\
% \endfirsthead
% \caption{Additional Abbreviations (continued)}\\
% \bfseries Book & \bfseries Standard Abbreviation & \bfseries Short Abbreviation\\
% \endhead
% \brm@foreachbook@full{\biblebookrow}{}{}{}{}{}{}{}{}
% \end{longtable}
% \end{center}
% \newpage
% }
% \makeatother
% 
% \section{Implementation}
% 
% All the internal macros have a name beginning with \verb|brl@|, which stands for \textsf{bibleref-lds}, so as to avoid polluting the global namespace.
% 
% \subsection{Book Names}
% 
% \begin{macro}{\brl@foreachbook@full}
% The full book names are accessible through \verb|\brl@foreachbook@full|\-\marg{callback}\-\marg{space}\-\marg{dash}\-\marg{bookof}\-\marg{booknumberstyle}
% The callback argument is expected to have the signature \callback\-\marg{book}\marg{bookname}.
% The number style argument is expected to be a function with the signature \callback\marg{number}.
%    \begin{macrocode}
\newcommand*{\brl@foreachbook@full}[5]{%
    #1{INephi}{#5{1}#4Nephi}%
    #1{IINephi}{#5{2}#4Nephi}%
    #1{Jacob}{#4Jacob}%
    #1{Enos}{#4Enos}%
    #1{Jarom}{#4Jarom}%
    #1{Omni}{#4Omni}%
    #1{WordsofMormon}{Words#2of#2Mormon}%
    #1{Mosiah}{#4Mosiah}%
    #1{Alma}{#4Alma}%
    #1{Helaman}{#4Helaman}%
    #1{IIINephi}{#5{3}#4Nephi}%
    #1{IVNephi}{#5{4}#4Nephi}%
    #1{Mormon}{#4Mormon}%
    #1{Ether}{#4Ether}%
    #1{Moroni}{#4Moroni}%
    #1{DoctrineandCovenants}{Doctrine#2and#2Covenants}%
    #1{OfficialDeclaration}{Official#2Declaration}%
    #1{Moses}{#4Moses}%
    #1{Abraham}{#4Abraham}%
    #1{JosephSmith-Matthew}{Joseph#2Smith#3Matthew}%
    #1{JosephSmith-History}{Joseph#2Smith#3History}%
    #1{ArticlesofFaith}{Articles#2of#2Faith}%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@foreachbook@abbrv}
% The abbreviated book names are accessible through \verb|\brl@foreachbook@abbrv|\-\marg{callback}\-\marg{standardperiod}\-\marg{optionalperiod}\-\marg{space}\-\marg{ampersand}\-\marg{booknumberstyle}
% The optional period argument is for books that are normally written without a period, but which could reasonably have an alias defined which does use a period.
% The callback argument is expected to have the signature \callback\-\marg{book}\marg{bookname}.
% The number style argument is expected to be a function with the signature \callback\marg{number}.
%    \begin{macrocode}
\newcommand*{\brl@foreachbook@abbrv}[6]{%
    #1{INephi}{#6{1}Ne#2}%
    #1{IINephi}{#6{2}Ne#2}%
    #1{Jacob}{Jacob}%
    #1{Enos}{Enos}%
    #1{Jarom}{Jarom}%
    #1{Omni}{Omni}%
    #1{WordsofMormon}{W#3#4of#4M#3}%
    #1{Mosiah}{Mosiah}%
    #1{Alma}{Alma}%
    #1{Helaman}{Hel#2}%
    #1{IIINephi}{#6{3}Ne#2}%
    #1{IVNephi}{#6{4}Ne#2}%
    #1{Mormon}{Morm#2}%
    #1{Ether}{Ether}%
    #1{Moroni}{Moro#2}%
    #1{DoctrineandCovenants}{D#3#5C#3}%
    #1{OfficialDeclaration}{O#3D#3}%
    #1{Moses}{Moses}%
    #1{Abraham}{Abr#2}%
    #1{JosephSmith-Matthew}{J#3S#3-M#3}%
    #1{JosephSmith-History}{J#3S#3-H#3}%
    #1{ArticlesofFaith}{A#3#4of#4F#3}%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@foreachbook@thumb}
% The shorter abbreviated book names are accessible through \verb|\brl@foreachbook@thumb|\-\marg{callback}\-\marg{period}\-\marg{space}\-\marg{ampersand}\-\marg{booknumberstyle}
% These are the abbreviations that are used on the thumb index of many editions.
% The optional period argument is for books that are normally written without a period, but which could reasonably have an alias defined which does use a period.
% The callback argument is expected to have the signature \callback\-\marg{book}\marg{bookname}.
% The number style argument is expected to be a function with the signature \callback\marg{number}.
%    \begin{macrocode}
\newcommand*{\brl@foreachbook@thumb}[6]{%
    #1{INephi}{#6{1}Ne#2}%
    #1{IINephi}{#6{2}Ne#2}%
    #1{Jacob}{Jac#2}%
    #1{Enos}{Eno#2}%
    #1{Jarom}{Jar#2}%
    #1{Omni}{Omn#2}%
    #1{WordsofMormon}{W#3#4Mn#3}%
    #1{Mosiah}{Msh#2}%
    #1{Alma}{Alma}%
    #1{Helaman}{Hel#2}%
    #1{IIINephi}{#6{3}Ne#2}%
    #1{IVNephi}{#6{4}Ne#2}%
    #1{Mormon}{Mor#2}%
    #1{Ether}{Eth#2}%
    #1{Moroni}{Mni#2}%
    #1{DoctrineandCovenants}{D#3#5C#3}%
    #1{OfficialDeclaration}{O#3D#3}%
    #1{Moses}{Mos#2}%
    #1{Abraham}{Abr#2}%
    #1{JosephSmith-Matthew}{J#3S#3-M#3}%
    #1{JosephSmith-History}{J#3S#3-H#3}%
    #1{ArticlesofFaith}{A#3#4of#4F#3}%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@foreachbook@bible@abbrv}
% The modified Bible book abbrevations are accessible through \verb|\brl@foreachbook@bible@abbrv|\-\marg{callback}\-\marg{period}\-\marg{epistlenumberstyle}
% These are the standard abbreviations that are used in official LDS publications, but that are different from the popularly accepted abbreviations in the \textsf{bibleref-mouth} package.
% The callback argument is expected to have the signature \callback\-\marg{book}\marg{bookname}.
% The number style argument is expected to be a function with the signature \callback\marg{number}.
%    \begin{macrocode}
\newcommand*{\brl@foreachbook@bible@abbrv}[3]{%
    #1{Exodus}{Ex#2}%
    #1{Esther}{Esth#2}%
    #1{Ecclesiastes}{Eccl#2}%
    #1{SongofSongs}{Song#2}%
    #1{Hosea}{Hosea}%
    #1{Obadiah}{Obad#2}%
    #1{Micah}{Micah}%
    #1{Nahum}{Nahum}%
    #1{Philippians}{Philip#2}%
    #1{IThessalonians}{#3{1}Thes#2}%
    #1{IIThessalonians}{#3{2}Thes#2}%
    #1{Titus}{Titus}%
    #1{James}{James}%
    #1{IJohn}{#3{1}Jn#2}%
    #1{IIJohn}{#3{2}Jn#2}%
    #1{IIIJohn}{#3{3}Jn#2}%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@foreachbook@bible@thumb}
% Some modified short Bible book abbrevations are accessible through \verb|\brl@foreachbook@bible@thumb|\-\marg{callback}\-\marg{period}\-\marg{space}\-\marg{booknumberstyle}\-\marg{epistlenumberstyle}
% These are the abbreviations that are used on the thumb index of many editions, and that are different from the popularly accepted abbreviations in the \textsf{bibleref-mouth} package.
% The callback argument is expected to have the signature \callback\-\marg{book}\marg{bookname}.
% The two number style arguments are expected to be functions with the signature \callback\marg{number}.
%    \begin{macrocode}
\newcommand*{\brl@foreachbook@bible@thumb}[5]{%
    #1{Exodus}{Exo#2}%
    #1{Deuteronomy}{Deu#2}%
    #1{Joshua}{Jos#2}%
    #1{Judges}{Jdg#2}%
    #1{Ruth}{Rth#2}%
    #1{Ezra}{Ezr#2}%
    #1{Esther}{Est#2}%
    #1{Psalms}{Psm#2}%
    #1{Proverbs}{Pro#2}%
    #1{Ecclesiastes}{Ecl#2}%
    #1{SongofSongs}{S#2#3S#2}%
    #1{Ezekiel}{Ezk#2}%
    #1{Joel}{Jol#2}%
    #1{Amos}{Amo#2}%
    #1{Obadiah}{Oba#2}%
    #1{Jonah}{Jna#2}%
    #1{Zephaniah}{Zph#2}%
    #1{Zechariah}{Zch#2}%
    #1{Matthew}{Mat#2}%
    #1{Mark}{Mrk#2}%
    #1{Luke}{Luk#2}%
    #1{John}{Jhn#2}%
    #1{Philippians}{Phl#2}%
    #1{IThessalonians}{#5{1}Ths#2}%
    #1{IIThessalonians}{#5{2}Ths#2}%
    #1{Philemon}{Phm#2}%
    #1{IJohn}{#5{1}Jhn#2}%
    #1{IIJohn}{#5{2}Jhn#2}%
    #1{IIIJohn}{#5{3}Jhn#2}%
}
%    \end{macrocode}
% \end{macro}
% 
% \subsection{Book Aliases}
% 
% Various book aliases are provided for all the book names, including versions of the full names, the abbreviated names, and the short abbreviated names.
% The book numbers can be done with either Arabic or Roman numerals.
% The abbreviations are supported both with and without periods.
% An ampersand can be represented as either \verb|&| or \verb|and|.
%    \begin{macrocode}
\brl@foreachbook@full{\providebiblebookalias}{}{-}{}%
    {\brm@number@upperromanascii}
\brl@foreachbook@full{\providebiblebookalias}{}{-}{}%
    {\brm@number@arabic}
\brl@foreachbook@abbrv{\providebiblebookalias}{}{}{}{&}%
    {\brm@number@upperromanascii}
\brl@foreachbook@abbrv{\providebiblebookalias}{}{}{}{&}%
    {\brm@number@arabic}
\brl@foreachbook@abbrv{\providebiblebookalias}{.}{.}{}{&}%
    {\brm@number@upperromanascii}
\brl@foreachbook@abbrv{\providebiblebookalias}{.}{.}{}{&}%
    {\brm@number@arabic}
\brl@foreachbook@abbrv{\providebiblebookalias}{}{}{}{and}%
    {\brm@number@upperromanascii}
\brl@foreachbook@thumb{\providebiblebookalias}{}{}{}{&}%
    {\brm@number@upperromanascii}
\brl@foreachbook@thumb{\providebiblebookalias}{}{}{}{&}%
    {\brm@number@arabic}
\brl@foreachbook@thumb{\providebiblebookalias}{.}{.}{}{&}%
    {\brm@number@upperromanascii}
\brl@foreachbook@thumb{\providebiblebookalias}{.}{.}{}{&}%
    {\brm@number@arabic}
\brl@foreachbook@thumb{\providebiblebookalias}{}{}{}{and}%
    {\brm@number@upperromanascii}
\brl@foreachbook@bible@abbrv{\providebiblebookalias}{}%
    {\brm@number@upperromanascii}
\brl@foreachbook@bible@abbrv{\providebiblebookalias}{}%
    {\brm@number@arabic}
\brl@foreachbook@bible@abbrv{\providebiblebookalias}{.}%
    {\brm@number@upperromanascii}
\brl@foreachbook@bible@abbrv{\providebiblebookalias}{.}%
    {\brm@number@arabic}
\brl@foreachbook@bible@thumb{\providebiblebookalias}{}{}%
    {\brm@number@upperromanascii}{\brm@number@upperromanascii}
\brl@foreachbook@bible@thumb{\providebiblebookalias}{}{}%
    {\brm@number@arabic}{\brm@number@arabic}
\brl@foreachbook@bible@thumb{\providebiblebookalias}{.}{}%
    {\brm@number@upperromanascii}{\brm@number@upperromanascii}
\brl@foreachbook@bible@thumb{\providebiblebookalias}{.}{}%
    {\brm@number@arabic}{\brm@number@arabic}
%    \end{macrocode}
% 
% \subsection{Formatted Book Names}
% 
% Several different forms of book names are created by default.
% These commands define the callback as \verb|\providebiblebook{|\meta{stylename}\verb|}|, which creates a version of each book name in the given style.
% The LDS book names are added to the existing styles that are defined in the \textsf{bibleref-mouth} package.
%    \begin{macrocode}
\brl@foreachbook@full{\providebiblebook{fullname}}{\ }{---}{}%
    {\brm@number@arabicspace}
\brl@foreachbook@abbrv{\providebiblebook{jerusalem}}{}{}{\ }{\&}%
    {\brm@number@arabicspace}
\brl@foreachbook@abbrv{\providebiblebook{anglosaxon}}{.}{}{\ }{\&}%
    {\brm@number@upperromanspace}
\brl@foreachbook@abbrv{\providebiblebook{JEH}}{.}{}{\ }{\&}%
    {\brm@number@arabicspace}
\brl@foreachbook@full{\providebiblebook{MHRA}}{\ }{---}{}%
    {\brm@number@scromanspace}
\brl@foreachbook@abbrv{\providebiblebook{NTG}}{}{}{\ }{\&}%
    {\brm@number@arabicspace}
\brl@foreachbook@abbrv{\providebiblebook{MLA}}{.}{}{\ }{\&}%
    {\brm@number@arabicspace}
\brl@foreachbook@abbrv{\providebiblebook{chicago}}{.}{}{\ }{\&}%
    {\brm@number@arabicspace}
%    \end{macrocode}
% 
% \subsection{Renamed Book}
% 
% The book commonly called ``Song of Songs'' is known in LDS publications as ``Song of Solomon.''
% That name is overridden for the existing styles that use it in the \textsf{bibleref-mouth} package.
%    \begin{macrocode}
\providebiblebook{fullname}{SongofSongs}{Song of Solomon}
\providebiblebook{text}{SongofSongs}{Song of Solomon}
%    \end{macrocode}
% 
% \subsection{LDS Style}
% 
% The style of book names used in LDS publications is similar to the existing styles but not identical to any of them, so a new format is defined here.
%    \begin{macrocode}
\brl@foreachbook@abbrv{\providebiblebook{lds}}%
    {.}{}{\ }{\&}{\brm@number@arabicspace}
\brm@foreachbook@altabbrv{\providebiblebook{lds}}%
    {.}{\ }{\brm@number@arabicspace}{\brm@number@arabicspace}
\brl@foreachbook@bible@abbrv{\providebiblebook{lds}}%
    {.}{\brm@number@arabicspace}
%    \end{macrocode}
% 
% The style of references used in LDS publications is similar to the existing styles but not identical to any of them, so a new one is defined here.
%    \begin{macrocode}
\providebiblestyle{lds}{\standardbiblestyle{lds}%
    {\ }{:}{; }{; }{, }{--}%
    {\brm@number@arabic}{\brm@number@arabic}%
    {#1}{#2}{#3}}
%    \end{macrocode}
% 
% \subsection{Text Style}
% 
% This style outputs a textual description of the reference.
% It overrides the corresponding style in the \textsf{bibleref-mouth} package, and adds support for LDS scriptures.
% The main difference is that not all LDS books are organized into chapters.
%
% \emph{This style depends on the non-expandable text style in the \textsf{bibleref-mouth} package, so it may not be used in an expandable context.}
% 
% \begin{macro}{\brl@formatchapter}
% This style normally outputs a chapter with a ``chapter'' label.
% However, there are a few exceptions.
% The Doctrine and Covenants is divided into sections.
% The Offical Declaraions and the Articles of Faith also do not have chapters.
%    \begin{macrocode}
\newcommand*{\brl@formatchapter}[1]{%
    \brm@ifsamestr{\thebook{#1}}{DoctrineandCovenants}{%
        section \brm@number@stomach@text{\thechapter{#1}}%
    }{%
        \brm@ifsamestr{\thebook{#1}}{OfficialDeclaration}{%
            \Numberstringnum{\thechapter{#1}}%
        }{%
            \brm@ifsamestr{\thebook{#1}}{ArticlesofFaith}{%
            }{%
                chapter \brm@number@stomach@text{\thechapter{#1}}%
            }%
        }%
    }%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@formatverse}
% This style normally outputs a verse with a ``verse'' label.
% However, there is one exception.
% The Articles of Faith are composed articles.
%    \begin{macrocode}
\newcommand*{\brl@formatverse}[1]{%
    \brm@ifsamestr{\thebook{#1}}{ArticlesofFaith}{%
        article \brm@number@stomach@text{\theverse{#1}}%
    }{%
        verse \brm@number@stomach@text{\theverse{#1}}%
    }%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@bkchsep}
% A book is normally separated from a chapter by a comma.
% However, there are a couple exceptions.
% The Official Declarations use a dash.
% The Articles of Faith don't have chapters, so they don't need a separator.
%    \begin{macrocode}
\newcommand*{\brl@bkchsep}[1]{%
    \brm@ifsamestr{\thebook{#1}}{OfficialDeclaration}{%
        ---%
    }{%
        \brm@ifsamestr{\thebook{#1}}{ArticlesofFaith}{%
        }{%
            ,\ %
        }%
    }%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@chvsep}
% A chapter is normally separated from a verse by a space.
% However, there is one exception.
% The Articles of Faith don't have a chapter, and so they use a comma, similar to the way other books have a book separator.
%    \begin{macrocode}
\newcommand*{\brl@chvsep}[1]{%
    \brm@ifsamestr{\thebook{#1}}{ArticlesofFaith}{%
        ,\ %
    }{%
        \ %
    }%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@text@filter}
% A filter for standard formats is \verb|\brl@text@filter|\-\marg{lastpassage}\marg{passage}\-\marg{infixseparators}\-\marg{prefixes}\-\marg{formatters}\-\marg{delegate}.
% It makes sure that the correct separators are used, which depend on the book name.
%    \begin{macrocode}
\newcommand*{\brl@text@filter}[6]{%
    #6%
        {#1}%
        {#2}%
        {\brm@packseparators{\brl@bkchsep{#2}}{\brl@chvsep{#2}}}%
        {#4}%
        {#5}%
}
%    \end{macrocode}
% \end{macro}
% 
% The style of book names needs to be extended to support LDS books.
%    \begin{macrocode}
\brl@foreachbook@full{\providebiblebook{text}}{\ }{---}{Book of }%
    {\brm@number@stomach@ordspace}
%    \end{macrocode}
% 
% The style of references uses the helpers in this section to format correct text descriptions of LDS references.
% No separators are given, because they would be overridden in \cs{brl@text@filter} anyway.
%    \begin{macrocode}
\providebiblestyle{text}{%
    \brm@standard@filtered%
        {}%
        {\brm@packpassage{,\ and\ }{,\ and\ }{,\ and\ }}%
        {\brm@packpassage{\ to\ }{\ to\ }{\ to\ }}%
        {\brm@packpassage%
            {\thebookname{text}}%
            {\brl@formatchapter}%
            {\brl@formatverse}}%
        {\brl@text@filter}%
        {#1}{#2}{#3}%
}
%    \end{macrocode}
% 
% \subsection{Linked Style}
% 
% This section defines a style that links to \url{http://www.lds.org/scriptures}.
% 
% First all the books must be associated with a valid URL path component.
%    \begin{macrocode}
\providebiblebook{lds.org}{Genesis}{gen}
\providebiblebook{lds.org}{Exodus}{ex}
\providebiblebook{lds.org}{Leviticus}{lev}
\providebiblebook{lds.org}{Numbers}{num}
\providebiblebook{lds.org}{Deuteronomy}{deut}
\providebiblebook{lds.org}{Joshua}{josh}
\providebiblebook{lds.org}{Judges}{judg}
\providebiblebook{lds.org}{Ruth}{ruth}
\providebiblebook{lds.org}{ISamuel}{1\_sam}
\providebiblebook{lds.org}{IISamuel}{2\_sam}
\providebiblebook{lds.org}{IKings}{1\_kgs}
\providebiblebook{lds.org}{IIKings}{2\_kgs}
\providebiblebook{lds.org}{IChronicles}{1\_chr}
\providebiblebook{lds.org}{IIChronicles}{2\_chr}
\providebiblebook{lds.org}{Ezra}{ezra}
\providebiblebook{lds.org}{Nehemiah}{neh}
\providebiblebook{lds.org}{Esther}{esth}
\providebiblebook{lds.org}{Job}{job}
\providebiblebook{lds.org}{Psalms}{ps}
\providebiblebook{lds.org}{Proverbs}{prov}
\providebiblebook{lds.org}{Ecclesiastes}{eccl}
\providebiblebook{lds.org}{SongofSongs}{song}
\providebiblebook{lds.org}{Isaiah}{isa}
\providebiblebook{lds.org}{Jeremiah}{jer}
\providebiblebook{lds.org}{Lamentations}{lam}
\providebiblebook{lds.org}{Ezekiel}{ezek}
\providebiblebook{lds.org}{Daniel}{dan}
\providebiblebook{lds.org}{Hosea}{hosea}
\providebiblebook{lds.org}{Joel}{joel}
\providebiblebook{lds.org}{Amos}{amos}
\providebiblebook{lds.org}{Obadiah}{obad}
\providebiblebook{lds.org}{Jonah}{jonah}
\providebiblebook{lds.org}{Micah}{micah}
\providebiblebook{lds.org}{Nahum}{nahum}
\providebiblebook{lds.org}{Habakkuk}{hab}
\providebiblebook{lds.org}{Zephaniah}{zeph}
\providebiblebook{lds.org}{Haggai}{hag}
\providebiblebook{lds.org}{Zechariah}{zech}
\providebiblebook{lds.org}{Malachi}{mal}
\providebiblebook{lds.org}{Matthew}{matt}
\providebiblebook{lds.org}{Mark}{mark}
\providebiblebook{lds.org}{Luke}{luke}
\providebiblebook{lds.org}{John}{john}
\providebiblebook{lds.org}{Acts}{acts}
\providebiblebook{lds.org}{Romans}{rom}
\providebiblebook{lds.org}{ICorinthians}{1\_cor}
\providebiblebook{lds.org}{IICorinthians}{2\_cor}
\providebiblebook{lds.org}{Galatians}{gal}
\providebiblebook{lds.org}{Ephesians}{eph}
\providebiblebook{lds.org}{Philippians}{philip}
\providebiblebook{lds.org}{Colossians}{col}
\providebiblebook{lds.org}{IThessalonians}{1\_thes}
\providebiblebook{lds.org}{IIThessalonians}{2\_thes}
\providebiblebook{lds.org}{ITimothy}{1\_tim}
\providebiblebook{lds.org}{IITimothy}{2\_tim}
\providebiblebook{lds.org}{Titus}{titus}
\providebiblebook{lds.org}{Philemon}{philem}
\providebiblebook{lds.org}{Hebrews}{heb}
\providebiblebook{lds.org}{James}{james}
\providebiblebook{lds.org}{IPeter}{1\_pet}
\providebiblebook{lds.org}{IIPeter}{2\_pet}
\providebiblebook{lds.org}{IJohn}{1\_jn}
\providebiblebook{lds.org}{IIJohn}{2\_jn}
\providebiblebook{lds.org}{IIIJohn}{3\_jn}
\providebiblebook{lds.org}{Jude}{jude}
\providebiblebook{lds.org}{Revelation}{rev}
\providebiblebook{lds.org}{INephi}{1\_ne}
\providebiblebook{lds.org}{IINephi}{2\_ne}
\providebiblebook{lds.org}{Jacob}{jacob}
\providebiblebook{lds.org}{Enos}{enos}
\providebiblebook{lds.org}{Jarom}{jarom}
\providebiblebook{lds.org}{Omni}{omni}
\providebiblebook{lds.org}{WordsofMormon}{w\_of\_m}
\providebiblebook{lds.org}{Mosiah}{mosiah}
\providebiblebook{lds.org}{Alma}{alma}
\providebiblebook{lds.org}{Helaman}{hel}
\providebiblebook{lds.org}{IIINephi}{3\_ne}
\providebiblebook{lds.org}{IVNephi}{4\_ne}
\providebiblebook{lds.org}{Mormon}{morm}
\providebiblebook{lds.org}{Ether}{ether}
\providebiblebook{lds.org}{Moroni}{moro}
\providebiblebook{lds.org}{DoctrineandCovenants}{dc}
\providebiblebook{lds.org}{OfficialDeclaration}{od}
\providebiblebook{lds.org}{Moses}{moses}
\providebiblebook{lds.org}{Abraham}{abr}
\providebiblebook{lds.org}{JosephSmith-Matthew}{js\_m}
\providebiblebook{lds.org}{JosephSmith-History}{js\_h}
\providebiblebook{lds.org}{ArticlesofFaith}{a\_of\_f}
%    \end{macrocode}
% 
% This style emits a URL that points to \url{http://scriptures.lds.org/}.
% There is a newer URL at \url{http://lds.org/scriptures/}, but with the older URL the anchors are placed better.
% The older URL will redirect to the newer URL.
%    \begin{macrocode}
\providebiblestyle{lds.org-url}{%
    http://scriptures.lds.org/%
    \thebookname{lds.org}{#1}/%
    \ifhaschapter{#1}{%
        \thechapter{#1}/%
        \ifhasverse{#1}{%
            \theverse{#1}%
        }{%
        }%
    }{%
    }%
    \brl@ldsdotorgurl@passage{#1}{#2}{-}%
    #3{
        \brl@ldsdotorgurl@list{\ifhasbook{#2}{#2}{#1}}%
    }{%
    }%
    \ifhasverse{#1}{%
        \#\theverse{#1}%
    }{%
    }%
}
%    \end{macrocode}
% 
% \begin{macro}{\brl@ldsdotorgurl@passage}
% A single portion of the URL for a passage is generated by \verb|\brl@ldsdotorgurl@passage|\-\marg{lastpassage}\-\marg{passage}\-\marg{separator}.
%    \begin{macrocode}
\newcommand*{\brl@ldsdotorgurl@passage}[3]{%
    \ifhasbook{#2}{%
        \ifsamebook{#1}{#2}{%
            \ifsamechapter{#1}{#2}{%
                \ifsameverse{#1}{#2}{%
                }{%
                    #3\theverse{#2}%
                }%
            }{%
                \brm@error{Links cannot span chapters}%
            }%
        }{%
            \brm@error{Links cannot span books}%
        }%
    }{%
    }%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@ldsdotorgurl@list}
% A portion of the URL for lists of verses is generated by \verb|\brl@ldsdotorgurl@passage|\-\marg{lastpassage}\-\marg{beginpassage}\-\marg{endpassage}\-\marg{list}.
%    \begin{macrocode}
\newcommand*{\brl@ldsdotorgurl@list}[4]{%
    \brl@ldsdotorgurl@passage{#1}{#2}{,}%
    \brl@ldsdotorgurl@passage{#2}{#3}{-}%
    #4{
        \brl@ldsdotorgurl@list{\ifhasbook{#3}{#3}{#2}}%
    }{%
    }%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\provideldsdotorgstyle}
% \hypertarget{provideldsdotorgstyle}{}
% Different users might wish to define links for a variety of styles.
% For example, a user might wish to have either full text or abbreviated text being linked.
% To provide this flexibility, this command will define a new link style.
% There are more than nine parameters that are needed, and \TeX only allows nine parameters to any one command.
% The workaround is to consume the first nine arguments in this command and then consume the rest of the arguments in \cs{brl@ldsdotorg@consumeargs}.
% The signature, including all parameters, is \verb|\provideldsdotorgstyle|\-\marg{stylename}\-\marg{bookstyle}\-\marg{bkchsep}\marg{chvsep}\-\marg{bksep}\marg{chsep}\marg{vsep}\-\marg{rangesep}\-\marg{chapterstyle}\-\marg{versestyle}.
% The user first gives the name for this new style, and then the name for the style of book names, and then the formatting for the link text.
% 
% This command is not able to take an arbitrary style name to use as the link text, like \cs{providebiblegatewaystyle} can, because the link text needs to be divided into multiple links for each chapter.
% Links to the LDS website cannot span chapter boundaries.
%    \begin{macrocode}
\newcommand*{\provideldsdotorgstyle}[8]{%
    \brl@ldsdotorg@consumeargs{#1}{#2}%
        {\brm@packseparators{#3}{#4}}%
        {\brm@packpassage{#5}{#6}{#7}}%
        {\brm@packpassage{#8}{#8}{#8}}%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@ldsdotorg@consumeargs}
% This command helps collect arguments by consuming five arguments from \cs{provideldsdotorgstyle} and two remaining arguments for the number formatters.
% It's signature is \verb|\brl@ldsdotorg@consumeargs|\-\marg{stylename}\-\marg{bookstyle}\-\marg{infixseparators}\-\marg{listseparators}\-\marg{rangeseparators}\-\marg{chapterstyle}\-\marg{versestyle}.
%    \begin{macrocode}
\newcommand*{\brl@ldsdotorg@consumeargs}[7]{%
    \brl@ldsdotorg@providestyle{#1}{#3}{#4}{#5}%
        {\brm@packpassage{\thebookname{#2}}%
        {\brm@formatchapter{#6}}%
        {\brm@formatverse{#7}}}%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@ldsdotorg@providestyle}
% The actual link style is created by the \verb|\brl@ldsdotorg@providestyle|\-\marg{stylename}\-\marg{infixseparators}\-\marg{listseparators}\-\marg{rangeseparators}\-\marg{formatters} command.
%    \begin{macrocode}
\newcommand*{\brl@ldsdotorg@providestyle}[5]{%
    \providebiblestyle{#1}{%
        \brl@ldsdotorg@style{#2}{#3}{#4}{#5}{##1}{##2}{##3}%
    }%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@ldsdotorg@style}
% The link style is generated by the \verb|\brl@ldsdotorg@style|\-\marg{infixseparators}\-\marg{listseparators}\-\marg{rangeseparators}\-\marg{formatters}\-\marg{beginpassage}\-\marg{endpassage}\-\marg{list} command.
%    \begin{macrocode}
\newcommand*{\brl@ldsdotorg@style}[7]{%
    \brl@ldsdotorg@range%
        {\brm@packpassage{}{}{}}%
        {#5}{#6}{#1}%
        {\brm@packpassage{}{}{}}%
        {#3}{#4}%
    #7{%
        \brl@ldsdotorg@list{#1}{#2}{#3}{#4}{\ifhasbook{#6}{#6}{#5}}%
    }{%
    }%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@ldsdotorg@list}
% Additional references in a list are generated by the \verb|\brl@ldsdotorg@list|\-\marg{infixseparators}\-\marg{listseparators}\-\marg{rangeseparators}\-\marg{formatters}\-\marg{lastpassage}\-\marg{beginpassage}\-\marg{endpassage}\-\marg{list} command.
%    \begin{macrocode}
\newcommand*{\brl@ldsdotorg@list}[8]{%
    \brl@ldsdotorg@range{#5}{#6}{#7}{#1}{#2}{#3}{#4}%
    #8{%
        \brl@ldsdotorg@list{#1}{#2}{#3}{#4}{\ifhasbook{#7}{#7}{#6}}%
    }{%
    }%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@number@empty}
% In order to output only the punctuation for a passage, there must be a way to suppress the output of the chapter and verse numbers.
% A special number formatter for this is \verb|\brl@number@empty|\-\marg{number}.
% It always outputs the empty string.
%    \begin{macrocode}
\newcommand*{\brl@number@empty}[1]{}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@ldsdotorg@range}
% Ranges of references are generated by the \verb|\brl@ldsdotorg@range|\-\marg{lastpassage}\-\marg{beginpassage}\-\marg{endpassage}\-\marg{infixseparators}\-\marg{listseparators}\-\marg{rangeseparators}\-\marg{formatters} command.
% It decides which punctuation would be necessary and then delegates to \cs{brl@ldsdotorg@href}.
% The punctuation is not straightforward, because sometimes a reference must be split into multiple separate links.
% Also, in between the links, there might be some punctuation that does not link anywhere.
% This can be done using the regular \cs{brm@standard@passage} helper.
% Sometimes the helper is invoked with no punctuation, so it outputs only a formatted passage.
% Sometimes it is invoked with empty number formatters and only punctuation, so it outputs only the delimiters around a passage.
%    \begin{macrocode}
\newcommand*{\brl@ldsdotorg@range}[7]{%
    \brl@ldsdotorg@href{#2}{#3}{%
        \brm@standard@passage{#1}{#2}%
            {\brm@packpassage{}{}{}}%
            {#5}%
            {\brm@packpassage%
                {\brl@number@empty}%
                {\brl@number@empty}%
                {\brl@number@empty}}%
    }{%
        \brm@standard@passage{#1}{#2}{#4}%
            {\brm@packpassage{}{}{}}%
            {#7}%
    }{%
        \brm@standard@passage{#2}{#3}%
            {\brm@packpassage{}{}{}}%
            {#6}%
            {\brm@packpassage%
                {\brl@number@empty}%
                {\brl@number@empty}%
                {\brl@number@empty}}%
    }{%
        \brm@standard@passage{#2}{#3}{#4}{\brm@packpassage{}{}{}}{#7}%
    }%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@ldsdotorg@href}
% A single range of references that has been checked by \cs{brl@ldsdotorg@range} is processed further by \verb|\brl@ldsdotorg@href|\-\marg{beginpassage}\-\marg{endpassage}\-\marg{prefix}\-\marg{formattedbeginpassage}\-\marg{rangeseparator}\-\marg{formattedendpassage}.
%    \begin{macrocode}
\newcommand*{\brl@ldsdotorg@href}[6]{%
    \ifsamebook{#1}{#2}{%
        \ifsamechapter{#1}{#2}{%
            \brl@ldsdotorg@samechapter{#1}{#2}{#3}{#4}{#5}{#6}%
        }{%
            \brl@ldsdotorg@spanchapter{#1}{#2}{#3}{#4}{#5}{#6}%
        }%
    }{%
        \brl@ldsdotorg@spanchapter{#1}{#2}{#3}{#4}{#5}{#6}%
    }%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@ldsdotorg@samechapter}
% If a reference is to a range of verses within one chapter, then the link is generated by \verb|\brl@ldsdotorg@samechapter|\-\marg{beginpassage}\-\marg{endpassage}\-\marg{prefix}\-\marg{formattedbeginpassage}\-\marg{rangeseparator}\-\marg{formattedendpassage}.
%    \begin{macrocode}
\newcommand*{\brl@ldsdotorg@samechapter}[6]{%
    #3%
    \href{%
        \brm@delegatestyle{lds.org-url}{#1}{#2}{\brm@nillist}%
    }{%
        #4#5#6%
    }%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\brl@ldsdotorg@spanchapter}
% If a reference is to a range of verses that are not within one chapter, then the links are generated by \verb|\brl@ldsdotorg@spanchapter|\-\marg{beginpassage}\-\marg{endpassage}\-\marg{prefix}\-\marg{formattedbeginpassage}\-\marg{rangeseparator}\-\marg{formattedendpassage}.
% The begin and end of the range have to be separate links because a single link cannot span chapters.
%    \begin{macrocode}
\newcommand*{\brl@ldsdotorg@spanchapter}[6]{%
    #3%
    \href{%
        \brm@delegatestyle{lds.org-url}{#1}%
            {\brm@packpassage{}{}{}}%
            {\brm@nillist}%
    }{%
        #4%
    }%
    #5%
    \ifhasbook{#2}{%
        \href{%
            \brm@delegatestyle{lds.org-url}{#2}%
            {\brm@packpassage{}{}{}}%
            {\brm@nillist}%
        }{%
            #6%
        }%
    }{%
    }%
}
%    \end{macrocode}
% \end{macro}
% 
% This style uses the standard LDS abbreviations and has links to the official LDS website.
% This is the default style if it has not been overridden by the user.
%    \begin{macrocode}
\provideldsdotorgstyle{lds.org}{lds}%
    {\ }{:}{; }{; }{, }{--}%
    {\brm@number@arabic}{\brm@number@arabic}
%    \end{macrocode}
% 
% This style uses the full names of books and has links to the offical LDS website.
% A user can choose this style with the following command.
% 
% \begin{verbatim}
%\setbiblestyle{lds.org-fullname}
% \end{verbatim}
% 
%    \begin{macrocode}
\provideldsdotorgstyle{lds.org-fullname}{fullname}%
    {\ }{:}{; }{;}{,}{--}%
    {\brm@number@arabic}{\brm@number@arabic}
%    \end{macrocode}
% 
% \subsection{Default Style}
% 
% The default style for documents that don't override it is the one that outputs the full name of the books.
%    \begin{macrocode}
\setbiblestyle{lds.org}
%    \end{macrocode}
% \Finale
\endinput