% \iffalse meta-comment
%
% Copyright 2019--2022 Uro�� Stefanovi�� and any individual authors
% listed elsewhere in this file.  All rights reserved.
% Earlier Maintainers: Dejan Muhamedagi��, Slobodan Jankovi��, Javier Bezos L��pez, Johannes L. Braams
% 
% This file is intended to be used with the Babel system.
% ------------------------------------------------------
% 
% It 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 2003/12/01 or later.
% 
% This work has the LPPL maintenance status "maintained".
% 
% The Current Maintainer of this work is Uro�� Stefanovi��.
% 
% The list of derived (unpacked) files belonging to the distribution
% and covered by LPPL is defined by the unpacking scripts (with
% extension .ins) which are part of the distribution.
% \fi
% \iffalse
%    Tell the \LaTeX\ system who we are and write an entry on the
%    transcript.
%<*dtx>
\ProvidesFile{serbian.dtx}
%</dtx>
%<code>\ProvidesLanguage{serbian}
%\fi
%\ProvidesFile{serbian.dtx}
        [2022/09/30 2.2a Serbian Latin support for the Babel system]
%\iffalse
%% File `serbian.dtx'
%
%    This file is part of the babel system, it provides the source
%    code for the Serbian Latin language definition file.
%<*filedriver>
\documentclass{ltxdoc}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper,top=2.0cm,left=3cm,right=2.5cm,bottom=2cm,includefoot,includehead]{geometry}
\title{The Serbian Latin Language in the \babel\ system}
\author{Uro�� Stefanovi��\footnote{\texttt{urostajms@gmail.com}}} 
\newcommand*\babel{\textsf{babel}}
\newcommand*\langvar{$\langle \it lang \rangle$}
\newcommand*\note[1]{}
\newcommand*\Lopt[1]{\textsf{#1}}
\newcommand*\file[1]{\texttt{#1}}
\begin{document}
 \maketitle
 \DocInput{serbian.dtx}
\end{document}
%</filedriver>
%\fi
% \GetFileInfo{serbian.dtx}
%
%  \section*{The Serbian Latin Language}
%
%    The file \file{\filename} defines all the language definition
%    macros for the Serbian language, typeset in a Latin script.
%
%    For this language the character |"| is made active. In
%    table~\ref{tab:serbian-quote} an overview is given of its
%    purpose. One of the reasons for this is that in the Serbian
%    language some special characters are used.
%
%    \begin{table}[htb]
%     \begin{center}
%     \begin{tabular}{lp{8cm}}
%      |"c| & |\v c|, also implemented for the lowercase and uppercase s and z.                \\
%      |"d| & |\dj|, also implemented for |"D|.                     \\
%      |"-| & An explicit hyphen sign, allowing hyphenation
%             in the rest of the word; inserts a hyphen which is repeated at the beginning of the
%             next line (recommended to use for compound words with hyphen).                \\
%      \verb="|= & Disables ligature at this position.                   \\
%      |""| & Similar to |"-| but prints no hyphen sign. 			   \\
%      |"~| & Compound word mark without a breakpoint, prints hyphen
%            prohibiting hyphenation at the point.		                \\
%      |"=| & A compound word mark with a breakpoint, prints hyphen
%            allowing hyphenation in the composing words.               \\
%      |"`| & German opening double quote (looks like ,\kern-0.08em,).      \\
%      |"'| & German closing double quote (looks like ``).                    \\
%      |"'| & (if the \Lopt{quotes} attribute is used) Closing double quote (looks like '').                    \\
%      |"<| & French opening double quote (looks like $<\!\!<$).     \\
%      |">| & French closing double quote (looks like $>\!\!>$).    \\
%     \end{tabular}
%     \caption{The extra definitions made
%              by \file{serbian.ldf}}\label{tab:serbian-quote}
%     \end{center}
%    \end{table}
%
%    Macro |\today| prints the date in Serbian. Alternatively, if attribute \Lopt{datei} is used,
%    |\today| prints the current date, but prints `juni' and `juli' for `June' and `July'.
%    If you prefer to use `juni' and `juli' instead of default `jun' and `jul',
%    use the \Lopt{datei} attribute. Also, the |\today*| macro prints the date without dot after the year
%    (used when after the date is the punctuation mark, such as comma).
%    Alternatively, the commands |\todayRoman| and |\todayRoman*| prints the current date using Roman numerals for months;
%    |\todayGen| and |\todayGen*| prints the current month name in the genitive case,
%    and |\todayArabic| and |\todayArabic*| prints the current month as a number.
%
%    The alphabetical enumerations in texts use the Latin alphabet and alphabetic order,
%    but the letters q, w, x and y are omitted by the rules of the Serbian language (22 letters are used).
%    However, if the user wants to use the English alphabet for the enumeration (26 letters), this option is also available.
%    We will also provide the enumeration with the Latin letters but in alphabetic order that matches the Cyrillic alphabet (30 letters).
%    This of course shouldn't be used when the text is written in the Latin script.
%    However, sometimes the text is written in the Latin script so it can be later
%    converted into Cyrillic script (for example using the |OT2| encoding); in such case this alphabet order will be useful. 
%    One can manually switch the enumeration alphabet with the commands |\enumCyr|, |\enumLat| and |\enumEng|.
%    This commands can be used after the |\begin{document}| when the \Lopt{serbian} language is active.
%    In principle, enumerations are a matter for class and style designers but the same can be
%    said also about things, other than enumerations, such as names of sections and bibliography lists.
%
%    Apart from defining shorthands we need to make sure that the
%    first paragraph of each section is indented. Furthermore the
%    following new math operators are defined: |\sh|, |\ch|, |\tg|, |\ctg|,
%    |\arctg|, |\arcctg|, |\th|, |\cth|, |\arsh|,
%    |\arch|, |\arth|, |\arcth|, |\cosec|, |\Prob|, |\Expect|, |\Variance|,
%    |\arcsec|, |\arccosec|, |\sech|, |\cosech|, |\arsech|, |\arcosech|,
%    |\NZD|, |\nzd|, |\NZS|, |\nzs|.
%
% By default, a ekavian spelling is enabled. For ijekavian
% spelling can be enabled by setting the attribute to \Lopt{ijekav}. To set
% an attribute, put the |\languageattribute| macro within a document preamble after
% \babel, for example,
%\begin{verbatim}
%    \usepackage[english,serbian]{babel}
%    \languageattribute{serbian}{ijekav}
%\end{verbatim}
% Setting the \Lopt{ijekav} attribute changes the built-in strings (caption names).
% For example, the part will be entitled as
% `Deo' by default and as `Dio' if the
% Serbian language attribute is set to \Lopt{ijekav}.
% Same result can be achieved using a modifier as follows:
%\begin{verbatim}
%    \usepackage[english,serbian.ijekav]{babel}
%\end{verbatim}
% Using a modifier in a package option is often better. A modifier is set after
% the language name, and is prefixed with a dot (only when the language is set
% as package option ��� neither global options nor the main key accept them).
% Also, it's possible to use more than one attribute:
%\begin{verbatim}
%    \usepackage[english,serbian.ijekav.datei.quotes]{babel}
%\end{verbatim}
%
% The file \file{serbian.ldf} is designed to work both with
% legacy non-unicode (8-bit) and new Unicode encodings of the source document
% files (input encodings) and of the font files (font encodings).
%
% \StopEventually{}
%
%  \section*{The code}
%
%    The macro |\LdfInit| takes care of preventing that this file is
%    loaded more than once, checking the category code of the
%    \texttt{@} sign, etc.
%
%    \begin{macrocode}
%<*code>
\LdfInit{serbian}{captionsserbian}
%    \end{macrocode}
%
%    First, we check if Lua\LaTeX\ or Xe\LaTeX\ is running. If so, we set
%    boolean key |\if@srb@uni@ode| to true.
%
%    \begin{macrocode}
\ifdefined\if@srb@uni@ode
  \PackageError{babel}{if@srb@uni@ode already defined.}
  \relax
