\documentclass{article}
\usepackage[english]{betababel}
\usepackage{hyperref}

\title{Documentation for the {\sf betababel.sty} package}
\author{Felix G. Berkemeier\thanks{ Questions, commentary and bug reports to \texttt{felix.berkemeier@gmx.de} please.}}
\date{2005/07/10}


\begin{document}
\maketitle
\begin{abstract}
The \textsf{betababel} package extends the \texttt{polutonikogreek} option of the \textsf{babel} package. It provides the possibility to directly type or paste in ancient Greek texts with diacritical characters coded by the common Beta Code convention.

This file documents version 0.5 of \textsf{betababel.sty}.
\end{abstract}

\tableofcontents
\section{Introduction}
Although the \LaTeX{} typesetting system is often used especially for its capabilities of displaying fancy formulas in scientific texts, there are plenty of other possible uses. Whoever wants a smooth layout made (almost) by itself freeing time to care for the content, not for its form, would use \LaTeX, \emph{if} other specific needs are satisfied as well. One (maybe very) specific, but nevertheless requested need is the possibility to type ancient Greek texts. These texts require not only the Greek alphabet, but special diacritics. As those are usually not supported as input characters, there exist some transliteration codes to describe the Greek characters and diacritics by representing them by Latin characters and ASCII signs. One very common code has been defined by the \textsc{Thesaurus Linguae Graecae}; it's called Beta Code. (For complete documentation of the code, visit \url{http://www.tlg.uci.edu/}.)

The Beta Code assigns to every Greek letter one Latin letter, diacritical characters are coded by braces, slashes and other signs (see table below). All Latin input letters, uppercase or lowercase, are handled as lowercase; Greek uppercase letters are coded by an asterisk prefix. E.g.: *w = \bcode{*w} (uppercase omega). To place one or more special characters over (or in case of the iota subscript under) a Greek letter, they have to directly follow the letter to be placed on. There is an order to be respected in placing the diacritics: First comes (if there is) the spiritus or the diaeresis, then the accent and, finally, a iota subscriptum, eventually. Caution: For some reason (possibly because of the prefixing of diacritics of uppercase Greek letters), if the letter to whom the diacritics belong is an uppercase letter, the diacritical signs have to be placed between the asterisk and the letter, i.e. \emph{before} the letter! E.g.: *)/a = \bcode{*)/a} (uppercase alpha with smooth breathing and acute accent); a)/ = \bcode{a)/} (lowercase alpha with smooth breathing and acute accent).

{\paragraph{Code table}
\begin{center}
\begin{tabular}{llllllllllll}
a & b & g & d & e & z & h & q & i & k & l & m\\
\bcode{a} & \bcode{b} & \bcode{g} & \bcode{d} & \bcode{e} & \bcode{z} & \bcode{h} & \bcode{q} & \bcode{i} & \bcode{k} & \bcode{l} & \bcode{m}\\[.8em]
n & c & o & p & r & s & t & u & f & x & y & w\\
\bcode{n} & \bcode{c} & \bcode{o} & \bcode{p} & \bcode{r} & \bcode{s} & \bcode{t} & \bcode{u} & \bcode{f} & \bcode{x} & \bcode{y} & \bcode{w}
\end{tabular}
\end{center}}

Though, for instance, the semicolon `\texttt{;}' has another meaning in Greek than in Latin, it is still the same sign and thus the punctuation remains almost unchanged in Beta Code with the exception  of the `\texttt{:}' that becomes `\bcode{:}'.

\pagebreak[4]
{\paragraph{Code for the diacritics}
\begin{center}
\begin{tabular}{rc}
smooth breathing (spiritus lenis) & \verb')'\\
rough breathing (spiritus asper) & \verb'('\\
diaeresis & \verb'+'\\[.8em]
acute accent & \verb'/'\\
grave accent & \verb'\'\\
circumflex accent & \verb'='\\[.8em]
iota subscriptum & \verb'|'\\
\end{tabular}
\end{center}}

In section \ref{usage} you can find some examples for Beta Code text and the usage of \textsf{betababel}.

\section{Betababel}
\subsection{Loading the package}
The \textsf{betababel} package is an extension to the widely used \textsf{babel} package that, therefore, has to be correctly installed in order to enable {\sf betababel} to work properly. To use \textsf{betababel} the \textsf{betababel.sty} file has to be in a directory searched by your \LaTeX{} system (if you don't know where this is, just copy the file into the directory you'll save your \LaTeX{} document) and your document must contain the line \verb'\usepackage['\textit{language option(s)}\verb']{betababel}' in its preamble. The possible language options are exactly the same as those of the \textsf{babel} package. By default \textsf{betababel} uses the \texttt{polutonikogreek} option of the \textsf{babel} package. If your text is written in another language, you should give the right option; for instance for a mostly English text that contains some ancient Greek passages, type: \verb'\usepackage[english]{betababel}'.

