Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions TeXmacs/packages/custom/appendix-toc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<TeXmacs|2.1.4>

<style|<tuple|source|std|section-base>>

<\body>
<active*|<\src-title>
<src-package|appendix-toc|1.0>

<\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-purpose>

<src-copyright|2026|Soyo and Yuki>

<\src-license>
This software falls under the <hlink|GNU general public license,
version 3 or later|$TEXMACS_PATH/LICENSE>. It comes WITHOUT ANY
WARRANTY WHATSOEVER. You should have received a copy of the license
which the software. If not, see <hlink|http://www.gnu.org/licenses/gpl-3.0.html|http://www.gnu.org/licenses/gpl-3.0.html>.
</src-license>
</src-title>>

<assign|appendix-section|<\macro|title>
<section|<arg|title>><with|toc-prefix|appendix-toc|<toc-main-2|<the-section><section-sep><arg|title>>>
</macro>>

<assign|appendix-subsection|<\macro|title>
<subsection|<arg|title>><with|toc-prefix|appendix-toc|<toc-normal-2|<the-subsection><subsection-sep><arg|title>>>
</macro>>

<assign|appendix-subsubsection|<\macro|title>
<subsubsection|<arg|title>><with|toc-prefix|appendix-toc|<toc-normal-3|<the-subsubsection><subsubsection-sep><arg|title>>>
</macro>>

<assign|with-subtoc|<\macro|prefix|body>
<with|toc-prefix|<arg|prefix>|<arg|body>>
</macro>>

<assign|table-of-contents|<\macro|aux|body>
<render-table-of-contents|<if|<value|in-appendix>|<appendix-table-of-contents-text>|<table-of-contents-text>>|<arg|body>>
</macro>>

<assign|render-table-of-contents|<\macro|name|body>
<with|chapter-toc|<macro|name|>|section-toc|<macro|name|>|<section*|<arg|name>>>

<with|par-first|0fn|par-par-sep|0fn|<arg|body>>
</macro>>

</body>

<\initial>
<\collection>
<associate|preamble|true>
</collection>
</initial>
2 changes: 2 additions & 0 deletions TeXmacs/packages/section/section-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@

<assign|table-of-contents-text|<macro|<localize|Table of contents>>>

<assign|appendix-table-of-contents-text|<macro|<localize|Appendix table of contents>>>

<assign|index-text|<macro|<localize|Index>>>

<assign|glossary-text|<macro|<localize|Glossary>>>
Expand Down
4 changes: 4 additions & 0 deletions TeXmacs/plugins/lang/dic/en_US/zh_CN.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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" "作为")
Expand Down
9 changes: 9 additions & 0 deletions TeXmacs/progs/text/text-menu.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
81 changes: 81 additions & 0 deletions TeXmacs/tests/tmu/222_54.tmu
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<TMU|<tuple|1.1.0|2026.2.1-rc2>>

<style|<tuple|generic|chinese|table-captions-above|number-europe|preview-ref|appendix-toc>>

<\body>
<\hide-preamble>
<assign|chapter-numbered-title|<macro|title|<style-with|src-compact|none|<chapter-title|<ordinal-text> <the-chapter> <chapter-text><chapter-sep><vspace|1fn><arg|title>>>>>
</hide-preamble>

<\table-of-contents|toc>
<vspace*|1fn><with|font-series|bold|math-font-series|bold|第 1 章<space|2spc>chapter><datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.05fn>.<space|0.05fn>>>>>|<htab|5mm>><no-break><pageref|auto-1><vspace|0.5fn>

<with|par-left|1tab|1.1<space|2spc>section<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.05fn>.<space|0.05fn>>>>>|<htab|5mm>><no-break><pageref|auto-2>>

<with|par-left|2tab|1.1.1<space|2spc>subsection<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.05fn>.<space|0.05fn>>>>>|<htab|5mm>><no-break><pageref|auto-3>>

<vspace*|1fn><with|font-series|bold|math-font-series|bold|附录<space|2spc>appendix><datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.05fn>.<space|0.05fn>>>>>|<htab|5mm>><no-break><pageref|auto-4><vspace|0.5fn>
</table-of-contents>

<chapter|chapter>

<section|section>

<subsection|subsection>

\;

<appendix|appendix>

<\table-of-contents|appendix-toc>
<vspace*|1fn><with|font-series|bold|math-font-series|bold|A.1<space|2spc>section><datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.05fn>.<space|0.05fn>>>>>|<htab|5mm>><no-break><pageref|auto-5><vspace|0.5fn>

