Skip to content

Commit 3a5aa37

Browse files
authored
通过 Python 将引注链接到参考文献表 (#357)
更新了"将引注链接到参考文献表"文档中的链接方法,添加了使用Python脚本添加超链接的介绍。
1 parent 382b60a commit 3a5aa37

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

user-guide/misc/link-citation-to-bibliography.md

+38-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ title: 在 Word 中把引注链接到参考文献表
1616

1717
Zotero 官方不提供该功能,这是因为 Zotero 使用的 CSL 处理器将 citation 渲染为一个 filed,无法添加超链接 [^1]
1818

19+
以下提供两种方法来实现为 citation 添加超链接的功能。
20+
21+
## Word 宏
22+
1923
从 Zotero 论坛发现了通过 Word 宏实现的功能 [^2],虽有一些缺陷,但基本可以达成需求。
2024

21-
## 配置及使用
25+
### 配置及使用
2226

2327
在 Word 里新建一个宏,添加宏代码如下:
2428

@@ -239,11 +243,41 @@ Public Sub ZoteroLinkCitation()
239243
End Function
240244
```
241245

246+
## Python 脚本
247+
248+
通过使用 Python 的 pywin32 库,可以在 Python 中实现与 Word 宏类似的功能。
249+
250+
### 使用前的注意事项
251+
252+
- 本 Python 代码仅对引用格式为 `(作者, 年份)` 的文档做过测试
253+
254+
### 配置及使用
255+
256+
1. 直接下载 [link-zotero-citation-bibliography](https://github.com/Syize/link-zotero-citation-bibliography) 仓库中的 [link-zotero-citation-bibliography.py](https://github.com/Syize/link-zotero-citation-bibliography/blob/master/link-zotero-citation-bibliography.py) 文件。
257+
2. 安装以下依赖库:
258+
- pywin32
259+
- rich
260+
261+
```bash
262+
pip install pywin32 rich
263+
```
264+
265+
3. 修改代码中的以下设置:
266+
- `word_file_path`:您的 Word 文档的绝对路径。
267+
- `new_file_path`:新保存的 Word 文档的绝对路径。
268+
4. (可选) 修改函数 `create_hyperlinks_to_literature_bookmarks` 参数值:
269+
- `setColor`:为 citation 设置的字体颜色,默认为蓝色。你可以通过查阅 VBA 的手册获取相应颜色的值[^3]
270+
- `etal_number`:使用 `et al.``` 代替作者名字时的作者数。
271+
5. 运行代码。
272+
242273
## 缺陷和注意事项
243274

244-
- 手动更新引注时会出现引注已被修改的弹窗
245-
- 无法实现从参考文献表跳转到引注
246-
- 同时引用多个引注时只能链接最后一个。
275+
- 手动更新引注时会出现引注已被修改的弹窗。
276+
- 无法实现从参考文献表跳转到引注。
277+
- 使用 Word 宏方法时,同时引用多个引注时只能链接最后一个。
278+
- Python 脚本未对顺序引注测试过。
279+
- 当你选择 Unlink Citations 时,添加的所有超链接会失效。
247280

248281
[^1]: 来源添加
249282
[^2]: [Word: Possibility to link references and bibliography in a document? -  Zotero Forums](https://forums.zotero.org/discussion/comment/324312/#Comment_324312)
283+
[^3]: [VBA 文档](https://learn.microsoft.com/zh-cn/office/vba/api/word.wdcolor)

0 commit comments

Comments
 (0)