% \iffalse meta-comment
% 
% File: linguistix-marathi.dtx
% 
% ----------------------------------------------------------
% The LaTeX bundle LinguisTiX v0.8
% Copyright © 2025, 2026 निरंजन
% 
% This program is free software: you can redistribute it
% and/or modify it under the terms of the GNU General Public
% License as published by the Free Software Foundation,
% either version 3 of the License, or (at your option) any
% later version.
% 
% This program is distributed in the hope that it will be
% useful, but WITHOUT ANY WARRANTY; without even the implied
% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
% PURPOSE. See the GNU General Public License for more
% details.
% 
% You should have received a copy of the GNU General Public
% License along with this program. If not, see
% <https://www.gnu.org/licenses/>.
% ----------------------------------------------------------
% 
% \fi
% \iffalse
%<*driver>
\documentclass{l3doc}
\usepackage{linguistix}
\usepackage{xcolor}
\usepackage{fontawesome5}
\usepackage[verbose=silent]{microtype}
\usepackage{cleveref}
\usepackage{hyperxmp}

\makeatletter
\def\@xobeysp{\hphantom{X}}%
\makeatother

\linguistix{old style one}
\loadlanguages{british,marathi}

\setquotestyle{british}

\colorlet{lngxredcolor}{red!50!black}
\colorlet{lngxgreencolor}{green!50!black}
\colorlet{lngxbluecolor}{blue!50!black}

\urlstyle{tt}

\hypersetup{%
  unicode,%
  colorlinks,%
  linkcolor              = {lngxredcolor},
  citecolor              = {lngxgreencolor},
  urlcolor               = {lngxbluecolor},
  pdftitle               = {linguistix-marathi},%
  pdfauthor              = {निरंजन},%
  pdfsubject             = {%
    मराठी (Marathi) with LinguisTiX.%
  },%
  pdfcreator             = {निरंजन},%
  pdfkeywords            = {Linguistics, LaTeX},%
  pdfcopyright           = {%
    The LaTeX bundle LinguisTiX\textLF
    Copyright © 2025, 2026 निरंजन\textLF
    This program is free software: you can redistribute it
    and/or modify it under the terms of the GNU General
    Public License as published by the Free Software
    Foundation, either version 3 of the License, or (at your
    option) any later version.%
  },%
  pdflicenseurl          = {gnu.org/licenses/gpl-3.0.html}%
}%

\colorlet{lngxpurplecolor}{blue!50!red}

\def\lngxtval{%
  \begingroup
  \color{lngxredcolor}
  true%
  \endgroup
  \,|\,false%
}

\def\lngxfval{%
  true%
  \begingroup
  \color{lngxredcolor}
  \,|\,false%
  \endgroup
}

\ExplSyntaxOn
\msg_redirect_name:nnn { l3doc }
                       { foreign-internal }
                       { none }
\ExplSyntaxOff

\makeatletter
\NewDocumentCommand \supportfootnote { +m } {%
  \begingroup
  \def\thefootnote{}%
  \let\@makefntext\relax
  \def\Hy@Warning##1{}%
  \footnotetext{%
    \hspace*{-\parindent}%
    #1%
  }%
  \endgroup
}
\makeatother