<with|par-left|1tab|A.1.1<space|2spc>subsecton<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.05fn>.<space|0.05fn>>>>>|<htab|5mm>><no-break><pageref|auto-6>>
</table-of-contents>

<\appendix-section>
section
</appendix-section>

<\appendix-subsection>
subsecton
</appendix-subsection>
</body>

<\initial>
<\collection>
<associate|page-medium|paper>
<associate|page-screen-margin|false>
<associate|sectional-short-style|<macro|false>>
</collection>
</initial>

<\references>
<\collection>
<associate|auto-1|<tuple|1|1>>
<associate|auto-2|<tuple|1.1|1>>
<associate|auto-3|<tuple|1.1.1|1>>
<associate|auto-4|<tuple|1.1.1|1>>
<associate|auto-5|<tuple|A.1|1>>
<associate|auto-6|<tuple|A.1.1|1>>
</collection>
</references>

<\auxiliary>
<\collection>
<\associate|appendix-toc>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|A.1<space|2spc>section><datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.05fn>.<space|0.05fn>>>>>|<htab|5mm>><no-break><pageref|auto-5><vspace|0.5fn>

<with|par-left|<quote|1tab>|A.1.1<space|2spc>subsecton<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.05fn>.<space|0.05fn>>>>>|<htab|5mm>><no-break><pageref|auto-6>>
</associate>
<\associate|toc>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|第 1 章<space|2spc>chapter><datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.05fn>.<space|0.05fn>>>>>|<htab|5mm>><no-break><pageref|auto-1><vspace|0.5fn>

<with|par-left|<quote|1tab>|1.1<space|2spc>section<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.05fn>.<space|0.05fn>>>>>|<htab|5mm>><no-break><pageref|auto-2>>

<with|par-left|<quote|2tab>|1.1.1<space|2spc>subsection<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.05fn>.<space|0.05fn>>>>>|<htab|5mm>><no-break><pageref|auto-3>>

<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|附录<space|2spc>appendix><datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.05fn>.<space|0.05fn>>>>>|<htab|5mm>><no-break><pageref|auto-4><vspace|0.5fn>
</associate>
</collection>
</auxiliary>
47 changes: 47 additions & 0 deletions devel/222_54.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# [222_54] 添加附录目录 (appendix-toc) 宏包

## 如何测试
- 涉及ts文件的需要先清理缓存
- 打开测试文件`TeXmacs/tests/tmu/222_54.tmu`
- 检查效果
- 新建文件
- 查看 `插入->自动`里是否有 附录目录
- 查看 `插入->章节`里是否有 附录节 附录子节 附录小节
- 点击工具栏 `增加宏包->custom->appendix-toc`,添加本宏包
- 重复查看上述部分
- 测试使用
- 结构如下
|- <appendix|>
|- <table-of-contents|appendix-toc|>
|- <appendix-section|>
|- <appendix-subsection|>
|- <appendix-subsubsection|>


## 2025/03/11 实现附录子目录宏包

### What
创建了 `appendix-toc.ts` 宏包,位于 `TeXmacs/packages/custom/`,提供以下功能:
- `<appendix-section|title>` - 附录内的 section,使用 "appendix-toc" 前缀
- `<appendix-subsection|title>` - 附录内的 subsection,使用 "appendix-toc" 前缀
- `<appendix-subsubsection|title>` - 附录内的 subsubsection,使用 "appendix-toc" 前缀
- `<with-subtoc|prefix|body>` - 通用宏,用于创建任意范围的子目录

### Why
- 原系统所有章节标题都写入同一个 `local_aux["toc"]`,无法实现范围限定的子目录
- 用户需要在附录范围内有一个独立的目录,只包含附录章节
- 通过切换 `toc-prefix` 参数,可以实现任意范围的子目录

### How
1. 利用现有的 `with-toc` 宏切换 `toc-prefix`:
```ts
<assign|with-toc|<macro|toc|body|<with|toc-prefix|<arg|toc>|<arg|body>>>>
```

2. 附录内的 section/subsection 同样使用 `with|toc-prefix|appendix-toc` 包装

3. 核心原理:
- `toc-entry` 宏使用 `<write|<value|toc-prefix>|...>` 写入 aux 数据
- 通过 `with|toc-prefix|<arg|prefix>` 临时改变前缀
- 不同前缀的数据存储在独立的 `local_aux` 键中
- `<table-of-contents|appendix-toc|...>` 只读取 "appendix-toc" 键的数据