#Escape and bindings for Kotlin

17 messages · Page 1 of 1 (latest)

dull jackal
#

These are actually two projects, the former using the latter.

https://github.com/LDemetrios/Typst4k
Typst4k is a library which allows manipulating typst values and accessing the compiler from within Kotlin code. (There are yet few issues with queries that obtain something except numbers, strings, arrays, nones, dicts and contents)

https://github.com/LDemetrios/TypstEscape
TypstEscape is an app that allows invoking shell commands from within typst doc. Some security measures have been taken, but be accurate! However I found it very useful for documenting libraies and stuff for other languages. May be some time I'll have time to make documentations for these two projects using itself 🙂 For now, here is an example: https://github.com/LDemetrios/Programnomicon/blob/main/reinterpret_cast and java/reinterpret-cast-and-java.pdf

They are in draft state, so something may be not working properly, but they work!

#

Example of the Typst4k usage as well

flint zealot
#

can't access the second link
I think it's either private or wrong repo name

runic canopy
#

This is really cool! Does Kotlin have many other types that have a meaningful Typst representation?

dull jackal
runic canopy
#

that answers my question, so I think you got it!

#

you maybe could do Kotlin string --> Typst string? what's the difference between "a".t and "a".text?

dull jackal
# runic canopy you maybe could do Kotlin string --> Typst string? what's the difference between...

Those produce different types. There are TStr which represents typst str and TText (extends TContent), typst text.
"a".t is a shorthand for TStr("a")
"a".text is a shorthand for TText(text = TStr("a"))
As Kotlin is strictly typed, difference is important. sequence is basically a list of contents, so contructor of TSequence accepts TArray<TContent> or vararg TContent. TText is TContent, TStr is not, so we use "a".text. Where there are actual strs used, e.g. in eval, there we use"a".t.

runic canopy
#

TStr which represents typst str
Oh cool, already done!

#

thanks for the explanation, that helps

dull jackal
#

I may be in future could simplify that with a bunch of boilerplate (like if function accepts TStr, it can also accept Kotlin's natural String), but that's for another day:)

runic canopy
#

you might be interested in (my project) Typstry.jl, which does similar things but for Julia

dull jackal
#

I just had a wild thought. In Kotlin one can (with a bit of dark magic) access the bytecode of a closure and its captured values... Which probably means I can (to the limit) convert kotlin functions into typst functions...

runic canopy
#

what's it like to extract data from the bytecode, is it difficult to understand?