diff --git a/TeXmacs/packages/custom/appendix-toc.ts b/TeXmacs/packages/custom/appendix-toc.ts new file mode 100644 index 0000000000..719484b9ad --- /dev/null +++ b/TeXmacs/packages/custom/appendix-toc.ts @@ -0,0 +1,57 @@ + + +> + +<\body> + + + + <\src-purpose> + Support for independent table of contents in appendix sections. This + package allows creating a separate table of contents that only includes + appendix chapters, sections, and subsections. + + + + + <\src-license> + This software falls under the . It comes WITHOUT ANY + WARRANTY WHATSOEVER. You should have received a copy of the license + which the software. If not, see . + + > + + + >>> + > + + + >>> + > + + + >>> + > + + + |> + > + + + ||>|> + > + + + |section-toc||>> + + > + > + + + +<\initial> + <\collection> + + + diff --git a/TeXmacs/packages/section/section-base.ts b/TeXmacs/packages/section/section-base.ts index 13c1d3c6c9..bf3e8511e0 100644 --- a/TeXmacs/packages/section/section-base.ts +++ b/TeXmacs/packages/section/section-base.ts @@ -56,6 +56,8 @@ >> + >> + >> >> diff --git a/TeXmacs/plugins/lang/dic/en_US/zh_CN.scm b/TeXmacs/plugins/lang/dic/en_US/zh_CN.scm index a7497e5621..e63c086b61 100644 --- a/TeXmacs/plugins/lang/dic/en_US/zh_CN.scm +++ b/TeXmacs/plugins/lang/dic/en_US/zh_CN.scm @@ -4,6 +4,10 @@ ("Advanced page numbering" "高级页码") ("Allow multiple spaces" "允许多个空格") ("Angle brackets ⟨ ⟩" "尖括号 ⟨ ⟩") +("Appendix section" "附录节") +("Appendix subsection" "附录子节") +("Appendix subsubsection" "附录小节") +("Appendix table of contents" "附录目录") ("Applying from" "起始于") ("Applying to" "结束于") ("As" "作为") diff --git a/TeXmacs/progs/text/text-menu.scm b/TeXmacs/progs/text/text-menu.scm index ba6ccc20f9..056ea1c03a 100644 --- a/TeXmacs/progs/text/text-menu.scm +++ b/TeXmacs/progs/text/text-menu.scm @@ -135,6 +135,10 @@ ("Subparagraph" (make-section 'subparagraph)) --- ("Appendix" (make-section 'appendix)) + (if (has-style-package? "appendix-toc") + ("Appendix section" (make-section 'appendix-section)) + ("Appendix subsection" (make-section 'appendix-subsection)) + ("Appendix subsubsection" (make-section 'appendix-subsubsection))) ("Prologue::menu" (begin (make-unnamed-section 'prologue) @@ -471,6 +475,11 @@ (begin (make-aux "table-of-contents" "toc-prefix" "toc") (update-document "all"))) + (if (has-style-package? "appendix-toc") + ("Appendix table of contents" + (begin + (insert `(table-of-contents "appendix-toc" (document ""))) + (update-document "all")))) ("Bibliography" (open-bibliography-inserter)) ("Index" (begin diff --git a/TeXmacs/tests/tmu/222_54.tmu b/TeXmacs/tests/tmu/222_54.tmu new file mode 100644 index 0000000000..e65cb9ca2f --- /dev/null +++ b/TeXmacs/tests/tmu/222_54.tmu @@ -0,0 +1,81 @@ +> + +> + +<\body> + <\hide-preamble> + >>>> + + + <\table-of-contents|toc> + chapter>|.>>>>|> + + section|.>>>>|>> + + subsection|.>>>>|>> + + appendix>|.>>>>|> + + + + + + + + + \; + + + + <\table-of-contents|appendix-toc> + section>|.>>>>|> + + subsecton|.>>>>|>> + + + <\appendix-section> + section + + + <\appendix-subsection> + subsecton + + + +<\initial> + <\collection> + + + > + + + +<\references> + <\collection> + > + > + > + > + > + > + + + +<\auxiliary> + <\collection> + <\associate|appendix-toc> + |math-font-series||A.1section>|.>>>>|> + + |A.1.1subsecton|.>>>>|>> + + <\associate|toc> + |math-font-series||第 1 章chapter>|.>>>>|> + + |1.1section|.>>>>|>> + + |1.1.1subsection|.>>>>|>> + + |math-font-series||附录appendix>|.>>>>|> + + + diff --git a/devel/222_54.md b/devel/222_54.md new file mode 100644 index 0000000000..190fffd7d7 --- /dev/null +++ b/devel/222_54.md @@ -0,0 +1,47 @@ +# [222_54] 添加附录目录 (appendix-toc) 宏包 + +## 如何测试 +- 涉及ts文件的需要先清理缓存 +- 打开测试文件`TeXmacs/tests/tmu/222_54.tmu` + - 检查效果 +- 新建文件 + - 查看 `插入->自动`里是否有 附录目录 + - 查看 `插入->章节`里是否有 附录节 附录子节 附录小节 + - 点击工具栏 `增加宏包->custom->appendix-toc`,添加本宏包 + - 重复查看上述部分 + - 测试使用 + - 结构如下 + |- + |- + |- + |- + |- + + +## 2025/03/11 实现附录子目录宏包 + +### What +创建了 `appendix-toc.ts` 宏包,位于 `TeXmacs/packages/custom/`,提供以下功能: +- `` - 附录内的 section,使用 "appendix-toc" 前缀 +- `` - 附录内的 subsection,使用 "appendix-toc" 前缀 +- `` - 附录内的 subsubsection,使用 "appendix-toc" 前缀 +- `` - 通用宏,用于创建任意范围的子目录 + +### Why +- 原系统所有章节标题都写入同一个 `local_aux["toc"]`,无法实现范围限定的子目录 +- 用户需要在附录范围内有一个独立的目录,只包含附录章节 +- 通过切换 `toc-prefix` 参数,可以实现任意范围的子目录 + +### How +1. 利用现有的 `with-toc` 宏切换 `toc-prefix`: + ```ts + |>>> + ``` + +2. 附录内的 section/subsection 同样使用 `with|toc-prefix|appendix-toc` 包装 + +3. 核心原理: + - `toc-entry` 宏使用 `|...>` 写入 aux 数据 + - 通过 `with|toc-prefix|` 临时改变前缀 + - 不同前缀的数据存储在独立的 `local_aux` 键中 + - `` 只读取 "appendix-toc" 键的数据