\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
% \title{मराठी\,--\,\lngxmarathilogo}
% \author{निरंजन}
% \date{^^A
%   \today\ (v0.8)\\[1ex]^^A
%   {^^A
%     \small\faIcon{home}\quad
%     \url{^^A
%       https://ctan.org/pkg/linguistix^^A
%     }\\[0.5ex]^^A
%     \small\faIcon{git-alt}\quad
%     \url{^^A
%       https://puszcza.gnu.org.ua/projects/linguistix^^A
%     }\\[0.5ex]^^A
%     \small\faIcon[regular]{comments}\quad
%     \url{^^A
%       https://matrix.to/\#/\#linguistix:matrix.org^^A
%     }^^A
%   }^^A
% }
% 
% \maketitle
%
% \supportfootnote{^^A
%   The \lngxpkg\ bundle
%
%   \noindent
%   Copyright © 2025, 2026 निरंजन
%
%   This program is free software: you can redistribute it
%   and/or modify it under the terms of the \textsc{gnu}
%   General Public License as published by the Free Software
%   Foundation, either version 3 of the License, or (at your
%   option) any later version.
%
%   This program is distributed in the hope that it will be
%   useful, but \emph{\textbf{without any warranty}};
%   without even the implied warranty of
%   \emph{\textbf{merchantability}} or \emph{\textbf{fitness
%   for a particular purpose}}. See the \textsc{gnu} General
%   Public License for more details.
%
%   You should have received a copy of the GNU General
%   Public License along with this program. If not, see
%   \url{https://www.gnu.org/licenses/}.^^A
% }
%
% \begin{implementation}
% \noindent I initialise the package with basic information.
%    \begin{macrocode}
%<*marathi>
\ProvidesExplPackage{linguistix-marathi}
                    {2026-02-02}
                    {v0.8}
                    {मराठी (Marathi)}
%    \end{macrocode}
% Average height of Marathi conjuncts could be more than
% that of Latin letters with descenders. This requires minor
% adjustments in the baseline stretch. To do it uniformly
% for footnotes also, I use the \pkg{setspace} package (if
% not loaded already).
%    \begin{macrocode}

\IfPackageLoadedF { setspace } {
  \RequirePackage { setspace }
}
%    \end{macrocode}
% We need to set the spacing between lines and words for
% which I use internal floating point numbers. They are
% declared here.
%    \begin{macrocode}

\fp_gzero_new:N \g_मराठी_शब्दांतील_अंतर_fp
\fp_gzero_new:N \g_मराठी_ओळींतील_अंतर_fp
%    \end{macrocode}
% This macro grabs an argument and passes it to the key
% |शब्दांतील अंतर| which is used to set the inter-word space
% for Marathi.
%    \begin{macrocode}

\cs_new_protected:Npn \मराठी_शब्दांतील_अंतर:n #1 {
  \lngx_set_keys:n { शब्दांतील~ अंतर = { #1 } }
}

\cs_gset_eq:NN \शब्दांतीलअंतर \मराठी_शब्दांतील_अंतर:n
%    \end{macrocode}
% This macro grabs an argument, (g-)sets it as the value of
% \cs{g_मराठी_ओळींतील_अंतर_fp} and resets the baseline stretch
% with \cs{setstretch} command. If the current class is
% \cls{memoir}, then there is a method to do that without
% any package. I use that.
%    \begin{macrocode}

\cs_new_protected:Npn \मराठी_ओळींतील_अंतर:n #1 {
  \fp_gset:Nn \g_मराठी_ओळींतील_अंतर_fp { #1 }
  \IfClassLoadedTF { memoir } {
    \setSingleSpace {
      \fp_use:N \g_मराठी_ओळींतील_अंतर_fp
    }
    \SingleSpacing
  } {
    \setstretch {
      \fp_use:N \g_मराठी_ओळींतील_अंतर_fp
    }
  }
}

\cs_gset_eq:NN \ओळींतीलअंतर \मराठी_ओळींतील_अंतर:n
%    \end{macrocode}
% Here I define two keys for adjusting the space between
% words and lines respectively. Their defaults are also set
% here.
%    \begin{macrocode}

\keys_define:nn { मराठी } {
  शब्दांतील~ अंतर
  .fp_gset:N             = \g_मराठी_शब्दांतील_अंतर_fp,
  शब्दांतील~ अंतर
  .initial:n             = { 1.25 },
  ओळींतील~ अंतर
  .code:n                = {
    \मराठी_ओळींतील_अंतर:n { #1 }
  }
}
%    \end{macrocode}
% The \pkg{babel} package defines |\extrasxxxx| commands for
% languages where the additional code that should go with a
% particular language (|xxxx| in this case) is set. The
% |\addto| command is used for appending to the same. I
% start with defining additional macros for Marathi.
%    \begin{macrocode}

\addto { \extrasmarathi } {
%    \end{macrocode}
% I have added the command for using the socket for native
% numbering. It will pickup its value from the current
% assignment of the plugs and produce the results
% accordingly.
%    \begin{macrocode}
  \socket_use:n { lngx / native-numbering }
%    \end{macrocode}
% By default, \LaTeX\ prints roman numeral (in capital) as
% part numbers. They are not suitable for Marathi. Thus we
% change them to be printed with \cs{lngx_counter:n}
% instead.
%    \begin{macrocode}
  \cs_set:Npn \thepart { \lngx_counter:n { part } }
%    \end{macrocode}
% The default \LaTeX\ produces Latin numerals, roman (small
% and capital both) alphabets and a-z alphabets with
% enumerate at different levels of nesting. In Marathi, both
% are irrelevant. Thus I renew all of the concerned commands
% and change them to print Marathi numbers. Since Marathi
% doesn’t have much variety available for counters, I have
% chosen a simpler style, i.e. 1, 1.1, 1.1.1 and 1.1.1.1.
%    \begin{macrocode}
  \cs_set:Npn \theenumi { \lngx_counter:n { enumi } }
  \cs_set:Npn \theenumii {
    \lngx_counter:n { enumi } .
    \lngx_counter:n { enumii }
  }
%    \end{macrocode}
% A period is added after each ‘label’ in enumerate. In
% default \LaTeX, the label for second level enumeration is
% printed inside brackets. We don’t need it in Marathi. So
% I change the \cs{labelenumii} command and add a period.
% It is not added for the first level because that’s
% \LaTeX-default too. Similarly, this is extended to all the
% other levels.
%    \begin{macrocode}
  \cs_set:Npn \labelenumii { \theenumii . }
  \cs_set:Npn \theenumiii {
    \lngx_counter:n { enumi } .
    \lngx_counter:n { enumii } .
    \lngx_counter:n { enumiii }
  }
  \cs_set:Npn \labelenumiii { \theenumiii . }
  \cs_set:Npn \theenumiv {
    \lngx_counter:n { enumi } .
    \lngx_counter:n { enumii } .
    \lngx_counter:n { enumiii } .
    \lngx_counter:n { enumiv }
  }
  \cs_set:Npn \labelenumiv { \theenumiv . }
%    \end{macrocode}
% The \pkg{expex} package has an independent mechanism of
% defining and using counters. I define a set called
% |देवनागरी| here and make it the default when Marathi is
% used. Note that this change will go with the
% \cs{lngx_misc_reset:} command. Refer to |linguistix.pdf|
% for more information on this.
%    \begin{macrocode}
  \IfPackageLoadedT { expex } {
    \definelabeltype { देेवनागरी } {
      labelgen                 = { list },
      labellist                = {
        अ, आ, इ, ई,
        उ, ऊ, ए, ऐ,
        ओ, औ, अं, अः,
        ॲ, ऋ, ॠ, ऌ, ॡ, ऑ
      },
      labelformat              = {A.},
      fullrefformat            = {XA},
      labelalign               = {left},
      labelwidth               = {1.5em}
    }
    \lingset {
      labeltype                = { देवनागरी }
    }
  }
%    \end{macrocode}
% Marathi doesn’t distinguish between Italic and Upright. So
% I redefine \cs{emph} to produce the argument in bold
% instead. This also goes when \cs{lngx_misc_reset:} is
% used.
%    \begin{macrocode}
  \cs_gset_eq:NN \emph \textbf
}
%    \end{macrocode}
% With the following code, I add the date conversion
% settings and the parameters to |onchar| command inside
% \cs{babelprovide}. This is done only if Marathi is the
% main language of the document. I also set the numbering
% style to |strict|ly native if Marathi is the main
% language.
%    \begin{macrocode}

\tl_if_eq:NnTF \g_lngx_main_language_tl { marathi } {
  \lngx_set_keys:n { native~ numbering = { strict } }
  \babelprovide [
    onchar               = { ids~ fonts },
    date.gregorian /
    date.long            = {
      [d|digits]~ [MMMM],~ [y|digits]
    },
%    \end{macrocode}
% We need numbers in words when in frontmatter. They are
% added in a special counter |आकडे| and used with a hook for
% frontmatter. The settings are reset after mainmatter is
% started.
%    \begin{macrocode}
    counters / आकडे =
    एक~ दोन~ तीन~ चार~ पाच~
    सहा~ सात~ आठ~ नऊ~ दहा~
    अकरा~ बारा~ तेरा~ चौदा~ पंधरा~
    सोळा~ सतरा~ अठरा~ एकोणीस~ वीस~
    एकवीस~ बावीस~ तेवीस~ चोवीस~ पंचवीस~
    सव्वीस~ सत्तावीस~ अठ्ठावीस~ एकोणतीस~ तीस~
    एकतीस~ बत्तीस~ तेहतीस~ चौतीस~ पस्तीस~
    छत्तीस~ सदतीस~ अडतीस~ एकोणचाळीस~ चाळीस~
    एकेचाळीस~ बेचाळीस~ त्रेचाळीस~ चव्वेचाळीस~ पंचेचाळीस~
    शेहेचाळीस~ सत्तेचाळीस~ अठ्ठेचाळीस~ एकोणपन्नास~ पन्नास~
    एकावन्न~ बावन्न~ त्रेपन्न~ चौपन्न~ पंचावन्न~
    छप्पन्न~ सत्तावन्न~ अठ्ठावन्न~ एकोणसाठ~ साठ~
    एकसष्ट~ बासष्ट~ त्रेसष्ट~ चौसष्ट~ पासष्ट~
    सहासष्ट~ सदुष्ट~ अडुसष्ट~ एकोणसत्तर~ सत्तर~
    एकाहत्तर~ बाहत्तर~ त्र्याहत्तर~ चौऱ्याहत्तर~ पंचाहत्तर~
    शाहत्तर~ सत्त्याहत्तर~ अठ्ठ्याहत्तर~ एकोणऐंशी~ ऐंशी~
    एक्याऐंशी~ ब्याऐंशी~ त्र्याऐंशी~ चौऱ्याऐंशी~ पंच्याऐंशी~
    श्याऐंशी~ सत्त्याऐंशी~ अठ्ठ्याऐंशी~ एकोणनव्वद~ नव्वद~
    एक्याण्णव~ ब्याण्णव~ त्र्याण्णव~ चौऱ्याण्णव~ पंचाण्णव~
    शहाण्णव~ सत्त्याण्णव~ अठ्याण्णव~ नव्याण्णव~ शंभर
  ] { marathi }
  \hook_gput_code:nnn { cmd / frontmatter / after } { . } {
    \cs_set:Npn \thepage {
      \localecounter { आकडे } { page }
    }
  }
  \hook_gput_code:nnn { cmd / mainmatter / after } { . } {
    \cs_set:Npn \thepage {
      \marathicounter { page }
    }
  }
%    \end{macrocode}
% The |\arraystretch| command needs to be reset to a larger
% value so that it can incorporate Marathi’s vertical
% conjuncts.
%    \begin{macrocode}
  \cs_set:Npn \arraystretch { 1.2 }
%    \end{macrocode}
% I have used only the bold and light variant of Mukta for
% all the fonts. In sans and mono, the width of the New
% Computer Modern fonts is slightly more, so I use the
% ‘regular’ variant of Mukta there. Otherwise, Mukta-Light
% is a better match for New Computer Modern Book.
%    \begin{macrocode}
  \clist_map_inline:nn {
    upright,
    italic,
    slanted,
    swash
  } {
    \lngx_set_keys:n {
      text~ #1               = { Mukta - Light . ttf   },
      text~ bold~ #1         = { Mukta - Bold . ttf    },
      text~ sans~ #1         = { Mukta - Regular . ttf },
      text~ sans~ bold~ #1   = { Mukta - Bold . ttf    },
      text~ mono~ #1         = { Mukta - Regular . ttf },
      text~ mono~ bold~ #1   = { Mukta - Bold . ttf    }
    }
  }
%    \end{macrocode}
% Using the |text extra features| key, I declare
% \textsc{nfss} families called |देवनागरी_main|,
% |देवनागरी_sans|, |देवनागरी_mono| that will be used
% later. Also, I use the key for interword-spacing here.
%    \begin{macrocode}
  \lngx_set_keys:n {
    text~ extra~
    features                 = {
      NFSSFamily               = { देवनागरी_main },
      WordSpace                = {
        \fp_use:N \g_मराठी_शब्दांतील_अंतर_fp
      }
    },
    text~ sans~ extra~
    features                 = {
      NFSSFamily               = { देवनागरी_sans },
      WordSpace                = {
        \fp_use:N \g_मराठी_शब्दांतील_अंतर_fp
      }
    },
    text~ mono~ extra~
    features                 = {
      NFSSFamily               = { देवनागरी_mono },
      WordSpace                = {
        \fp_use:N \g_मराठी_शब्दांतील_अंतर_fp
      }
    }
  }
} {
%    \end{macrocode}
% In the false branch (i.e., if Marathi is not the main
% language), I use the macros that set the ‘other’
% (non-main) fonts for Marathi. The fonts are the same, but
% the key-value interface is not available, so the code is
% slightly verbose. Before that we load the |onchar| option
% with |ids| and |fonts| options.
%    \begin{macrocode}
  \babelprovide [ onchar     = { ids~ fonts } ] { marathi }
  \lngx_other_main_font:nee { marathi } {
    WordSpace                = {
      \fp_use:N \g_मराठी_शब्दांतील_अंतर_fp
    },
    NFSSFamily               = { देवनागरी_main },
    UprightFont              = { Mukta - Light . ttf   },
    ItalicFont               = { Mukta - Light . ttf   },
    BoldFont                 = { Mukta - Bold . ttf    },
    BoldItalicFont           = { Mukta - Bold . ttf    },
    SlantedFont              = { Mukta - Light . ttf   },
    BoldSlantedFont          = { Mukta - Bold . ttf    },
    SwashFont                = { Mukta - Light . ttf   },
    BoldSwashFont            = { Mukta - Bold . ttf    },
    SmallCapsFont            = { Mukta - Light . ttf   }
  } { Mukta - Light . ttf }
  \lngx_other_sans_font:nee { marathi } {
    WordSpace                = {
      \fp_use:N \g_मराठी_शब्दांतील_अंतर_fp
    },
    NFSSFamily               = { देवनागरी_sans },
    UprightFont              = { Mukta - Regular . ttf },
    ItalicFont               = { Mukta - Regular . ttf },
    BoldFont                 = { Mukta - Bold . ttf    },
    BoldItalicFont           = { Mukta - Bold . ttf    },
    SlantedFont              = { Mukta - Regular . ttf },
    BoldSlantedFont          = { Mukta - Bold . ttf    },
    SwashFont                = { Mukta - Regular . ttf },
    BoldSwashFont            = { Mukta - Bold . ttf    },
    SmallCapsFont            = { Mukta - Regular . ttf }
  } { Mukta - Regular . ttf }
  \lngx_other_mono_font:nee { marathi } {
    WordSpace                = {
      \fp_use:N \g_मराठी_शब्दांतील_अंतर_fp
    },
    NFSSFamily               = { देवनागरी_mono },
    UprightFont              = { Mukta - Regular . ttf },
    ItalicFont               = { Mukta - Regular . ttf },
    BoldFont                 = { Mukta - Bold . ttf    },
    BoldItalicFont           = { Mukta - Bold . ttf    },
    SlantedFont              = { Mukta - Regular . ttf },
    BoldSlantedFont          = { Mukta - Bold . ttf    },
    SwashFont                = { Mukta - Regular . ttf },
    BoldSwashFont            = { Mukta - Bold . ttf    },
    SmallCapsFont            = { Mukta - Regular . ttf }
  } { Mukta - Regular . ttf }
}
%    \end{macrocode}
% In order to allow Devanagari in math mode, I use the
% following code. Since this setting has to be done after
% the initialisation, I use a hook for lazy loading.
%    \begin{macrocode}

\IfPackageLoadedT { lua-unicode-math } {
  \DeclareSymbolFont { देवनागरी }
                     { TU }
                     { देवनागरी_main }
                     { m }
                     { n }
}

\hook_gput_code:nnn { begindocument / end } { . } {
  \IfPackageLoadedF { lua-unicode-math } {
    \DeclareSymbolFont { देवनागरी }
                       { TU }
                       { देवनागरी_main }
                       { m }
                       { n }
  }
  \int_step_inline:nnn { "0900 } { "097F } {
    \Umathcode #1 = "0 ~ \use:c { symदेवनागरी } ~ #1
  }
}
%</marathi>
%    \end{macrocode}
% \end{implementation}
% \selectlanguage{english}
% \Finale
