vincentb1 / fmtcount

Source for LaTeX fmtcount package
11 stars 5 forks source link

Open up fmtcount to custom language files #48

Open fredrikpaues opened 1 year ago

fredrikpaues commented 1 year ago

I am a bit out of my depth here, but it would be great if \FCloadlang{lang} could define lang as xkeyval key in the fmtcount family so that custom language files could then set up language options as fc-french.def does.

I'm trying to incorporate such options into the fc-swedish.def language file that I've posted in #47. But it's proving quite hard. While a quite simple document

\documentclass[swedish]{article}
\usepackage{babel}
\usepackage{fmtcount}
\FCloadlang{swedish}
\begin{document}
  \Ordinalstringnum{12}
\end{document}

allows me to format numbers in Swedish, it seems that I need to do part of the heavy lifting that arguable ought to be done in fmtcount.sty to set up language options. Sadly, I haven't figured out how to do it yet.

fredrikpaues commented 1 year ago

It seems that this setup allows me to add options in the same way as fc-french.def:

\documentclass[swedish]{article}
\usepackage{babel}
\usepackage{fmtcount}
\FCloadlang{swedish}
\makeatletter
\define@key{fmtcount}{swedish}[]{%
  \setkeys{fcswedish}{#1}%
}
\define@key{fcswedish}{fmtord}{%
  \ifthenelse{\equal{#1}{raise}\or\equal{#1}{level}}{%
    \expandafter\let\expandafter\@tempa\csname fc@set@ord@as@#1\endcsname
    \expandafter\@tempa\csname fc@ord@swedish\endcsname
  }{%
    \ifthenelse{\equal{#1}{undefine}}{%
      \expandafter\let\csname fc@ord@swedish\endcsname\undefined
    }{%
      \PackageError{fmtcount}%
      {Invalid value `#1' to fmtord key}%
      {Option `fmtord' can only take the values `level', `raise'
        or `undefine'}%
    }
  }
}
\makeatother
\fmtcountsetoptions{swedish={one=hundred, space=both}}
\begin{document}
  \newcounter{mycounter}
  \setcounter{mycounter}{8} \themycounter\ \Numberstring{mycounter}\\
\end{document}