有没有办法自动将文本格式化为标题大小写?例如输入:
\somemagiccommand{the table, the ass and the stick}
其结果为:
The Table, the Ass and the Stick
我已经在互联网上搜索过,但没有发现任何比手动进行套管更有效的方法......
答案1
\documentclass{article}
\makeatletter
\def\somemagiccommand#1{%
\let\tc@w\@empty
\protected@edef\tmp{\noexpand\tc@a#1\relax}\expandafter\tc@uc@\tmp}
\def\tc@a{\futurelet\tmp\tc@aa}
\def\tc@aa{%
\ifcat a\noexpand\tmp\expandafter\tc@ab
\else\expandafter\tc@ac\fi}
\def\tc@ab#1{\edef\tc@w{\tc@w#1}\tc@a}
\def\tc@ac{%
\csname tc@@\tc@w\endcsname\expandafter\tc@uc\tc@w
\let\tc@w\@empty
\ifx\tmp\@sptoken\let\next\tc@sp
\else\ifx\tmp\relax\let\next\relax
\else\let\next\tc@nxt
\fi\fi\next}
\def\tc@sp#1{ \tc@a#1}
\def\tc@nxt#1{#1\tc@a}
\def\tc@uc#1{\uppercase{#1}}
\def\tc@uc@#1#2{\uppercase{#1#2}}
\let\tc@@the\@gobbletwo
\let\tc@@and\@gobbletwo
\makeatother
\begin{document}
\somemagiccommand{the table, the ass and the stick}
\end{document}
答案2
你可能想要mfirstuc
及其命令\capitalisewords{}
。为了使像“the”这样的单词保持较小,我们必须通过隐藏它前面的空格来将其隐藏起来。这是通过使用\space
而不是实际空格来实现的。或者,您可以告诉解析器\MFUnocap
要省略哪些单词:
\documentclass{article}
\usepackage{mfirstuc}
\begin{document}
\capitalisewords{the table,\space the ass\space and\space the stick}
\MFUnocap{the}\MFUnocap{and}
\capitalisewords{the table, the ass and the stick}
\end{document}
答案3
这stringstrings
包中有一个\capitalizetitle
宏可以完成您想要的操作。您需要定义不大写的单词。
答案4
为了完整起见,这里是半自动解决方案#3:
\documentclass{scrartcl}
\usepackage{biblatex}
\begin{document}
Well {I} Have Searched the {ENTIRE} {I}nternet but Have Found Nothing\par
\MakeSentenceCase{Well {I} Have Searched the {ENTIRE} {I}nternet but Have Found Nothing}
\end{document}