如何保留自定义编号同时移除附录引用中的冒号?
Typst附录标题引用冒号问题解决方法
问题背景
我当前使用的Typst代码如下:
#outline() This is the body of my text. There is something cool I show in @first, but you will have to read it to find out. #heading("Appendices", numbering: none) #set heading( offset: 1, numbering: (_, ..rest) => "Appendix " + numbering("A:", ..rest), supplement: [] ) = First <first> Text of the first appendix. = Second <second> Text of the second appendix.
这段配置能实现:用一级标题语法编写附录,但显示时为二级标题效果(目录中缩进,隶属于一级标题“Appendices”)。但存在问题:正文中引用附录时,编号后会带冒号,和常规numbering: "A:"的表现不符。需要在保留所有现有功能的前提下解决该问题。
解决方案
核心思路是将标题显示的冒号与引用的编号分离,通过supplement参数控制标题的冒号显示,让numbering只生成不带冒号的引用编号。修改后的代码如下:
#outline() This is the body of my text. There is something cool I show in @first, but you will have to read it to find out. #heading("Appendices", numbering: none) #set heading( offset: 1, numbering: (_, ..rest) => "Appendix " + numbering("A", ..rest), supplement: ":" ) = First <first> Text of the first appendix. = Second <second> Text of the second appendix.
逻辑说明
- 保留
offset:1和#heading("Appendices", numbering: none)的设置,确保附录在目录中仍以二级标题形式缩进,归属于“Appendices”下; - 调整
numbering函数,只生成不带冒号的“Appendix A”格式编号,这样正文中引用附录时(如@first)会显示不带冒号的正确格式; - 通过
supplement: ":"在标题的编号后添加冒号,保持原有标题“Appendix A: First”的显示效果。
内容的提问来源于stack exchange,提问作者DJDuque
相关产品推荐
相关产品推荐