Since \textsf{betababel} internally loads the \textsf{babel} package by itself, there \emph{must not} be a \verb'\usepackage[...]{babel}' command in your document preamble. If, for instance, you had a \verb'\usepackage[english,german]{babel}' in your document, just replace it by \verb'\usepackage[english,german]{betababel}'.

Some of \textsf{betababel}'s extended functionality (\frenchspacing e.\ g. \nonfrenchspacing all the characters whose Beta Code uses the hash character `\#' --- added in version v0.5) requires Claudio Beccari's \textsf{teubner.sty} package. You can find it at \url{http://www.ctan.org/tex-archive/macros/latex/contrib/teubner/}. While \textsf{betababel} can be run without \textsf{teubner}, it than lacks some of its features.

\subsection{Usage and examples}
\label{usage}
The \textsf{betababel} package provides two slightly different ways to insert Beta Code input into your \LaTeX{} document. You can enclose the Beta Code in an evironment using \verb'\begin{betacode}' and \verb'\end{betacode}' or you can pass the Beta Code through the argument of the \verb'\bcode{}' command.

\subsubsection{The \texttt{betacode} environment}
The \texttt{betacode} environment inserts some vertical space before and after the Beta Code input. The amount of this space can be set through the length \verb'\betaskip'. All paragraphs within the \texttt{betacode} environment will be indented just like standard paragraphs, i.e. by the length \verb=\parindent=.
 
The text used for the following example has been taken from the \textsc{Thesaurus Linguae Graecae} (\url{http://www.tlg.uci.edu/}).

\begin{betacode}
*)/ANDRA MOI E)/NNEPE, *MOU=SA, POLU/TROPON, O(\S MA/LA POLLA\

PLA/GXQH, E)PEI\ *TROI/HS I(ERO\N PTOLI/EQRON E)/PERSE:
\end{betacode}

These lines have been produced by
\begin{verbatim}
\begin{betacode}
*)/ANDRA MOI E)/NNEPE, *MOU=SA, POLU/TROPON, O(\S MA/LA POLLA\

PLA/GXQH, E)PEI\ *TROI/HS I(ERO\N PTOLI/EQRON E)/PERSE:
\end{betacode}
\end{verbatim}

\subsubsection{The \texttt{$\backslash$bcode} command}
The argument of the \verb'\bcode' command will be inserted in the output exactly where the command appears,\frenchspacing i.\ e. \nonfrenchspacing without any extra space before or after it. Paragraphs (= blank line) in the Beta Code input text are converted to line breaks and aren't indented.

The text used for the following example has been taken from the \textsc{Perseus} Project (\url{http://www.perseus.tufts.edu/}).\bigskip

Here starts the odyssee: \bcode{
a)/ndra moi e)/nnepe, mou=sa, polu/tropon, o(\s ma/la polla\

pla/gxqh, e)pei\ *troi/hs i(ero\n ptoli/eqron e)/persen:}
To be continued \dots\bigskip

These lines have been produced by
\begin{verbatim}
Here starts the odyssee: \bcode{
a)/ndra moi e)/nnepe, mou=sa, polu/tropon, o(\s ma/la polla\

pla/gxqh, e)pei\ *troi/hs i(ero\n ptoli/eqron e)/persen:}
To be continued \dots
\end{verbatim}

\subsection{Features}
\subsubsection{Placing of the diacritics}
As mentioned before, there is a difference in placing the diacritics on an uppercase or on a lowercase letter. But as there are some sources that don't respect this rule, \textsf{betababel} doesn't handle this strictly. It allows you to place the diacritics before or after an uppercase letter (if they are placed before \emph{and} after the letter, the ones after are neglected).

\subsubsection{Inner-word and final sigma}
As defined in Beta Code, there is only one Latin representation (the character \texttt{s}) for both the inner-word and final sigma characters. \textsf{Betababel} therefore recognizes by itself which one's to be used. Beta Code, however, provides a way to determine explicitly the sigma by a suffix number: \texttt{s1} represents the inner-word sigma and \texttt{s2} the final sigma. For instance: \verb'\bcode{*)ana/basis s1 s2}' gives \bcode{*)ana/basis s1 s2}.

Note: Sometimes it's found that the letter \texttt{j} is used to represent the final sigma. This, however, is not conform to the Beta Code convention. Therefore you shouldn't use it in your Beta Code texts. Since \textsf{betababel} handles the sigma automatically, you don't need an extra representation like \texttt{j}. If \textsf{betababel} finds a \texttt{j}, it displays a warning, but you can let continue the typesetting by hitting the return key; then, in most of the cases, the \texttt{j} will just be omitted.

