Skip to content

Commit 2c07122

Browse files
Merge pull request #67 from YDX-2147483647/cron
2 parents 265ed8f + e568961 commit 2c07122

File tree

4 files changed

+118
-27
lines changed

4 files changed

+118
-27
lines changed

README.en.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ A simple typst example.
149149

150150
🙈 hidden from the source, but still 🚀 executed in preview.
151151

152-
- Lines starting with `<<<`:
152+
- Lines starting with `<<< `:
153153

154154
👀 shown as the source, but 🛑 not executed in the preview.
155155

@@ -171,6 +171,8 @@ As a result:
171171

172172
For example, the default `text.cjk-latin-spacing` is typically `auto`, but here it is `none`.
173173

174+
- The styles for headings etc. are affected by the global style of the document.
175+
174176
-
175177

176178
If you require advanced features or 100% accuracy, please write a page example instead.
@@ -196,7 +198,7 @@ A standalone typst example compiled in a page.
196198
````
197199
`````
198200

199-
The meanings of `<<<` and `>>>` are the same as those in simple examples.
201+
The meanings of `<<< ` and `>>>` are the same as those in simple examples.
200202

201203
#### Bibliography examples (`example-bib`)
202204

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pnpm dev --open # ⇒ http://localhost:3000
148148

149149
🙈 在源代码中隐藏,但仍然 🚀 执行成预览结果。
150150

151-
- `<<<`打头的行:
151+
- `<<< `打头的行:
152152

153153
👀 显示到源代码,但 🛑 不会执行成预览结果。
154154

@@ -170,6 +170,8 @@ simple example 执行于容器中,且会在整篇文档中共享状态。
170170

171171
例如,`text.cjk-latin-spacing`一般默认为`auto`,但这里是`none`
172172

173+
- 标题等样式会受文档全局样式影响。
174+
173175
- ……
174176

175177
如需高级功能或 100% 准确,请换用 page example。
@@ -195,7 +197,7 @@ simple example 执行于容器中,且会在整篇文档中共享状态。
195197
````
196198
`````
197199

198-
`<<<``>>>`的意义与 simple example 相同。
200+
`<<< ``>>>`的意义与 simple example 相同。
199201

200202
#### Bibliography examples (`example-bib`)
201203

main.typ

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585

8686
#level.advanced
8787
#issue("typst#5908")
88+
#pull("typst#7399", rejected: true)
8889

8990
// Ref: https://www.w3.org/TR/clreq/#writing_modes_in_chinese_composition
9091
#babel(en: [There are two writing modes in Chinese composition:], zh: [中文有两种行文模式:])
@@ -314,6 +315,47 @@ $ f(x) = y "(定义8)" $
314315
// This example would emit a warning: variable fonts are not currently supported and may render incorrectly.
315316
// To avoid receiving the message repeatedly when running `pnpm dev`, we use `example-page` instead of `example`.
316317

318+
=== #bbl(
319+
en: [Unable to infer the writing script across elements, making `locl` sometimes ineffective],
320+
zh: [无法跨越元素推断文字种类,导致`locl`特性有时失效],
321+
)
322+
323+
#level.basic
324+
#issue("typst#7396")
325+
326+
#babel(
327+
en: [
328+
Typographical rules may have regional differences. For example, when writing Chinese horizontally, #unichar("") is placed at the _lower left_ corner in the square space in Chinese Mainland, but placed at the _center_ in Taiwan and Hong Kong.
329+
Some fonts handle these differences with the #link("https://learn.microsoft.com/typography/opentype/spec/features_ko#tag-locl")[OpenType `locl` (Localized Forms) feature], which requires the text to be properly tagged with both the language system and the writing script.
330+
However, typst does not infer the script across elements, making `locl` sometimes ineffective.
331+
],
332+
zh: [
333+
排版规则可能存在地区差异。例如横排中文时,中国大陆把 #unichar("") 放在字面的左下角,而港台则放在中央。有些字体使用 #link("https://learn.microsoft.com/typography/opentype/spec/features_ko#tag-locl")[OpenType 特性`locl` (Localized Forms)] 处理这种差异,而这要求文本同时正确标注了语言和文字。然而,typst 不会跨元素推断文字种类,导致`locl`特性有时失效。
334+
],
335+
)
336+
337+
#babel(
338+
en: [
339+
In the example below, typst infers the script of the first `。` from its surrounding Han texts, and uses the correct localized glyph. However, typst fails to do so for the second `。`, whose both sides are `ref` elements, and uses the wrong default glyph.
340+
],
341+
zh: [
342+
在下例中,typst 从相邻汉字推断出了第一个`。`的文字种类,选用了正确的本地化字形;可是未能应对夹在两个`ref`元素中间的第二个`。`,选用了错误的默认字形。
343+
],
344+
)
345+
346+
```example-page
347+
#set text(lang: "zh", region: "TW", font: "Noto Serif CJK SC")
348+
#set heading(numbering: "1")
349+
<<< #hide[= 何故 <a>]
350+
>>> #place(hide[= 何故 <a>])
351+
352+
>>> Current: \
353+
句號。@a。@a
354+
355+
>>> Expected: \
356+
>>> 句號。小節 1。小節 1
357+
```
358+
317359
== Context-based shaping and positioning
318360

