1

I want to convert a number to string at the beginning of a sentence.

Using the builtin functions in memoir class works fine… in english only. Thus I use the fmtcount package. However string from number is not correctly capitalised: for instance

\Numberstringnum{24}

leads to “Twenty-Four“ when I want “Twenty-four“.

I tried this solution, with no success…

Here is my MWE

% !TeX TS-encoding = utf8
% !TeX TS-spellcheck = fr_FR
% !BIB TS-program = biber
% !TeX TS-program = lualatex
\documentclass[12pt, a4paper]{memoir}

\RequirePackage[utf8]{luainputenc}
\RequirePackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
\RequirePackage{polyglossia}
\setmainlanguage{french}
\setotherlanguage[variant=british]{english}
\RequirePackage{fmtcount}
\FCloadlang{francais}
\fmtcountsetoptions{french={all plural=traditional}}
\usepackage{xparse}

\ExplSyntaxOn
\DeclareExpandableDocumentCommand \firstcap { m } { \tl_mixed_case:n {#1} }
\ExplSyntaxOff

\begin{document}
% Works fine… but only in english
\ordinaltoName{25}

% Works but every first letter capitalised
\Numberstring{part}
\Numberstringnum{1987}

\firstcap{qsdfg wxcvvcr} % works
%\firstcap{\numberstringnum{1987}} % leads to error « Improper alphabetic constant. »

\end{document}
NBur
  • 4,326
  • 10
  • 27
  • not directly related but why \RequirePackage[utf8]{luainputenc} ?this can be used for solving some specific compatibility issues but it disables most of the benefits of luatex's Unicode font support. – David Carlisle Jan 03 '18 at 22:25
  • @David Carlisle: it a remaining line in order to use frcusive. – NBur Jan 03 '18 at 22:27
  • @Christian Hupfer :) that was what I understood! – NBur Jan 03 '18 at 22:34
  • Your example sets French as the default language; I'm not sure where the problem is; if it is for English, you should make it clear in the example. – egreg Jan 03 '18 at 22:49
  • Off-topic, but relevant: Just last week, fmtcount was updated. Previously, luatex was not correctly detected. Under certain circumstances, a luatex user might find that the text was positioned incorrectly. Now it has been fixed, I believe. Also, be sure to load polyglossia, and set the default language, before loading fmtcount. –  Jan 03 '18 at 22:58
  • Furthermore: According to the authoritative Chicago Manual of Style, 17th Edition, item 8.161, if the usage is "headline style," then both numbers are capitalized in English: Twenty-Four. I presume that a chapter title would be "headline style," thus "Chapter Twenty-Four" would be preferred. Although there was some mention of French usage in other contexts, numbers were not discusser there. –  Jan 03 '18 at 23:10

2 Answers2

1

You should use \Ordinalstringnum, not \ordinaltoName that's memoir specific and only supports English.

\documentclass[12pt, a4paper]{memoir}

\usepackage{fontspec}
\usepackage{polyglossia}

\usepackage{fmtcount}
\usepackage{xparse}

\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
\setmainlanguage{french}
\setotherlanguage[variant=british]{english}

\FCloadlang{francais}
\fmtcountsetoptions{french={all plural=traditional}}

\begin{document}

\Ordinalstringnum{25}

\Numberstring{part}

\Numberstringnum{1987}

\end{document}

enter image description here

If your aim is to use this also for other languages, you can define your own commands based on \tl_mixed_case:n:

\documentclass[12pt, a4paper]{memoir}

\usepackage{fontspec}
\usepackage{polyglossia}

\usepackage{fmtcount}
\usepackage{xparse}

\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
\setmainlanguage{french}
\setotherlanguage[variant=british]{english}

\FCloadlang{francais}
\fmtcountsetoptions{french={all plural=traditional}}

\ExplSyntaxOn
\NewDocumentCommand{\Unumberstring}{mO{m}}
 {
  \nbur_fmtcount:Nnn \storenumberstring { #1 } { #2 }
 }
\NewDocumentCommand{\Unumberstringnum}{mO{m}}
 {
  \nbur_fmtcount:Nnn \storenumberstringnum { #1 } { #2 }
 }
\NewDocumentCommand{\Uordinalstring}{mO{m}}
 {
  \nbur_fmtcount:Nnn \storeordinalstring { #1 } { #2 }
 }
\NewDocumentCommand{\Uordinalstringnum}{mO{m}}
 {
  \nbur_fmtcount:Nnn \storeordinalstringnum { #1 } { #2 }
 }
\cs_new_protected:Nn \nbur_fmtcount:Nnn
 {
  #1{nbur-string}{#2}[#3]
  \tl_mixed_case:n { \FMCuse{nbur-string} }
 }
\ExplSyntaxOff


\begin{document}

\Uordinalstringnum{25}

\Unumberstring{part}

\Unumberstringnum{1987}

\selectlanguage{english}

\Uordinalstringnum{25}

\Unumberstring{part}

\Unumberstringnum{1987}

\end{document}

enter image description here

egreg
  • 1,121,712
  • Thank you so much for this great answer I'm going to use since I'll eventually change the language within the document. However, I accepted David Carlisle's answer since he solves elegantly my OP. – NBur Jan 04 '18 at 08:08
0

enter image description here

You can do it in two steps:

% !TeX TS-encoding = utf8
% !TeX TS-spellcheck = fr_FR
% !BIB TS-program = biber
% !TeX TS-program = lualatex
\documentclass[12pt, a4paper]{memoir}

\RequirePackage[utf8]{luainputenc}
\RequirePackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
\RequirePackage{polyglossia}
\setmainlanguage{french}
\setotherlanguage[variant=british]{english}
\RequirePackage{fmtcount}
\FCloadlang{francais}
\fmtcountsetoptions{french={all plural=traditional}}
\usepackage{xparse}

\ExplSyntaxOn
\DeclareExpandableDocumentCommand \firstcap { m } { \tl_mixed_case:n {#1} }
\ExplSyntaxOff

\begin{document}
% Works fine… but only in english
\ordinaltoName{25}

% Works but every first letter capitalised
\Numberstring{part}
\Numberstringnum{1987}

\firstcap{qsdfg wxcvvcr} % works

\storenumberstringnum{zz}{1987}

\firstcap{\FMCuse{zz}}

\end{document}
David Carlisle
  • 757,742