我准备记录一些内容,以内容做章节,比如在写的时候就写
\chapter{内容大类1}
\section{日期1,具体内容}
blabla
\section{日期3,具体内容}
注意这里日期3在日期2后面
\chapter{内容大类2}
\section{日期2,具体内容}
bla然后生成的目录是以内容区分好的。但是我还希望能有一个按日期排列的目录,这个日期显示与否其实不是特别重要,但是我希望这个目录是按日期的顺序排列的。
因为内容目录会生成类似
第 1 章 内容大类1 ... 页码
1.1. 日期1,具体内容 ... 页码
1.2. 日期3,具体内容 ... 页码
第 2 章 内容大类2 ... 页码
2.1. 日期2,具体内容 ... 页码
这种效果,那目前我希望日期目录是类似
1.1. 日期1,具体内容 ... 页码
2.1. 日期2,具体内容 ... 页码
1.2. 日期3,具体内容 ... 页码
这样的形式。当然如果有其他的形式,只要是按日期排列都是可以的。在此先行谢过回答的大佬。
试着做了一下
\documentclass{article}
\usepackage{lipsum}
\ExplSyntaxOn
\NewCommandCopy{\oldsection}{\section}
\keys_define:nn { alfred }
{
  date .clist_set:N = \l__alfred_date_tl,
  title .tl_set:N = \l__alfred_title_tl
}
\cs_new:Npn \alfred_parse_date:nN #1#2
{
  \tl_clear:N \l_tmpa_tl
  \clist_map_inline:nn { #1 }
  {
    \tl_put_right:Nn \l_tmpa_tl { ##1 }
  }
  \tl_set_eq:NN #2 \l_tmpa_tl 
}
\cs_new:Npn \alfred_parse_datefmt:nN #1#2 
{
  \tl_set:Ne \l_tmpa_tl 
  {
    \clist_item:nn {#1}{1}-
    \clist_item:nn {#1}{2}-
    \clist_item:nn {#1}{3}
  }
  \tl_set_eq:NN #2 \l_tmpa_tl 
}
\clist_new:N \g__alfred_date_clist 
\prop_new:N \g__alfred_section_date_title_prop
\tl_new:N \l__alfred_tmpa_tl 
\tl_new:N \l__alfred_tmpb_tl 
\tl_new:N \l__alfred_tmpc_tl 
\RenewDocumentCommand{\section}{sm}{
  \group_begin:
  \IfBooleanTF{#1}
  {
    \oldsection*{#2}
  }
  {
    \keys_set:nn { alfred } { #2 }
    \exp_args:NV \alfred_parse_date:nN \l__alfred_date_tl \l__alfred_tmpa_tl
    \exp_args:NV \alfred_parse_datefmt:nN \l__alfred_date_tl \l__alfred_tmpb_tl 
    \exp_args:No \oldsection { \l__alfred_tmpb_tl,~\l__alfred_title_tl }
    \clist_gput_right:NV \g__alfred_date_clist \l__alfred_tmpa_tl
    \prop_gput:NVx \g__alfred_section_date_title_prop \l__alfred_tmpa_tl 
    {
      \exp_not:N \contentsline{section}{\exp_not:N \numberline{\thesection} \l__alfred_tmpb_tl,~\l__alfred_title_tl}{\thepage}{}
    }
  }
  \group_end:
}
\iow_new:N \g__date_toc_iow
\AtEndDocument
{
  \clist_sort:Nn \g__alfred_date_clist
  {
    \int_compare:nNnTF { #1 } > { #2 }
    { \sort_return_swapped: }
    { \sort_return_same: }
  }
  \iow_open:Nn \g__date_toc_iow { \c_sys_jobname_str.date.toc }
  \clist_map_inline:Nn \g__alfred_date_clist 
  {
    \prop_get:NnN \g__alfred_section_date_title_prop { #1 } \l__alfred_tmpc_tl
    \exp_args:NNV \iow_now:Nn \g__date_toc_iow \l__alfred_tmpc_tl
  }
  \iow_close:N \g__date_toc_iow
}
\NewDocumentCommand{\tableofcontentswithdate}{}
{
  \section*{Contents~With~Date}
  \makeatletter
  \file_if_exist_input:n { \c_sys_jobname_str.date.toc }
  \makeatother
  \vspace*{.5in}
}
\ExplSyntaxOff
\begin{document}
\tableofcontents
\tableofcontentswithdate
\section{title = first, date = {2024, 09, 19}}
\lipsum[1-10]
\section{title = second, date = {2023, 06, 05}}
\lipsum[1-10]
\section{title = third, date = {2024, 08, 10}}
\lipsum[1-10]
\end{document}