11---
22tags : [bib]
3+ outline : [2, 3]
34---
45# 为什么指定参考文献 CSL 后,报错“failed to load CSL style”?
56
@@ -11,15 +12,53 @@ Typst [已经内置](https://typst.app/docs/reference/model/bibliography/#parame
1112
1213[ ^ present ] : 指 v0.14.0-rc.1 及之后的版本。
1314
14- 其实大部分非标准特性只影响特殊情况。可以先** 删除非标准特性** ,让 Typst 能读取样式生成参考文献;等真的遇到特殊情况了,再[ 专门解决] ( https://typst-doc-cn.github.io/clreq/#x7-bibliography ) 或[ 手动编辑] ( https://forum.typst.app/t/how-to-manually-correct-the-format-of-bibliography-for-60-styles/5303/2 ) 。此外,也可以尝试使用 [ Citext] ( https://github.com/Shuenhoy/citext ) 替代 Typst 原生的参考文献功能来获取 CSL-M 支持,请参考[ 如何修复英文参考文献中的“等”] ( ./bib-etal-lang.md ) 。
15+ 对此有两种解决思路:
16+
17+ - 其实大部分非标准特性只影响特殊情况。可以先** 删除非标准特性** ,让 Typst 能读取样式生成参考文献;等真的遇到特殊情况了,再[ 专门解决] ( https://typst-doc-cn.github.io/clreq/#x7-bibliography ) 或[ 手动编辑] ( https://forum.typst.app/t/how-to-manually-correct-the-format-of-bibliography-for-60-styles/5303/2 ) 。
18+
19+ - 使用 [ Citext] ( https://github.com/Shuenhoy/citext ) ** 替代 Typst 原生** 的参考文献引擎,支持非标准特性。
20+
21+ 这种方法可以根除问题,但会拖慢编译,而且有时需要调用特殊函数而不能单纯` @key ` 。详见[ 另一页面的专门小节] ( ./bib-etal-lang.md#citext ) 。
22+
23+ 下面具体介绍第一种方法。
24+
25+ ## 如何删除非标准特性
1526
1627::: tip
17- 对于 [ Zotero 中文社区的 CSL 样式] ( https://zotero-chinese.com/styles/ ) ,可直接前往[ 可用于 hayagriva 的 CSL 样式] ( https://typst-doc-cn.github.io/csl-sanitizer/ ) 下载批量修改好的版本。
28+ 对于 [ Zotero 中文社区的 CSL 样式] ( https://zotero-chinese.com/styles/ ) ,不必阅读后文, 可直接前往[ 可用于 Hayagriva 的 CSL 样式] ( https://typst-doc-cn.github.io/csl-sanitizer/ ) 下载批量修改好的版本。
1829:::
1930
20- 以下列出了常见报错以及解决方法,大致按常见程度降序排列。如果您遇到的错误不在其中,可尝试** 二分法** 依次删除各个` <macro> ` 来定位问题。
31+ 首先需** 定位问题** 。请将文件上传到 [ CSL 官方网站的 Validator] ( https://validator.citationstyles.org ) ,正常应出现下面这种结果。
32+
33+ > Oops, I found 8 errors.
34+ >
35+ > ** Errors**
36+ >
37+ > 1 . Line 42: Bad value ` citation-range-delimiter ` for attribute ` name ` on element ` term ` from namespace ` http://purl.org/net/xbiblio/csl ` .
38+ >
39+ > ``` xml
40+ > ms>
41+ > <term name =" citation-range-delimiter" >-</ter
42+ > ```
43+ >
44+ > 2. …
45+
46+ ::: details CSL Validator 提示 No errors found,但 Typst 仍然无法加载 CSL?
47+
48+ > CSL Validator: Good job! No errors found.
2149
22- ## duplicate field ` layout `
50+ CSL Validator 与 Typst/Hayagriva 毕竟原理不同,“CSL Validator 认为合法”与“Typst 认为合法”其实并无严格蕴含关系。
51+
52+ 遇到这种情况,可尝试用 Typst 持续编译文档,然后**二分法**依次删除各个`<macro >`来定位问题。
53+ :::
54+
55+ 接着结合 Typst 的报错,**逐一修改**各项错误。
56+
57+ 例如上例可能伴随 Typst 报错 data did not match any variant of untagged enum Term,与 CSL Validator 第一个错误写的 term 相关,那就找到 CSL 文件的第 42 行,删除或注释`citation-range-delimiter`这行。修改后,如果 Typst 仍然无法加载 CSL,就继续处理下一个错误,直到解决。
58+
59+ 以下列出了**常见报错以及解决方法**,大致按常见程度降序排列,可供参考。
60+
61+ ### duplicate field `layout`
2362
2463Typst 暂不支持 CSL-M 标准,可以注释掉多余的 `<layout >` 临时解决。
2564
@@ -44,7 +83,7 @@ Typst 暂不支持 CSL-M 标准,可以注释掉多余的 `<layout>` 临时解
4483
4584这样修改之后,CSL 根据文献语言自动使用“等”或“et al.”的功能会失效,请见[ 如何修复英文参考文献中的“等”] ( ./bib-etal-lang.md ) 。
4685
47- ## unknown variant ` institution ` , expected one of ` name ` , ` et-al ` , ` label ` , ` substitute `
86+ ### unknown variant ` institution ` , expected one of ` name ` , ` et-al ` , ` label ` , ` substitute `
4887
4988请在 CSL 文件里注释掉` <institution/> ` 。
5089
@@ -58,7 +97,7 @@ Typst 暂不支持 CSL-M 标准,可以注释掉多余的 `<layout>` 临时解
5897 </macro >
5998```
6099
61- ## data did not match any variant of untagged enum Term
100+ ### data did not match any variant of untagged enum Term
62101
63102该错误有多种可能原因。
64103
@@ -88,7 +127,7 @@ Typst 暂不支持 CSL-M 标准,可以注释掉多余的 `<layout>` 临时解
88127
89128此外,个别 CSL 文件错误地把` <term> ` 当成` <macro> ` 用。这种情况需要理解文件原本意图才能改正,建议直接向 CSL 维护者提出。
90129
91- ## data did not match any variant of untagged enum TextTarget/Variable
130+ ### data did not match any variant of untagged enum TextTarget/Variable
92131
93132请替换非标准的变量(variable),例如:
94133
@@ -117,9 +156,11 @@ Typst 暂不支持 CSL-M 标准,可以注释掉多余的 `<layout>` 临时解
117156 - ` original-issue `
118157 - ` original-jurisdiction `
119158
159+ - ` <if variable="CSTR"> ` 涉及[ 2025年新版国标] ( https://std.samr.gov.cn/gb/search/gbDetailed?id=4507EFE13D37CB6AE06397BE0A0A601F ) 引入的[ 科技资源标识 (CSTR)] ( https://std.samr.gov.cn/gb/search/gbDetailed?id=71F772D81092D3A7E05397BE0A0AB82A ) ,目前无法输入。可先在 CSL 删除整段` <if> ` ,然后在著录各篇文献时把` CSTR: … ` 作为文本夹带进相邻位置的字段。
160+
120161此外,个别 CSL 文件错误地把变量当成` <macro> ` 用。这种情况需要理解文件原本意图才能改正,建议直接向 CSL 维护者提出。
121162
122- ## missing field ` $value `
163+ ### missing field ` $value `
123164
124165CSL 标准规定` <else> ` 、` <group> ` 、` <layout> ` 等元素必须有内容。如果为空(或者只有注释),就会报告此错误。
125166
@@ -147,7 +188,7 @@ CSL 标准规定`<else>`、`<group>`、`<layout>`等元素必须有内容。如
147188 </citation>
148189```
149190
150- ## unknown variant ``, expected one of ` lowercase ` , ` uppercase ` , ` capitalize-first ` , ` capitalize-all ` , ` sentence ` , ` title `
191+ ### unknown variant ``, expected one of ` lowercase ` , ` uppercase ` , ` capitalize-first ` , ` capitalize-all ` , ` sentence ` , ` title `
151192
152193请删掉空的` text-case ` 属性。
153194
@@ -156,7 +197,7 @@ CSL 标准规定`<else>`、`<group>`、`<layout>`等元素必须有内容。如
156197+ <text variable="title"/>
157198```
158199
159- ## invalid locator
200+ ### invalid locator
160201
161202把` locator ` 属性改为标准规定的小写。
162203
0 commit comments