Created
March 23, 2024 03:07
-
-
Save zr-tex8r/76d71590cbf8fa9488213c6611314771 to your computer and use it in GitHub Desktop.
Typst: To get the version of Typst in use
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
// Typst version as int array, such as (0, 11, 0). | |
#let version = { | |
// >=0.9.0 : gets exact version | |
// <0.9.0 : error (sys.version is undefined) | |
let sys-version() = { | |
array(sys.version) | |
} | |
// checks whether chr is a valid counting symbol | |
let check-by-numbering(chr) = { | |
"B" not in str(numbering(chr + "A", 2, 1)) | |
} | |
// 0.9.0, 0.10.0 : true (str(-1) == "\u{2212}1") | |
// <0.9.0 : false (str(-1) == "-1") | |
let check-v9() = { | |
"\u{2212}" in str(-1) | |
} | |
// >=0.8.0 : true (type != str) | |
// <0.8.0 : false ("string" == "string") | |
let check-v8() = { | |
type(type(1)) != type("1") | |
} | |
// 0.7.0 : true | |
// ("11. B" stays in inner list, so len() == 2) | |
// 0.5.0, 0.6.0 : false | |
// ("11. B" stays in outer list, so len() == 4) | |
let check-v7() = { | |
let it = [ | |
1. A | |
1. A | |
11. B] | |
it.children.len() < 4 | |
} | |
// 0.6.0, 0.7.0 : true | |
// ("1/2!" is parsed as 1/(2!), so the entity is a frac) | |
// 0.5.0 : false | |
// ("1/2!" is parsed as (1/2)!) | |
let check-v6() = { | |
($1/2!$).body.func() == math.frac | |
} | |
// 0.4.0 : true (math.ast is U+2217) | |
// 0.2.0, 0.3.0 : false (math.ast is U+002A) | |
let check-v4() = { | |
str(math.ast.op) == str(math.ast) | |
} | |
// 0.3.0, 0.4.0 : true (math.dot is U+22C5) | |
// 0.2.0 : false (math.dot is U+002E) | |
let check-v3() = { | |
str(math.dot.op) == str(math.dot) | |
} | |
// sequence for version detection | |
if check-v8() { | |
let v11 = check-by-numbering("\u{3042}") | |
if v11 or check-v9() { | |
sys-version() | |
} else { | |
(0, 8, 0) | |
} | |
} else { | |
let v1 = check-by-numbering("\u{5D0}") | |
let v2 = check-by-numbering("\u{3044}") | |
let v5 = check-by-numbering("\u{AC00}") | |
if v5 { | |
if check-v7() { (0, 7, 0) } | |
else if check-v6() { (0, 6, 0) } | |
else { (0, 5, 0) } | |
} else if v2 { | |
if check-v4() { (0, 4, 0) } | |
else if check-v3() { (0, 3, 0) } | |
else { (0, 2, 0) } | |
} else { | |
if v1 { (0, 1, 0) } | |
else { (0, 0, 0) } // before 0.1.0 | |
} | |
} | |
} |
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
#import "tcversion.typ" | |
This is Typst version | |
// tcversion.version is an int array. | |
#tcversion.version.map(str).join(".");. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment