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

本文介绍在Latex中实现不同英文大小写样式的技巧,包括Sentencecase、Titlecase等,并提供统一命令实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 dog
Title case标题模式(一个句子各单词首字母均大写)The Quick Brown Fox Jumps over the Lazy Dog
All caps全大写(一个句子全部大写)THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
All lowercase全小写(一个句子全部小写)the quick brown fox jumps over the lazy dog
Small 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!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值