319361
#prompt(from-w3c: "https://www.w3.org/TR/clreq-gap/#glyphs")[
@@ -679,7 +721,7 @@ $ f(x) = y "(定义8)" $
679721

680722
#babel(
681723
en: [According to #link("https://www.w3.org/TR/clreq/#prohibition_rules_for_line_start_end")[prohibition rules for line start and line end] (basic), #unichar("·") should not appear at the line start.],
682-
zh: [按照#link("https://www.w3.org/TR/clreq/#prohibition_rules_for_line_start_end")[行首行尾禁则](基本处理),#unichar("·")不能出现在一行的开头。],
724+
zh: [按照#link("https://www.w3.org/TR/clreq/#prohibition_rules_for_line_start_end")[行首行尾禁则](基本处理),#unichar("·") 不能出现在一行的开头。],
683725
)
684726

685727
```example
@@ -892,10 +934,10 @@ $ f(x) = y "(定义8)" $
892934
第二天我起得非常迟,午饭之后,出去看了朋友。
893935
894936
// Expected to be possible:
895-
<<<#set text(overhang: ("、": 1.0, ",": 1.0, "。": 1.0))
937+
<<< #set text(overhang: ("、": 1.0, ",": 1.0, "。": 1.0))
896938
>>> = Expected
897939
>>> #set par(justify: false)
898-
<<<第二天我起得非常迟,午饭之后,出去看了朋友。
940+
<<< 第二天我起得非常迟,午饭之后,出去看了朋友。
899941
>>> 第二天我起得非常迟,午饭之后,#h(-1em)出去看了朋友。
900942
```
901943

@@ -1130,8 +1172,8 @@ $ integral f dif x $
11301172
>>> #set box(fill: aqua.lighten(50%))
11311173
>>> Current: \
11321174
>>> // Default: cap-height to baseline.
1133-
<<<Typst 国王 \
1134-
<<<Typst 国王
1175+
<<< Typst 国王 \
1176+
<<< Typst 国王
11351177
>>> #box[Typst 国王] \
11361178
>>> #box[Typst 国王]
11371179
@@ -1785,6 +1827,7 @@ $ integral f dif x $
17851827
=== #bbl(en: [Failed to load some CSL styles], zh: [无法加载某些 CSL 样式])
17861828

17871829
#level.advanced
1830+
#issue("citationberg#35", closed: true)
17881831
#issue("hayagriva#405")
17891832
#workaround("https://typst-doc-cn.github.io/guide/FAQ/bib-csl.html")
17901833
#workaround("https://typst-doc-cn.github.io/csl-sanitizer/", note: "csl-sanitizer")
@@ -1984,6 +2027,15 @@ $ integral f dif x $
19842027

19852028
= #bbl(en: [Addendum], zh: [附录])
19862029

2030+
== #bbl(en: [List of sites], zh: [站点列表])
2031+
2032+
- #bbl(en: [Main site], zh: [主站]) \
2033+
#link("https://typst-doc-cn.github.io/clreq/")[typst-doc-cn.github.io/clreq]
2034+
- #bbl(en: [Mirror site], zh: [镜像站]) \
2035+
#link("https://gap.zhtyp.art")[gap.zhtyp.art]
2036+
- #bbl(en: [Test site], zh: [测试站]) \
2037+
#link("https://clreq-gap-typst.netlify.app")[clreq-gap-typst.netlify.app]
2038+
19872039
== #bbl(en: [Environment of the examples], zh: [例子的环境信息])
19882040

19892041
- #bbl(en: [Update date], zh: [更新日期]) \

typ/show-example.typ

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#import "@preview/tidy:0.4.3": show-example as tidy-example
21
#import "@preview/digestify:0.1.0": bytes-to-hex, md5
32

43
#import "templates/html-toolkit.typ": div-frame
@@ -69,6 +68,42 @@
6968
/// -> any
7069
body,
7170
) = {
71+
/// - raw (str): The source of a simple or page example.
72+
/// -> dictionary `(displayed, executed)`
73+
let parse-example(raw) = {
74+
let lines = raw
75+
.split("\n")
76+
.map(x => if x.starts-with(">>>") {
77+
(
78+
displayed: none,
79+
executed: x.trim(">>>", at: start),
80+
)
81+
} else if x.starts-with("<<<") {
82+
(
83+
displayed: if x == "<<<" {
84+
"" // Support displaying an empty line
85+
} else {
86+
// The space after `<<<` is intentional. It is consistent with the official, but different with tidy.
87+
assert(
88+
x.starts-with("<<< "),
89+
message: "this line in the example is ambiguous; consider adding a space after `<<<`:\n" + x,
90+
)
91+
x.trim("<<< ", at: start)
92+
},
93+
executed: none,
94+
)
95+
} else {
96+
// Regular lines
97+
(displayed: x, executed: x)
98+
})
99+
100+
101+
let displayed = lines.map(x => x.displayed).filter(x => x != none).join("\n")
102+
let executed = lines.map(x => x.executed).filter(x => x != none).join("\n")
103+
104+
(displayed: displayed, executed: executed)
105+
}
106+
72107
let fix-scaling(it) = {
73108
// This reverts the default style for `raw`, making the result of `#context 1em.to-absolute()` in simple examples consistent with that in regular documents.
74109
//
@@ -86,29 +121,29 @@
86121

87122
// Simple example, directly evaluated in main.typ.
88123
show raw.where(lang: "example"): it => {
89-
show: fix-scaling
124+
let (displayed, executed) = parse-example(it.text)
125+
126+
let full-executed = ````typ
127+
// Some browsers hide the border. Therefore, the inset is necessary.
128+
#show: block.with(inset: 0.5em)
129+
{GENERAL-PREAMBLE}
90130
91-
tidy-example.show-example(
92-
raw(it.text, block: true, lang: "typ"),
93-
mode: "markup",
94-
preamble: ```typ
95-
// Some browsers hide the border. Therefore, the inset is necessary.
96-
#show: block.with(inset: 0.5em)
97-
{GENERAL-PREAMBLE}
98-
```
99-
.text
100-
.replace("{GENERAL-PREAMBLE}", GENERAL-PREAMBLE)
101-
+ "\n",
102-
layout: layout-example,
131+
{executed}
132+
````
133+
.text
134+
.replace("{GENERAL-PREAMBLE}", GENERAL-PREAMBLE)
135+
.replace("{executed}", executed)
136+
137+
show: fix-scaling
138+
layout-example(
139+
optional-map(raw.with(block: true, lang: "typ"), displayed),
140+
[#eval(full-executed, mode: "markup")],
103141
)
104142
}
105143

106144
// Page example, compiled by scripts/compile.ts.
107145
show raw.where(lang: "example-page"): it => {
108-
let lines = it.text.split("\n")
109-
110-
let displayed = lines.filter(x => not x.starts-with(">>>")).map(x => x.trim("<<<", at: start)).join("\n")
111-
let executed = lines.filter(x => not x.starts-with("<<<")).map(x => x.trim(">>>", at: start)).join("\n")
146+
let (displayed, executed) = parse-example(it.text)
112147

113148
let full-executed = ````typ
114149
// Some browsers hide the border. Therefore, the margin is necessary.

0 commit comments

Comments
 (0)