清單中自動小寫

清單中自動小寫

我相信這是一個非常簡單的問題,可能有一個非常簡單的答案,到目前為止我還沒有找到:如何將常規列表LaTeX2e(例如enumerate)中每個項目的文本強制排版為全小寫?我的問題是\lowercaseor\MakeLowercase是需要分隔參數的命令,而 an 則不是這樣\item,因為它作為控制序列工作。我的動機:有時我希望將項目列表中的文本排版為小型大寫字母,並且所有字符都與小寫字母高度相對應,但我希望能夠這樣做而無需在 a 上使用上述命令手動的每個項目的基礎上。最簡單的答案(只需以全小寫形式輸入文本)不會成為有用的答案,因為我希望能夠使用相同的文本,而無需重新輸入它,作為常規\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都不會首先設置為小寫。

相關內容