\subsubsection{Special characters}
\label{SpecChar}
If \textsf{betababel} detects a properly installed \textsf{teubner.sty} file of Claudio Beccari's \textsf{teubner} package, it will use it to be able to provide support for some additional special characters. The following table gives an overview over those characters and their Beta Code representation.

\begin{center}
\begin{tabular}{r@{\hspace{0pt}}l@{\hspace{3pt}}l|c}
&&\textbf{BetaCode}&\textbf{Result}\\
\hline\hline
&[&Left Square Bracket&\bcode{[}\\
\hline
&]&Right Square Bracket&\bcode{]}\\
\hline
&\#&Keraia&\bcode{#}\\
\hline
&\#1&Koppa&\bcode{#1}\\
\hline
&\#2&Stigma&\bcode{#2}\\
{*}&\#2&Stigma&\bcode{*#2}\\
\hline
&\#3&Coppa&\bcode{#3}\\
{*}&\#3&Coppa&\bcode{*#3}\\
\hline
&\#5&Sampi&\bcode{#5}\\
{*}&\#5&Sampi&\bcode{*#5}\\
\hline
&\#6&Paragraphos&\bcode{#6}\\
\hline
&\#12&EM Dash&\bcode{#12}\\
\hline
&\#22&low Keraia&\bcode{#22}\\
\end{tabular}
\end{center}

\subsubsection{Hyphenation}
\textsf{Betababel} simply converts the Beta Code to the input code for the \texttt{polutonikogreek} option of the \textsf{babel} package. Thus, it benefits from the Greek hyphenation capabilities of \textsf{babel}.

\pagebreak[4]
\subsection{Known limitations}
\paragraph{Using \textsf{betababel} within footnotes or other commands}
\label{footbug}
I got some feedback drawing my attention to the fact that \textsf{betababel} doesn't handle grave accents within footnotes properly. This is due to the backslash `\verb=\=' that is used in Beta Code for the grave accent; in \LaTeX, however, it prefixes commands. I found a way to handle this problem in simple use of \textsf{betababel}, but: If the \verb=\bcode= command or the \texttt{betacode} environment is used within another command (like \verb=\footnote= or \verb=\section= etc.) all the content of the argument of this command seems to be checked for correctness; and when a backslash followed by some other characters is found, but not recognized as a known command (which will most likely be the case), \LaTeX{} will prompt an error message and/or ignore the backslash and the following characters. --- This seems to be a quite fundamental problem arising when backslashes are used for other purposes than as command prefixes, and up to now I didn't figure it out how to fix the bug.

But to provide a way to properly generate grave accents in footnotes or within most other commands I added a little workaround to \textsf{betababel}. The modification doesn't eliminate the actual problem, but it allows to replace the impairing backslashes in footnotes or within other commands by exclamation marks `\texttt{!}'; they will work as a second transliteration for the grave accent. This is, of course, not conform to the Beta Code definition and thus against the original aims of the \textsf{betababel} package, but till I find a better solution it allows for using \textsf{betababel} to typeset Greek text in footnotes or within other commands.

\section{Version history}
\subsection{Changes in v0.5 of 2005/07/10}
\begin{itemize}
\item Digamma support (\bcode{*v}, \bcode{v})
\item Extended functionaliy of \textsf{betababel} by use of the \textsf{teubner.sty} package. Special characters added (see section \ref{SpecChar} on page \pageref{SpecChar}).
\end{itemize}

\subsection{Changes in v0.4b of 2005/05/26}
\begin{itemize}
\item Fixed bug that prevented use of \textsf{betababel} within some commands like \verb=\section= and others.
\item Some minor optimizations.
\end{itemize}

\subsection{Changes in v0.3 of 2004/04/20}
\begin{itemize}
\item Fixed the uppercase sigma bug.
\item Added workaround for the footnote bug (for further details see section \ref{footbug} on page \pageref{footbug}).
\item Reprogramming of the output routine.
\item Removed superfluous space after Greek text inserted using the \verb=\bcode= command.
\end{itemize}

\subsection{Changes in v0.2 of 2003/07/21 (first released version)}
\begin{itemize}
\item Added automatic handling of inner-word and final sigma.
\item Support for the Beta Codes {\tt s1} and {\tt s2} (forced inner-word and final sigma).
\item Added {\tt betacode} environment.
\item Added some Warnings.
\end{itemize}

\subsection{v0.1 of 2003/06}
\begin{itemize}
\item First try. For my own personal use only. Was able to perform the simple conversions from Beta Code to the transliteration used by the {\tt polutonikogreek} option of the {\sf babel} package.
\end{itemize}

\end{document}