-
In a comment in issue #2196, @EpicEricEE gave a function for turning content into string, but it failed when the content has some math function such as #let to-string(content) = {
if content.has("text") {
content.text
} else if content.has("children") {
content.children.map(to-string).join("")
} else if content.has("body") {
to-string(content.body)
} else if content == [ ] {
" "
}
}
// succeed
#let c = [This _*cool*_ project]
#let s = to-string(c)
#type(s) // string type
// fail
#let c = [Hello $sin x$ World]
#let s = to-string(c)
#type(s) // content type How to improve the |
Beta Was this translation helpful? Give feedback.
Answered by
lvjr
Apr 5, 2024
Replies: 1 comment
-
I found the cause of this problem: for #let to-string(content) = {
if content.has("text") {
if type(content.text) == "string" {
content.text
} else {
to-string(content.text)
}
} else if content.has("children") {
content.children.map(to-string).join("")
} else if content.has("body") {
to-string(content.body)
} else if content == [ ] {
" "
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lvjr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found the cause of this problem: for
sin
function,op.text = [sin]
which is not a string. And the following is an improvedto-string
function: