latex中英文字母大小写变换再讨论

您所在的位置:网站首页 公司口号标语大全集 latex中英文字母大小写变换再讨论

latex中英文字母大小写变换再讨论

2024-06-23 15:03| 来源: 网络整理| 查看: 265

latex中英文字母大小写变换再讨论

在英文的习惯中,特别是标题等内容中,大小写有一些常用的习惯。 在latex中如果正常输入英文段落和语句,通常作者会注意使用这些习惯,因此通常不太会需要太多的字母大小写转换。 反而在参考文献中,由于bib文件中的文献条目通常由网络获取,各个网站的习惯格式并不相同,所以通常没有一个统一的规范。 所以在参考文献的格式化过程中会更多的涉及到大小写转换。

关于大小写转换实践,我之前的文章已经讨论过一次,见 latex中字母大小写转换实践, Make the first letter of each word uppercase in sentence 。 这里是再梳理一下,并且提供一下统一的命令,命令主要借助biblatex,mfirstuc宏包实现。

英文习惯中的大小写样式 样式说明示例Sentence case句子模式(一个句子中除首字母大写外其它全部小写)The quick brown fox jumps over the lazy dogTitle case标题模式(一个句子各单词首字母均大写)The Quick Brown Fox Jumps over the Lazy DogAll caps全大写(一个句子全部大写)THE QUICK BROWN FOX JUMPS OVER THE LAZY DOGAll lowercase全小写(一个句子全部小写)the quick brown fox jumps over the lazy dogSmall caps小大写字母模式(一个句子中除首字母大写外其它全部用smallcap字母)The quick brown fox jumps over the lazy dog latex中的实现

latex提供了基础命令MakeUppercase、MakeLowercase,可以将整个句子进行大小写转换,且不考虑{}符号进行保护。 biblatex提供了MakeCapital和MakeSentenceCase,前者仅将句子首字母大写,后者除首字母大写外,也对剩余字母小写,支持{}符号的大小写保护。 mfirstuc提供了capitalisewords命令,可以将句子中所有的单词的首字母大写,不支持{}的保护,但可以用\MFUnocap命令进行保护。

为了方便使用,我们可以使用统一的命名方式来实现多种习惯大小写写法的命令,比如:

通过如下定义:

\makeatletter \def\firstletterparse#1#2&{\def\strfirstletter{#1}\def\strotherletters{#2}} \newcommand{\MakeSmallcaps}[1]{% \expandafter\firstletterparse#1& \expandafter\MakeUppercase\strfirstletter\textsc{\strotherletters}% }%\textrm \newcommand{\MakeTitlecase}[1]{% \capitalisewords{#1} } \makeatother

可以提供了前述所有模式的大小写方式:

命令说明可实现样式\MakeCapital{a small book of {SUN} rhyme}一个句子中首字母大写,其字母不变Sentence case\MakeSentenceCase{a small book of {SUN} rhyme}一个句子中除首字母大写外其它全部小写Sentence case\MakeTitlecase{a small book of {SUN} rhyme}一个句子各单词首字母均大写Title case\MakeUppercase{a small book of {SUN} rhyme}一个句子全部大写All caps\MakeLowercase{a small book of {SUN} rhyme}一个句子全部小写All lowercase\MakeSmallcaps{a small book of {SUN} rhyme}一个句子中除首字母大写外其它全部用smallcap字母Small caps 示例

这里给出一个测试文档:

\documentclass{article} \usepackage{ctex} \usepackage[backend=biber]{biblatex} \usepackage{mfirstuc} \makeatletter \def\firstletterparse#1#2&{\def\strfirstletter{#1}\def\strotherletters{#2}} \newcommand{\MakeSmallcaps}[1]{% \expandafter\firstletterparse#1& \expandafter\MakeUppercase\strfirstletter\textsc{\strotherletters}% }%\textrm \newcommand{\MakeTitlecase}[1]{% \capitalisewords{#1} } \makeatother \begin{document} \MakeUppercase{a small book of {SUN} rhyme} \MakeLowercase{a small book of {SUN} rhyme} \MakeCapital{a small book of {SUN} rhyme} \MakeSentenceCase{a small book of {SUN} rhyme} \MFUnocap{of} \MakeTitlecase{a small book of {SUN} rhyme} \MakeSmallcaps{a small book of {SUN} rhyme} \end{document} 小结

如此,我们通过统一的命名实现英文习惯大小写方式,可以在biblatex参考文献样式中可以有非常多的应用。

enjoy!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3