-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CH4typ:0.0.1 #1572
Open
tryptophawa
wants to merge
18
commits into
typst:main
Choose a base branch
from
tryptophawa:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
CH4typ:0.0.1 #1572
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c2c8765
Add files via upload
tryptophawa da961b2
Delete packages/preview/chem-reaction/0.1.0 directory
tryptophawa d2d49f1
Create readme.md
tryptophawa 168bcfb
Add files via upload
tryptophawa 0542747
Update typst.toml
tryptophawa 4ba41c0
Update typst.toml
tryptophawa 2f59c43
Update lib.typ
tryptophawa 39e1dbd
Update typst.toml
tryptophawa 180ff3f
Update readme.md
tryptophawa fb370e5
Create LICENCE
tryptophawa 9392a5f
Rename LICENCE to LICENSE
tryptophawa fdb8473
Update readme.md
tryptophawa b9a1836
Update readme.md
tryptophawa 46f1899
Update readme.md
tryptophawa aa713fc
Update typst.toml
tryptophawa 53f0294
Update typst.toml
tryptophawa 991c9e4
Rename packages/preview/CH4typ/0.0.1/readme.md to packages/preview/CH…
tryptophawa 71abf47
Rename packages/preview/CH4typ/README.md to packages/preview/CH4typ/0…
tryptophawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2025 β-吲哚基丙氨酸 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Typst Chemical Formula Package | ||
|
||
A Typst package (alpha) for typesetting chemical formulas, supporting both inorganic and organic chemistry notation. | ||
|
||
## Features | ||
|
||
- Basic chemical formula typesetting | ||
- Ion charge notation | ||
- Physical state markers | ||
- Organic chemistry structures | ||
- Reaction arrows and equilibrium symbols | ||
- Special support for phenyl group (Ph) | ||
- Support for C(n) general formula expressions | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/// Chemical formula typesetting package | ||
/// Version: 0.0.1 | ||
|
||
// 修改预编译的正则表达式模式 | ||
#let rx = regex("([A-Z][a-z]?)(?:\\(([A-Z][A-Za-z]+|[0-9]*n(?:[+-][0-9]+)*)\\))?([0-9]+)?(?:\\^\\(([0-9+-]+)\\))?(?:\\(([a-z]+)\\))?") | ||
|
||
// 新增有机化学正则表达式 | ||
#let organic = ( | ||
// 基本结构 - 改进对Cn模式的支持 | ||
basic: regex("([A-Z][a-z]?)(?:\\(([A-Z][A-Za-z]+|[0-9]*n(?:[+-][0-9]+)*)\\))?([0-9]+|n)?(?:[A-Z][0-9]+)*"), | ||
// 双键和三键 | ||
bonds: regex("(=|≡)"), | ||
// 有机基团 (如 -CH3, -OH, -COOH 等) | ||
groups: regex("\\-([A-Z][A-Za-z0-9]+)"), | ||
// 取代基位置 | ||
position: regex("([0-9]+)\\-"), | ||
// 苯环缩写 | ||
phenyl: regex("Ph"), | ||
) | ||
|
||
// 预定义连接符样式 | ||
#let bond-styles = ( | ||
single: $minus$, // 单键 | ||
double: $=$, // 双键 | ||
triple: $≡$, // 三键 | ||
) | ||
|
||
/// 格式化化学式 | ||
#let format(content) = { | ||
// 基础替换规则 | ||
show "react": $arrow$ | ||
show "equilibrium": math.arrow.l.r | ||
show "Delta": sym.Delta | ||
show "+": $+$ | ||
show "-": bond-styles.single | ||
show "=": bond-styles.double | ||
show "≡": bond-styles.triple | ||
show "Ph": "⌬" | ||
|
||
// 有机化学特殊处理 | ||
show organic.groups: it => { | ||
let group = it.text.slice(1) | ||
h(0.15em) + $minus$ + h(0.1em) + $upright(#group)$ // 优化基团连接 | ||
} | ||
|
||
show organic.position: it => { | ||
let pos = it.text.slice(0,-1) | ||
$upright(#pos)$ + h(0.1em) + $minus$ + h(0.15em) // 优化位置标记连接 | ||
} | ||
|
||
// 修改统一的匹配与处理部分 | ||
show rx: it => { | ||
let groups = it.text.match(rx) | ||
if groups == none { return it } | ||
|
||
let (base, group, num, charge, state) = groups.captures.slice(0) | ||
|
||
let result = $upright(#base)$ | ||
if group != none { | ||
// 处理括号中的表达式 | ||
if group.contains("n") { | ||
// 改进对数学表达式的处理 | ||
let expr = group | ||
.replace("n+", "n plus ") // 临时替换以避免与化学加号冲突 | ||
.replace("n-", "n minus ") | ||
expr = $#expr.replace("plus", "+").replace("minus", "-")$ | ||
result = $#result _(#expr)$ | ||
} else { | ||
result = $#result thin (#group)$ | ||
} | ||
} | ||
if num != none { | ||
// 特殊处理n的情况 | ||
if num == "n" { | ||
result = $#result_n$ | ||
} else { | ||
result = $#result _#num$ | ||
} | ||
} | ||
if charge != none { | ||
show "+": math.plus | ||
show "-": math.minus | ||
result = $#result^#charge$ | ||
} | ||
if state != none { | ||
// 修改状态标记显示方式 | ||
let pure_state = state.trim("()") | ||
result = $#result _(#pure_state)$ // 使用双括号确保正确显示 | ||
} | ||
|
||
result | ||
} | ||
|
||
$upright(#content)$ | ||
} | ||
|
||
// 导出接口 | ||
#let chemical = format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,7 @@ | ||||||
[package] | ||||||
name = "CH4typ" | ||||||
version = "0.0.1" | ||||||
license = "MIT" | ||||||
entrypoint = "lib.typ" | ||||||
authors = ["β-吲哚基丙氨酸"] | ||||||
description = "an alternative for chem-par packet" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion the description you wrote in your README is clearer to explain the purpose of the package, I would suggest copying it here.
Suggested change
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to to use lower-kebab-case for your package name. The current name would become
ch-4-typ
, but (if I remember my chemistry class correctly) that would ruin the joke in the name. Maybe you can change the name entirely if you are not satisfied with that.