如何按字母顺序对用 tocloft 定义的自定义列表进行排序?

如何按字母顺序对用 tocloft 定义的自定义列表进行排序?

我使用以下代码定义了一个“定义列表”:

\documentclass[a4paper, 12pt]{report}

\usepackage{subcaption}
\usepackage[subfigure]{tocloft}
\usepackage{blindtext}


\newcommand{\listdefinitionname}{List of Definitions}
\newlistof{definition}{def}{\listdefinitionname}

\newcommand{\define}[3]{
    \refstepcounter{definition}
    \label{definition:#2}
    \vspace*{2mm}
    \fbox{
        \begin{minipage}{\textwidth}
            \par\noindent\textbf{Definition \thedefinition.\\\linebreak \textit{#1}} #3
        \end{minipage}
    }    
    \vspace*{2mm}
    \addcontentsline{def}{definition}
    {\hspace{6mm} #1}\par
}

\newcommand{\listofdefinitions}{
    \phantomsection
    \addcontentsline{toc}{chapter}{List of Definitions}
    \listofdefinition
}

\begin{document} 

    \listofdefinitions
    \clearpage


    \blindtext

    \define{Silicon}{silicon}{
        The chemical element of atomic number 14, a non-metal with semiconducting properties, used in making electronic 
        circuits. Pure silicon exists in a shiny dark grey crystalline form and as an amorphous powder.
    }

    \blindtext

    \define{Latex}{latex}{
        A milky fluid found in many plants, such as poppies and spurges, which exudes when the plant is cut and 
        coagulates on exposure to the air. The latex of the rubber tree is the chief source of natural rubber.      
    }

\end{document}

截图:

第 1 页

在此处输入图片描述

第2页

在此处输入图片描述

与我的博士生导师讨论过几次之后,我认为更合适的做法是,不按出现顺序排列此列表,而是按字母顺序排列。

我怎样才能做这样的事?

答案1

tocloft旨在编辑 ToC 功能,即外观等,但没有排序功能。排序总是有点尴尬TeX,因此存在这样的外部程序makeindex

我建议定义一个词汇表数据库,def在其中添加术语的定义,然后使用它\define{foo}来显示词汇表条目“foo”。使用新词汇表的原因是为了防止与常规“主”词汇表混淆。

makeglossaries例如,排序是通过脚本完成的。

contentlike样式是一种新的词汇表样式,它以像目录中一样的方式显示词汇表条目。

pdflatex foo.tex ; makeglossaries foo ; pdflatex foo如果文档被调用,则运行foo.tex

以下是排序后的输出:

在此处输入图片描述

\documentclass[a4paper, 12pt]{report}


\usepackage{blindtext}

\usepackage[nomain,toc]{glossaries}

\newcounter{definition}

\newglossary{def}{defi}{defo}{List of Definitions}

\makeglossaries

\newglossaryentry{silicon}{
  type=def,
  name=Silicon,
  description={%
    The chemical element of atomic number 14, a non-metal with semiconducting properties, used in making electronic 
    circuits. Pure silicon exists in a shiny dark grey crystalline form and as an amorphous powder.
  }
}

\newglossaryentry{latex}{
  type=def,
  name=Latex,
  description={%
    A milky fluid found in many plants, such as poppies and spurges, which exudes when the plant is cut and 
    coagulates on exposure to the air. The latex of the rubber tree is the chief source of natural rubber.      
  }
}




\newcommand{\define}[1]{%
    \refstepcounter{definition}
    \label{definition:#1}
    \vspace*{2mm}
    \fbox{%
        \begin{minipage}{\textwidth}
          \par\noindent\textbf{Definition \thedefinition.\\\linebreak \textit{\glsentrytext{#1}}}           
          \glsdesc{#1}%
        \end{minipage}
      }    
    \vspace*{2mm}
    {\hspace{6mm}}\par
}


\newglossarystyle{contentlike}{%
  \renewenvironment{theglossary}%
  {\parindent0em}{}
  % have nothing after \begin{theglossary}:
  \renewcommand*{\glossaryheader}{}%
  % have nothing between glossary groups:
  \renewcommand*{\glsgroupheading}[1]{}%
  \renewcommand*{\glsgroupskip}{}
  \renewcommand*{\glossentry}[2]{%
    \textbf{\glstarget{##1}{\glossentryname{##1}}}\dotfill{##2}

  }%
}


\newcommand{\listofdefinitions}{%
  \setglossarystyle{contentlike}
  \printglossary[type=def,]
  \clearpage
}

\begin{document} 
\tableofcontents
\listofdefinitions


\blindtext

\define{silicon}

\blindtext

\define{latex}


\end{document}

相关内容