Skip to content

Commit

Permalink
docs: update syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ForkKILLET committed Jan 19, 2023
1 parent 57fa950 commit a783e5e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
39 changes: 27 additions & 12 deletions docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ English | [简体中文](./syntax.zh-Hans.md)

A *Chemical Structure* starts with a *Group*. A *Group* can:

- Include uppercase and lowercase characters, lowercase characters following uppercase characters will be merged into one font box (to make element notation more natural)
- Include uppercase and lowercase characters, lowercase characters following uppercase characters will be merged into one text box (to make element notation more natural)
- Include digits, digits will be rendered as subscript
- Be an isolated *Wildcard `?`*, and will not be rendered (to express a substituent)
- Be an isolated *Collapsed Carbon Atom `.`*, and will not be rendered, connected bonds will be rendered without gaps
- Start with a *Collapsing Flag `.`* to make the text box collapse. Connected *Bonds* will be rendered without gaps when there's nothing after `.` (like bond-line formulas)

A *Group* can include *In-group Typesetting*:

Expand Down Expand Up @@ -54,17 +54,26 @@ Rules of expressing a *Bond*:
*Bond Directions* have a similar expressing method to writing chemical structure:

- Using `-`, `|`, `/` and `\` to represent a *Bond* of 0°, 90°, 60° and 270° respectively
- Using `@` followed by a number to represent a *Bond* of specific degree. The degree can be positive or negative, integer or decima. At end it will be converted to a value between 0° and 360°
- *Bond Directions* can be `+`, see [Overlapping](#bond-overlapping) for details
- If *Bond Type* appears before the *Chemical Structure* it connected, the direction will follow the rules stated above; if *Bond Type* appears after the *Chemical Structure* it connected, the direction will be the opposite (i.e. adding a deflection of 180°)
- If *Bond Type* appears after the *Chemical Structure* it connected, the *Bond* can only appear in a *Bonds Set*
- *Bond Direction* must not be duplicated (bonds in), and must be unique from the direction of the *Bond* that it is connected from the *Group* it belongs to
- *Bond Direction* (of *Bonds out*) must not be duplicated, and must be unique from the direction of the *Bond* that it is connected from the *Group* it belongs to (i.e. *Bond in*)

*Bond Modifier*:

- *Bond Modifier `*`* sets the length (`length` *Attribute*) of the *Bond* to 0
- *Bond Modifier `*`* sets the length (*Attribute `length`*) of the *Bond* to 0
- *Bond Modifier `!`* can make all the following *Bond Directions* add a deflection of 180° (to express opposite *Bonds* outsides the *Bonds Set*)
- *Bond Modifier `~`* acts on all *Bond Directions* of `/` and `\` in the following *Bond Directions*. It can make their angle with x-axis change from 60° to 30°

Shorthand rules for *Bond Modifier `~`*:
- When `~` is not followed by *Bond Direction*, the direction will be automatically infered based on the direction of *Bond in*
- 若没有入键,方向推导为 `~/`;若同时存在「键修饰符 `!`」,方向推导为 `!~\`
- When there is no *Bond in*, the direction will be inferred to `~/`; when *Bond Modifier `!`* also exists, the direction will be inferred to `!~\`
- When there is a *Bond in*, `~/` and `~\` will be inferred to each other; when *Bond Modifier `!`* also exists, `!~\` and `!~/` will be inferred to each other
- When there is a *Bond in* but its direction is not among the above four directions, an inferring error will occur
- This shorthand rule is designed for expressing carbon chains in bond-line formulas

Shorthand rules for *Bond Directions*:

- If *Bond Count* exists, omitting *Bond Direction* is allowed, in this case, *Bond Direction* will be 0° by default
Expand All @@ -79,11 +88,16 @@ Overlapping more than one *Bond Direction* is allowed to express connecting to t
- If a *Bond Direction* and the first *Bond Direction* are symmetrical about the x-axis/y-axis, all the *Bonds* in the *Chemical Structure* connected to the former will be flipped by the x-axis/y-axis (however, the texts in the *Groups* in it will not be rotated)
- All *Bonds* in *Chemical Structure* connected by other *Bond Direction* will be rotated by the same angle as the angle between their *Bond Direction* and the first *Bond Direction*

Overlapping `@` (experimental)
- `@!` means an extra direction with the opposite direction
- `@-` means an extra direction with the x-flipped direction
- `@|` means an extra direction with the y-flipped direction

## Referencing

*Referencing* can be used to separate complicated *Chemical Structures* into parts to express

- A *Chemical Structure* can be named by using *Attribute* `ref`, a named *Chemical Structure* is referenceable
- A *Chemical Structure* can be named by using *Attribute `ref`*, a named *Chemical Structure* is referenceable
- A sign `&` followed by a referenced name is a *Referencing*, as well as a *Group*, it can be followed by *Bonds*
- Using `;` to separate different *Chemical Structures*. (Dangling `;` is allowed) Ultimately, these *Chemical Structures* must be fully connected by *Referencing*
- A *Referencing* cannot be connected to itself by a *Bond* (i.e., self-loops are not allowed)
Expand All @@ -100,13 +114,14 @@ Overlapping more than one *Bond Direction* is allowed to express connecting to t

*Bond* Attributes:

| Attribute Name | Alias | Type | Usage
| :------------- | :-------- | :---------------- | :----
| `color` | `C` | String | To specify the bond's color
| `highEnergy` | `HE`, `~` | Boolean | To describe a high-energy bond
| `from` | `<` | Boolean / Integer | Coordinate bond came from along the bond, an integer can specify the number of arrows
| `to` | `>` | Boolean / Integer | Coordinate bond came to along the bond, an integer can specify the number of arrows
| `length` | `L` | Float | To specify the bond's length (multiple of unit length, 1 by default)
| Attribute Name | Alias | Type | Usage
| :------------- | :-------- | :----------------- | :----
| `color` | `C` | String | To specify the bond's color
| `highEnergy` | `HE`, `~` | Boolean | To describe a high-energy bond
| `from` | `<` | Boolean / Integer | Coordinate bond came from along the bond, an integer can specify the number of arrows
| `to` | `>` | Boolean / Integer | Coordinate bond came to along the bond, an integer can specify the number of arrows
| `length` | `L` | Float | To specify the bond's length (multiple of unit length, 1 by default)
| `side` | `S` | Constant `L` / `R` | To specify the bond's inside. `L` means left and `R` means right. This determines which side the second bond of a double-bond appears

## Form

Expand Down
16 changes: 8 additions & 8 deletions docs/syntax.zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- 包含大小写字母,大写字母后的小写字母会与之合并在一个字框内(使元素符号更自然)
- 包含数字,数字会被渲染为下标形式
- 是一个单独的「通配符 `?`」,不渲染(用于表示取代基)
- 是一个单独的「塌缩碳原子 `.`,不渲染,与之相连的键不会留白(类似键线式)
- 以「塌缩标志 `.`开头,这会使字框塌缩。`.` 后无内容时,相连的「键」会无缝衔接(类似键线式)

「原子团」可以包含「原子团内排版」:
-`^`/`_`/`` ` `` 表示上标/下标/正常显示其后的一个字符
Expand Down Expand Up @@ -51,18 +51,18 @@
- 「键方向」可以为 `+`,见[重迭书写规则](#键的重迭书写)
- 当「键类型」写在连接的「化学结构」前时,方向即如上条所说;写在其后时,则反向(加上 180°)
- 「键类型」写在连接的「化学结构」后时,只能出现在「键组」内
- 键方向」不得重复(出键);也不得与连接其所属的「原子团」的「键」的方向(入键)相反
- (「出键」的)「键方向」不得重复;也不得与连接其所属的「原子团」的「键」(即「入键」)的方向相反

「键修饰符」:
- 「键修饰符 `*`」将「键」的长度(`length` 「属性」))设置为 0
- 「键修饰符 `*`」将「键」的长度(「属性 `length`」))设置为 0
- 「键修饰符 `!`」使其后的「键方向」都增加 180°(这样可以在「键组」外书写反方向的键)
- 「键修饰符 `~`」使其后的「键方向」中,为 `/``\` 的,与 x 轴夹角从 60° 变为 30°

「键修饰符 `~`」的简写规则:
-`~` 后不跟随「键方向」时,会根据其所属「原子团」的入键方向自动推导方向
- 若没有入键,方向推导为 `~/`;若同时存在「键修饰符 `!`」,方向推导为 `!~\`
- 若有入键,则按照 `~/` 对应 `~\` 推导;若同时存在「键修饰符 `!`」,则按照 `!~\` 对应 `!~/` 推导
- 若有入键且其方向不在上述 4 个方向中,则产生推导错误
-`~` 后不跟随「键方向」时,会根据「入键」方向自动推导方向
- 若没有「入键」,方向推导为 `~/`;若同时存在「键修饰符 `!`」,方向推导为 `!~\`
- 若有「入键」,则按照 `~/` 对应 `~\` 推导;若同时存在「键修饰符 `!`」,则按照 `!~\` 对应 `!~/` 推导
- 若有「入键」且其方向不在上述 4 个方向中,则产生推导错误
- 这一简写规则是为键线式中书写碳链设计的

「键方向」的简写规则:
Expand All @@ -86,7 +86,7 @@

「引用」可以用于将复杂的「化学结构」拆分开来表示

-`ref` 「属性」给某个「化学结构」命名,从而可被引用
-「属性 `ref`」给某个「化学结构」命名,从而可被引用
- 把引用名称写在 `&` 符号后面,就构成一个「引用」,其可以像「原子团」一样跟随「键」
-`;` 隔开不同的「化学结构」。(允许悬挂的 `;`)最终,通过「引用」的连接,这些「化学结构」必须完全连通
- 「引用」不能通过「键」连接到它本身(即不允许出现自环)
Expand Down

0 comments on commit a783e5e

Please sign in to comment.