%%
%% This is file `fixlatvian.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% fixlatvian.dtx  (with options: `package')
%% 
%% Copyright (C) Andrey Vihrov <andrey.vihrov@gmail.com>, 2010-2011
%%
%% 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.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% See the README for a list of files that constitute this work.
%%
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{svn-prov}
\ProvidesPackageSVN
  {$Id: fixlatvian.dtx 163 2011-02-05 18:51:11Z andrey.vihrov $}
  [v1a Improved Latvian support]
\DefineFileInfoSVN\relax
\RequirePackage{caption}
\RequirePackage{etoolbox}
\RequirePackage{perpage}
\RequirePackage{polyglossia}
\RequirePackage{xstring}
\RequirePackage{indentfirst}
\RequirePackage{icomma}
\ProcessOptions\relax
\@ifundefined{latvian@loaded}{\setdefaultlanguage{latvian}}{}
\frenchspacing
\newcommand{\FixL@warning}[1]{\PackageWarning{fixlatvian}{#1}}
\newcommand{\FixL@warning@noline}[1]{%
  \PackageWarningNoLine{fixlatvian}{#1}}
\newcommand{\FixL@info}[1]{\PackageInfo{fixlatvian}{#1}}
\newcommand{\FixL@alnum}{%
  ABCDEFGHIJKLMNOPQRSTUVWXYZ%
  abcdefghijklmnopqrstuvwxyz%
  0123456789%
}
\newcommand{\FixL@patchfailed}[1]{%
  \FixL@info{Could not change the definition of the \protect #1 command}}
\newcommand{\FixL@checkbefore}[1]{%
  \expandafter\newif\csname ifFixL@#1@before\endcsname
  \@ifpackageloaded{#1}{\csname FixL@#1@beforetrue\endcsname}{}%
  \AtBeginDocument{%
    \@ifpackageloaded{#1}{%
      \csname ifFixL@#1@before\endcsname\else
        \FixL@warning@noline{This package should be loaded after #1}%
      \fi
    }{}}}
\FixL@checkbefore{hyperref}
\FixL@checkbefore{amsthm}
\newcommand{\FixL@p}{.\@\nobreak}
\newcommand{\FixL@bigspace}{\hspace{.66667em}}
\CheckCommand*{\@seccntformat}[1]{\csname the#1\endcsname\quad}
\renewcommand{\@seccntformat}[1]{%
  \csname the#1\endcsname\FixL@p\FixL@bigspace}
\let\FixL@old@numberline\numberline
\renewcommand{\numberline}[1]{%
  \StrRight{#1}{1}[\FixL@tempa]%
  \FixL@old@numberline{#1%
    \IfSubStr{\FixL@alnum}{\FixL@tempa}{\FixL@p}{}%
  }}
\AtBeginDocument{%
  \let\nref\ref
  \let\npageref\pageref
}
\newcommand{\FixL@ref@base}[4]{%
  \begingroup
    \newcommand{\FixL@tempb}{\csname n#1\endcsname #2{#4}\FixL@p}%
    \IfStrEq{#3}{hyper}{\hyperref[#4]{\FixL@tempb}}{\FixL@tempb}%
  \endgroup
  \nobreak % Extra \nobreak
}
\AtBeginDocument{%
  \@ifpackageloaded{hyperref}{%
    \newcommand{\FixL@ref}[1]{\FixL@ref@base{ref}{*}{hyper}{#1}}%
    \newcommand{\FixL@ref@star}[1]{\FixL@ref@base{ref}{*}{}{#1}}%
    \renewcommand{\ref}{\@ifstar\FixL@ref@star\FixL@ref}%
    \newcommand{\FixL@pageref}[1]{\FixL@ref@base{pageref}{*}{hyper}{#1}}%
    \newcommand{\FixL@pageref@star}[1]{\FixL@ref@base{pageref}{*}{}{#1}}%
    \renewcommand{\pageref}{\@ifstar\FixL@pageref@star\FixL@pageref}%
  }{%
    \renewcommand{\ref}[1]{\FixL@ref@base{ref}{}{}{#1}}%
    \renewcommand{\pageref}[1]{\FixL@ref@base{pageref}{}{}{#1}}%
  }%
  \robustify{\ref}%
  \robustify{\pageref}%
}
\gappto\captionslatvian{%
  \renewcommand{\alsoname}{sk.~arī}%
  \renewcommand{\chaptername}{nodaļa}%
  \renewcommand{\figurename}{att}%
  \renewcommand{\indexname}{Rādītājs}%
  \renewcommand{\partname}{daļa}%
  \renewcommand{\tablename}{tabula}%
  \renewcommand{\seename}{sk.\@}%
}
\renewcommand{\@alph}[1]{%
  \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}
\renewcommand{\@Alph}[1]{%
  \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}
\@ifundefined{@makechapterhead}{}{%
  \patchcmd{\@makechapterhead}{\@chapapp\space \thechapter}{%
    \IfStrEq{\@chapapp}{\appendixname}{\@chapapp\space\thechapter}{%
      \thechapter\FixL@p\space\@chapapp}%
  }{}{\FixL@patchfailed{\chapter}}%
}
\newcommand{\FixL@fix@part}[1]{%
  \@ifundefined{#1}{}{%
    \renewcommand{\thepart}{\arabic{part}}%
    \expandafter\patchcmd\csname #1\endcsname{%
      \partname\nobreakspace\thepart}{\thepart\FixL@p\space\partname}{}{%
      \FixL@patchfailed{\part}}%
  }}
\AtBeginDocument{\FixL@fix@part{%
  \@ifpackageloaded{hyperref}{H@old@part}{@part}}}
\patchcmd{\ps@headings}{\@chapapp\ \thechapter}{%
  \thechapter\FixL@p\space\@chapapp}{}{\FixL@patchfailed{\chaptermark}}
\patchcmd{\ps@headings}{\thesection\quad}{%
  \thesection\FixL@p\FixL@bigspace}{}{\FixL@patchfailed{\sectionmark}}
\patchcmd{\ps@headings}{\thesubsection\quad}{%
  \thesubsection\FixL@p\FixL@bigspace}{}{%
  \FixL@patchfailed{\subsectionmark}}
\DeclareCaptionLabelSeparator{period@}{.\@\space}
\captionsetup{labelsep=period@}
\DeclareCaptionLabelFormat{latvian}{#2\FixL@p\space #1}
\captionsetup{labelformat=latvian}
\newif\ifFixL@amsthm@loaded
\@ifpackageloaded{amsthm}{\FixL@amsthm@loadedtrue}{}
\ifFixL@amsthm@loaded
  \swapnumbers
  \newcommand{\FixL@thmnumber}[1]{\@ifempty{#1}{}{#1\FixL@p}}
  \patchcmd{\swappedhead}{\thmnumber}{\FixL@thmnumber}{}{%
    \FixL@patchfailed{\swappedhead}}
\else
  \patchcmd{\@begintheorem}{#1\ #2}{#2\FixL@p\space #1}{}{%
    \FixL@patchfailed{\@begintheorem}}
  \patchcmd{\@opargbegintheorem}{#1\ #2}{#2\FixL@p\space #1}{}{%
    \FixL@patchfailed{\@opargbegintheorem}}
\fi
\MakePerPage{footnote}
\newcommand{\FixL@inpackage}[2]{%
  \AtBeginDocument{\@ifpackageloaded{#1}{#2}{}}}
\newcommand{\FixL@translate}[3]{%
  \FixL@inpackage{#1}{%
    \expandafter\renewcommand\csname #2\endcsname{#3}%
  }}
\FixL@inpackage{float}{\captionsetup[ruled]{labelformat=latvian}}
\FixL@inpackage{float}{\renewcommand{\floatname}[2]{%
  \expandafter\def\csname #1name\endcsname{#2}}}
\FixL@translate{algorithm}{listalgorithmname}{Algoritmu saraksts}
\FixL@inpackage{algorithm}{\floatname{algorithm}{algoritms}}
\FixL@translate{amsthm}{proofname}{Pierādījums}
\FixL@translate{appendix}{appendixtocname}{Pielikumi}
\newcommand{\FixL@doc@glossaryname}{Izmaiņu saraksts}
\FixL@inpackage{doc}{\GlossaryPrologue{%
  \section*{\FixL@doc@glossaryname}%
  \markboth{\FixL@doc@glossaryname}{\FixL@doc@glossaryname}%
}}
\FixL@inpackage{doc}{\IndexPrologue{%
  \section*{\indexname}%
  \markboth{\indexname}{\indexname}%
  Numuri kursīvā apzīmē lappusi, kurā aprakstīta attiecīgā komanda;
  pasvītrotie numuri norāda uz komandas \ifcodeline@index definīcijas
  pirmkoda rindu\else definīciju\fi; numuri parastajā rakstā apzīmē
  \ifcodeline@index pirmkoda rindu\else lappusi\fi, kurā komanda tiek
  izmantota.%
}}
\FixL@translate{doc}{generalname}{Vispārīgi}
\FixL@translate{listings}{lstlistlistingname}{Pirmkoda tekstu saraksts}
\FixL@translate{listings}{lstlistingname}{%
  \ifx\lst@@caption\@empty P\else p\fi irmkods}
\endinput
%%
%% End of file `fixlatvian.sty'.