\fi
\newif\if@srb@uni@ode
\ifdefined\luatexversion \@srb@uni@odetrue \else
\ifdefined\XeTeXrevision \@srb@uni@odetrue \fi\fi
%    \end{macrocode}
%
%    Check if hyphenation patterns for the Serbian language have been
%    loaded in \file{language.dat}. Namely, we check for the existence of
%    |\l@serbian|. If it is not defined, we declare Serbian as dialect
%    for the default language number 0 which almost for sure is English.
%
%    \begin{macrocode}
\ifx\l@serbian\@undefined
  \@nopatterns{Serbian}
  \adddialect\l@serbian0
\fi
%    \end{macrocode}
%
%    For Serbian the \texttt{"} character is made active. This is done
%    once, later on its definition may vary. Other languages in the
%    same document may also use the \texttt{"}~character for
%    shorthands; we specify that the Serbian group of shorthands
%    should be used. We save the original double quote character
%    in the |\dq| macro to keep it available. The shorthand \texttt{"-}
%    should be used in places where a word contains an explictit
%    hyphenation character. According to the rules of the Serbian language, when
%    a word break occurs at an explicit hyphen it must appear both at the end of the
%    first line and at the beginning of the second line.
%
%    \begin{macrocode}
\initiate@active@char{"}
\begingroup \catcode`\"12
\def\reserved@a{\endgroup
  \def\@SS{\mathchar"7019 }
  \def\dq{"}}
\reserved@a
\declare@shorthand{serbian}{"c}{\textormath{\v c}{\check c}}
\declare@shorthand{serbian}{"d}{\textormath{\dj}{\textnormal{\dj}}}
\declare@shorthand{serbian}{"s}{\textormath{\v s}{\check s}}
\declare@shorthand{serbian}{"z}{\textormath{\v z}{\check z}}
\declare@shorthand{serbian}{"C}{\textormath{\v C}{\check C}}
\declare@shorthand{serbian}{"D}{\textormath{\DJ}{\textnormal{\DJ}}}
\declare@shorthand{serbian}{"S}{\textormath{\v S}{\check S}}
\declare@shorthand{serbian}{"Z}{\textormath{\v Z}{\check Z}}
\declare@shorthand{serbian}{"`}{\quotedblbase}
\declare@shorthand{serbian}{"'}{\textquotedblleft}
\declare@shorthand{serbian}{"<}{\guillemotleft}
\declare@shorthand{serbian}{">}{\guillemotright}
\declare@shorthand{serbian}{""}{\hskip\z@skip}
\declare@shorthand{serbian}{"~}{\textormath{\leavevmode\hbox{-}}{-}}
\declare@shorthand{serbian}{"=}{\nobreak-\hskip\z@skip}
\declare@shorthand{serbian}{"|}{\textormath{\nobreak\discretionary{-}{}{\kern.03em}\allowhyphens}{}}
\declare@shorthand{serbian}{"-}{\nobreak\discretionary{-}{-}{-}\bbl@allowhyphens}
%    \end{macrocode}
%
%    The macro |\captionsserbian| defines all strings used in the four
%    standard documentclasses provided with \LaTeX.
%
%    \begin{macrocode}
\addto\captionsserbian{%
  \def\prefacename{Predgovor}%
  \def\refname{Literatura}%
  \def\abstractname{Sa\v zetak}%
  \def\bibname{Bibliografija}%
  \def\chaptername{Glava}%
  \def\appendixname{Dodatak}%
  \def\contentsname{Sadr\v zaj}%
  \def\listfigurename{Spisak slika}%
  \def\listtablename{Spisak tabela}%
  \def\indexname{Indeks}%
  \def\figurename{Slika}%
  \def\tablename{Tabela}%
  \def\partname{Deo}%
  \def\enclname{Prilozi}%
  \def\ccname{Kopije}%
  \def\headtoname{Prima}%
  \def\pagename{strana}%
  \def\seename{vidi}%
  \def\alsoname{vidi tako\dj e}%
  \def\proofname{Dokaz}%
  \def\glossaryname{Re\v cnik}%
}%
\if@srb@uni@ode
  \addto\captionsserbian{%
    \def\abstractname{Sa��etak}%
    \def\contentsname{Sadr��aj}%
    \def\alsoname{vidi tako��e}%
    \def\glossaryname{Re��nik}%
  }%
\fi
\let\captionsserbian@ijekav=\captionsserbian
\addto\captionsserbian@ijekav{%
  \def\partname{Dio}%
  \def\glossaryname{Rje\v cnik}%
}
\if@srb@uni@ode
  \addto\captionsserbian@ijekav{%
    \def\glossaryname{Rje��nik}%
  }
\fi
%    \end{macrocode}
%
%    The macro |\dateserbian| redefines the commands |\today|, |\today*|, |\todayRoman| and |\todayRoman*| to produce Serbian dates.
%    Also, the commands |\todayGen|, |\todayGen*|, |\todayArabic| and |\todayArabic*| are provided.
%
%    \begin{macrocode}
  \def\dateserbian{%
   \def\month@serbian{\ifcase\month\or
    januar\or
    februar\or
    mart\or
    april\or
    maj\or
    jun\or
    jul\or
    avgust\or
    septembar\or
    oktobar\or
    novembar\or
    decembar\fi}%
   \def\month@serbian@gen{\ifcase\month\or
    januara\or
    februara\or
    marta\or
    aprila\or
    maja\or
    juna\or
    jula\or
    avgusta\or
    septembra\or
    oktobra\or
    novembra\or
    decembra\fi}%
    \def\today{\number\day.~\month@serbian\ \number\year\@ifstar{}{.}}%
    \def\todayRoman{\number\day.~\@Roman\month~\number\year\@ifstar{}{.}}%
    \def\todayGen{\number\day.~\month@serbian@gen\ \number\year\@ifstar{}{.}}%
    \def\todayArabic{\number\day.~\number\month.~\number\year\@ifstar{}{.}}}
  \let\dateserbian@datei=\dateserbian
  \addto\dateserbian@datei{
    \def\month@serbian@datei{\ifnum\month=6 juni%
    \else\ifnum\month=7 juli\else\month@serbian\fi\fi}%
    \def\today{\number\day.~\month@serbian@datei\ \number\year\@ifstar{}{.}}
}
%    \end{macrocode}
%
%    The Serbian hyphenation patterns can be used with |\lefthyphenmin| and
%    |\righthyphenmin| set to~2. (Actually, the ���official��� definition allows even one character for |lefthyphen|,
%    but it is recommended to use value two for better results.)
%
%    \begin{macrocode}
\providehyphenmins{\CurrentOption}{\tw@\tw@}
\providehyphenmins{serbian}{\tw@\tw@}
%    \end{macrocode}
%
%    We specify that the Serbian group of shorthands should be used.
%
%    \begin{macrocode}
\addto\extrasserbian{\languageshorthands{serbian}}
\addto\extrasserbian{\bbl@activate{"}}
\addto\noextrasserbian{\bbl@deactivate{"}}
%    \end{macrocode}
%
%    Serbian typesetting requires |frenchspacing|. So, we add commands to
%	 |\extrasserbian| and |\noextrasserbian| to turn it on and off, respectively.
%
%    \begin{macrocode}
\addto\extrasserbian{\bbl@frenchspacing}
\addto\noextrasserbian{\bbl@nonfrenchspacing}
%    \end{macrocode}
%
%    In Serbian the first paragraph of each section should be indented.
%
%    \begin{macrocode}
\let\@aifORI\@afterindentfalse
\def\bbl@serbianindent{\let\@afterindentfalse\@afterindenttrue\@afterindenttrue}
\def\bbl@nonserbianindent{\let\@afterindentfalse\@aifORI\@afterindentfalse}
\addto\extrasserbian{\bbl@serbianindent}
\addto\noextrasserbian{\bbl@nonserbianindent}
%    \end{macrocode}
%
%    We redefine the macro |\Alph|, which now produces (uppercase) Latin letters without the letters q, w, x and y
%    when Serbian is switched on, but we will keep the English alphabet if the user wants to use it.
%    Also we will define Latin alphabet in order that matches Cyrillic alphabet.
%    The user can choose which alphabet to use through the commands |\enumCyr|, |\enumLat| and |\enumEng|
%    (or even to switch from one enumeration to another).
%
%    \begin{macrocode}
\newcount\srbl@lettering \srbl@lettering=\z@
\addto\extrasserbian{\babel@save\@Alph \let\@Alph\srbl@Alph}
\def\srbl@Alph#1{%
\ifcase\srbl@lettering
    \ifcase#1\or A\or B\or C\or D\or E\or F\or G\or H\or I\or
    J\or K\or L\or M\or N\or O\or P\or R\or S\or T\or U\or V\or
    Z\else\@ctrerr\fi
\or
    \if@srb@uni@ode
        \ifcase#1\or A\or B\or V\or G\or D\or ��\or E\or ��\or Z\or
        I\or J\or K\or L\or Lj\or M\or N\or Nj\or O\or
        P\or R\or S\or T\or ��\or U\or F\or H\or C\or
        ��\or D��\or ��\else\@ctrerr\fi
    \else
        \ifcase#1\or A\or B\or V\or G\or D\or\DJ\or E\or\v Z\or Z\or
        I\or J\or K\or L\or Lj\or M\or N\or Nj\or O\or
        P\or R\or S\or T\or\'C\or U\or F\or H\or C\or
        \v C\or D\v z\or\v S\else\@ctrerr\fi
    \fi
\or
    \ifcase#1\or A\or B\or C\or D\or E\or F\or G\or H\or I\or
    J\or K\or L\or M\or N\or O\or P\or Q\or R\or S\or T\or U\or V\or
    W\or X\or Y\or Z\else\@ctrerr\fi
\fi}%
%    \end{macrocode}
%
%    The same thing will be done with the macro |\alph|.
%
%    \begin{macrocode}
\addto\extrasserbian{\babel@save\@alph \let\@alph\srbl@alph}
\def\srbl@alph#1{%
\ifcase\srbl@lettering
    \ifcase#1\or a\or b\or c\or d\or e\or f\or g\or h\or i\or
    j\or k\or l\or m\or n\or o\or p\or r\or s\or t\or u\or v\or
    z\else\@ctrerr\fi
\or
    \if@srb@uni@ode
        \ifcase#1\or a\or b\or v\or g\or d\or ��\or e\or ��\or z\or
        i\or j\or k\or l\or lj\or m\or n\or nj\or o\or
        p\or r\or s\or t\or ��\or u\or f\or h\or c\or
        ��\or d��\or ��\else\@ctrerr\fi
    \else
        \ifcase#1\or a\or b\or v\or g\or d\or\dj\or e\or\v z\or z\or
        i\or j\or k\or l\or lj\or m\or n\or nj\or o\or
        p\or r\or s\or t\or\'c\or u\or f\or h\or c\or
        \v c\or d\v z\or\v s\else\@ctrerr\fi
    \fi
\or
    \ifcase#1\or a\or b\or c\or d\or e\or f\or g\or h\or i\or
    j\or k\or l\or m\or n\or o\or p\or q\or r\or s\or t\or u\or v\or
    w\or x\or y\or z\else\@ctrerr\fi
\fi}%
\addto\extrasserbian{%
  \babel@save\enumEng\def\enumEng{\srbl@lettering=\tw@}%
  \babel@save\enumLat\def\enumLat{\srbl@lettering=\z@}%
  \babel@save\enumCyr\def\enumCyr{\srbl@lettering=\@ne}%
}%
%    \end{macrocode}
%
%    An |ijekav| attribute changes default behavior and activates an
%    alternative set of captions suitable for typesetting in ijekavian dialect.
%    The |quotes| attribute changes the |"'| shorthand to produce '' as closing quote,
%    instead the traditional `` quote of Serbian language.
%    Also, the |datei| attribute will produce `juni' and `juli' instead `jun' and `jul'
%    for date.
%
%    \begin{macrocode}
\bbl@declare@ttribute{serbian}{ijekav}{%
 \PackageInfo{babel}{Serbian attribute set to ijekav}%
 \let\captionsserbian=\captionsserbian@ijekav }
\@onlypreamble\captionsserbian@ijekav
\bbl@declare@ttribute{serbian}{quotes}{%
 \PackageInfo{babel}{Serbian attribute set to quotes}%
 \declare@shorthand{serbian}{"'}{\textquotedblright} }
\bbl@declare@ttribute{serbian}{datei}{%
 \PackageInfo{babel}{Serbian attribute set to datei}%
 \let\dateserbian=\dateserbian@datei }
\@onlypreamble\dateserbian@datei
%    \end{macrocode}
%
%    Some math functions in Serbian math books have other names:
%    e.g. |sinh| in Serbian is written as |sh| etc. So we define a
%    number of new math operators.
%
%    \begin{macrocode}
\def\sh{\mathop{\operator@font sh}\nolimits}
\def\ch{\mathop{\operator@font ch}\nolimits}
\def\tg{\mathop{\operator@font tg}\nolimits}
\def\ctg{\mathop{\operator@font ctg}\nolimits}
\def\arctg{\mathop{\operator@font arctg}\nolimits}
\def\arcctg{\mathop{\operator@font arcctg}\nolimits}
\addto\extrasserbian{%
  \babel@save{\th}%
  \let\ltx@th\th
  \def\th{\textormath{\ltx@th}%
                     {\mathop{\operator@font th}\nolimits}}%
  }
\def\cth{\mathop{\operator@font cth}\nolimits}
\def\arsh{\mathop{\operator@font arsh}\nolimits}
\def\arch{\mathop{\operator@font arch}\nolimits}
\def\arth{\mathop{\operator@font arth}\nolimits}
\def\arcth{\mathop{\operator@font arcth}\nolimits}
\def\cosec{\mathop{\operator@font cosec}\nolimits}
\def\arcsec{\mathop{\operator@font arcsec}\nolimits}
\def\arccosec{\mathop{\operator@font arccosec}\nolimits}
\def\sech{\mathop{\operator@font sech}\nolimits}
\def\cosech{\mathop{\operator@font cosech}\nolimits}
\def\arsech{\mathop{\operator@font arsech}\nolimits}
\def\arcosech{\mathop{\operator@font arcosech}\nolimits}
\def\Prob{\mathop{\kern\z@\mathsf{P}}\nolimits}
\def\Expect{\mathop{\kern\z@\mathsf{E}}\nolimits}
\def\Variance{\mathop{\kern\z@\mathsf{D}}\nolimits}
\def\nzs{\mathop{\operator@font nzs}\nolimits}
\def\nzd{\mathop{\operator@font nzd}\nolimits}
\def\NZS{\mathop{\operator@font NZS}\nolimits}
\def\NZD{\mathop{\operator@font NZD}\nolimits}
%    \end{macrocode}
%
%    The macro |\ldf@finish| takes care of looking for a
%    configuration file, setting the main language to be switched on
%    at |\begin{document}| and resetting the category code of
%    \texttt{@} to its original value.
%
%    \begin{macrocode}
\ldf@finish{serbian}
%</code>
%    \end{macrocode}
%
% \Finale
%%
%% \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         \~}
%%
\endinput