使用 fmtcount 将第一个字母大写

使用 fmtcount 将第一个字母大写

我想将句子开头的数字转换为字符串。

使用 memoir 类中的内置函数效果很好……仅限英文。因此我使用 fmtcount 包。但是数字中的字符串没有正确大写:例如

\Numberstringnum{24}

当我想要“Twenty-four”时,结果却是“Twenty-F​​our”。

我试过此解决方案,但没有成功……

这是我的 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}

答案1

在此处输入图片描述

您可以分两个步骤完成:

% !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}

答案2

您应该使用\Ordinalstringnum,而不是特定\ordinaltoNamememoir并且仅支持英语。

\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}

在此处输入图片描述

如果您的目的是将其用于其他语言,您可以根据以下内容定义自己的命令\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}

在此处输入图片描述

相关内容