在 LaTeX 中,“主动”声明(不带参数的命令)会\Gamma
向输出流生成可打印字符,而“被动”声明则\itshape
不会生成可打印字符。是否有一个宏(或如何编写一个宏)在给定 LaTeX 声明作为参数的情况下,可以确定该声明是主动的还是被动的?
我需要能够解决这个问题,以便正确格式化带有嵌入声明的输入 LaTeX 参数的呈现。
答案1
这不是对当前所述问题的回答。鉴于 darrelld 的一些评论,我认为目标是定义一个宏,,将其参数置于标题大小写中。这可以以不同程度的稳健性完成,但一种方法是一次读取一个标记并使用和\TitleCase
转换字母。\uppercase
\lowercase
这里,\TitleCase@case
始终是\uppercase
或:它在命令的最开始处以及每个空格后\lowercase
设置为。它由任何字母设置为。\uppercase
\TitleCase
\lowercase
结果每次被存储到 中\TitleCase@tl
,并在最后使用。
\makeatletter
\newcommand*{\TitleCase@tl}{}
\newcommand*{\TitleCase@case}{}
\newcommand*{\TitleCase@marker}{\TitleCase@marker}
\DeclareRobustCommand{\TitleCase}[1]
{%
\let\TitleCase@tl\empty
\let\TitleCase@case\uppercase
\TitleCase@#1\TitleCase@marker
\TitleCase@tl
}
\newcommand*{\TitleCase@}{\futurelet\@let@token\TitleCase@@}
\newcommand*{\TitleCase@@}
{%
\ifcase 0%
\ifcat\noexpand\@let@token\bgroup 1\fi
\ifx\@let@token\@sptoken 2\fi
\ifx\@let@token\TitleCase@marker 3\fi
\relax
\expandafter\TitleCase@normal
\or \expandafter\TitleCase@group
\or \expandafter\TitleCase@space
\or \expandafter\@gobble
\fi
}
\newcommand{\TitleCase@normal}[1]
{%
\TitleCase@case
{%
\expandafter\def\expandafter\TitleCase@tl\expandafter
{\TitleCase@tl #1}%
}%
\ifcat A\noexpand\@let@token
\let\TitleCase@case\lowercase
\fi
\TitleCase@
}%
\newcommand{\TitleCase@group}[1]
{%
\begingroup
\let\TitleCase@tl\empty
\TitleCase@ #1\TitleCase@marker
\expandafter
\endgroup
\expandafter\expandafter\expandafter\def
\expandafter\expandafter\expandafter\TitleCase@tl
\expandafter\expandafter\expandafter{%
\expandafter\TitleCase@tl\expandafter{\TitleCase@tl}}%
\TitleCase@
}
\newcommand{\TitleCase@space}
{\afterassignment\TitleCase@space@\let\@let@token= }
\newcommand{\TitleCase@space@}
{%
\let\TitleCase@case\uppercase
\expandafter\expandafter\expandafter\def
\expandafter\expandafter\expandafter\TitleCase@tl
\expandafter\expandafter\expandafter{\expandafter\TitleCase@tl\space}%
\TitleCase@
}
\makeatother
\documentclass{article}
\begin{document}
\section{\TitleCase{helLo, \itshape wo\textup{Rl}D!}}
\end{document}