1
0

feat: fix pandoc-tex-numbering style error by patch

This commit is contained in:
2026-06-13 19:45:37 +08:00
parent c1fbde559d
commit e956691614
3 changed files with 44 additions and 1 deletions

View File

@@ -42,6 +42,36 @@ uv run pandoc <thesis.tex> \
- `--reference-doc=my-thesis.docx`设置了转换到DOCX格式时使用的模板。你也可以把`my-thesis.docx`换成你想要的模板,至于如何编辑属于你的模板,请参考后文。
- `-o <thesis.docx>`:在执行的时候将`<thesis.docx>`替换为指向你存储转换后的DOCX文档的路径。
# 过滤器补丁
本项目采用了名为`pandoc-tex-numbering`的过滤器这是一个很棒的项目但它在图标标题的事情上没有任何方法可以做到我期望的样子因此我不得不使用一种比较“脏”的手段来使其达到我想要的效果。我采用Git Diff的方式给下载下来的`pandoc-tex-numbering`包的源码打补丁,使其符合我的需求。下面将介绍如何打补丁。
## 应用补丁
> [!WARNING]
> 应用补丁前,请确保已经使用`uv sync`指令配置好虚拟环境,否则以下指令无效。
在该目录下执行以下命令以应用补丁:
```sh
git apply --directory pandoc/.venv/Lib/site-packages/pandoc_tex_numbering numbering-caption-delimiter.diff
```
其中`--directory`选项用于在`diff`文件的路径前附加指定路径使其成为一个完整的相对于git根目录的路径。
## 撤销补丁
> [!WARNING]
> 如果不执行撤销补丁的指令由于Astral UV的硬链接原因所有使用该版本`pandoc-tex-numbering`包的项目都会受到该补丁影响。因此我强烈建议在使用完本环境后将补丁撤销。
当你使用完本环境后,执行以下命令以撤销补丁:
```sh
git apply -R --directory pandoc/.venv/Lib/site-packages/pandoc_tex_numbering numbering-caption-delimiter.diff
```
其中`-R`选项表示反向应用补丁。
# DOCX模板
该目录下的`my-thesis.docx`文件是我已经编辑好的模板。该模板可以满足我的大部分的需求,输出也足够的美观。

View File

@@ -5,7 +5,7 @@ link-bibliography: false # 文献中的链接不要引出
# 杂项设置
number-theorems: false
numbering-caption-delimiter: " - "
# numbering-caption-delimiter: " "
prefix-space: true
section-max-levels: 3
number-reset-level: 0 # 编号不需要按章节重置因此设置为0表示在最顶层的层级的父级才重置编号即不重置编号

View File

@@ -0,0 +1,13 @@
diff --git a/pandoc_tex_numbering.py b/pandoc_tex_numbering.py
index 35e2656..d1e941b 100644
--- a/pandoc_tex_numbering.py
+++ b/pandoc_tex_numbering.py
@@ -399,7 +399,7 @@ def add_label_to_caption(num_obj, label: str, elem):
has_caption = False
if has_caption:
# If there's no caption text, we shouldnot add a colon
- label_items.extend([Str(":"), Space()])
+ label_items.extend([Space(), ])
for item in label_items[::-1]:
elem.caption.content[0].content.insert(0, item)