列表中自动使用小写字母

列表中自动使用小写字母

我相信这是一个非常简单的问题,可能有一个非常简单的答案,到目前为止我还没有找到:如何强制将常规列表LaTeX2e(例如enumerate)中每个项目的文本排版为全小写?我的问题是\lowercase\MakeLowercase命令需要分隔参数,而它不是这种情况\item,因为它作为控制序列工作。我的动机:有时我想将项目列表中的文本排版为小写,并使所有字符都与小写字母的高度相对应,但我希望能够做到这一点,而不必在手动的按项目计算。最简单的答案(只需输入全小写的文本)并不是有用的答案,因为我希望能够使用相同的文本,而不需要重新输入它,就像使用常规\upshape文本一样。

编辑:我已将 A. Ellett 的提议勾选为答案,因为它的功能符合我的问题,而且我认为它本身就是一项有价值且经过深思熟虑的贡献。尽管如此,如果可行的话,更简单的方法仍然会受到欢迎。

答案1

此更新版本(请参阅旧版本的修订历史记录)不需要用户向其环境添加任何功能。不需要\item*或类似的东西。这是通过在\item第一次迭代中偷偷加入然后转移(重新定义再次\item我添加了大量注释,以便您能够修改此代码以更好地满足您的需要。

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\makeatletter

%% We will use two versions for redefining \item                       
%% The first version is temporary and only used                        
%% for the first iteration.  It's purpose is to                        
%% allow us to slip in an \item just before the                        
%% environment is ended.                                               
\def\@ae@item@va@#1\item#2\@nil{%%
  \def\item##1\end{\@ae@item@vb@##1\@nil}%%
  \@ae@item@vb@#1\item#2\@nil}

\def\@ae@item@vb@#1\item#2\@nil{%%
  %% Don't immediately pass to \olditem                                
  %% we need to see whether there's any optional                       
  %% arguments being passed to \item                                   
  \ae@olditem #1\@nil%%
  %% If second argument is empty, then that means                      
  %% we've parsed the entire environment and should                    
  %% quit.  Restore the "\end" we stole earlier.                       
  \if\relax\detokenize{#2}\relax
    \expandafter\end
  \else
    %% We don't want to get too deeply buried within                   
    %% \if...\fi structures.  So save #2 to a macro                    
    %% then call a dummy macro, but only after first                   
    %% leaving the \if...\fi structure.                                
    \def\ae@tmp{#2}%%
    \expandafter\@@ae@continue@iterating@item
  \fi}

%% Test whether there's an optional argument.                          
\def\ae@olditem{%%
  \@ifnextchar[%]
    {\@o@ae@olditem}
    {\@@ae@olditem}}
\def\@o@ae@olditem[#1]{\olditem[#1] \@@ae@@format}
\def\@@ae@olditem{\olditem \@@ae@@format}
%% The actual formatting of the content following \item
\def\@@ae@@format#1\@nil{%%
  \bgroup\scshape\lowercase{#1}\egroup}
%% The macro handling the continuation of iterating over               
%% the \item's in the environment.  Notice the use of                  
%% \expandafter.  We don't want to pass the formatting                 
%% macro content buried into a temporary macro.  Remember              
%% the \ae@tmp was only used to help us jump out of the                
%% \if ... \fi structure.                                              
\def\@@ae@continue@iterating@item{%%
  \expandafter\item\ae@tmp\end}

\newenvironment{mylc}
  {%%
    \begin{enumerate}
    \let\olditem\item
    %% new definition for \item but only good for first iteration.     
    %% This is how we smuggle in a final \item                         
    %% just before ending the environment.  Here we                    
    %% also steal the `\end` which closes the environment.             
    %% We'll have to restore that before we're done.                   
    \def\item##1\end{%%
      \@ae@item@va@##1\item\@nil}
  }
  {\end{enumerate}}

\makeatother
\def\aerandomstuff{A random string of stuff.}
\begin{document}

  \begin{mylc}
  \item  `A' is for Amy who\ldots
  \item[<optional argument>] This line has an optional argument.
  \item  
  \item  The previous item was empty, but that won't cause us to
         prematurely terminate.
  \item  Matter buried in a macro will not be handled correctly: \aerandomstuff
  \item  This is the last line. No special mark up needed.
  \end{mylc}

\end{document}

在此处输入图片描述

关于扩展问题:\lowercase仅适用于扩展内容。任何偷运进来的内容(就像我所做的那样)\aerandomstuff都不会先设置为小写。

相关内容