Skip to content

Instantly share code, notes, and snippets.

@kolibril13
Created April 17, 2025 16:50
Show Gist options
  • Save kolibril13/53797d20bd3f802c39b0edf23684c2ab to your computer and use it in GitHub Desktop.
Save kolibril13/53797d20bd3f802c39b0edf23684c2ab to your computer and use it in GitHub Desktop.
from typst_importer.typst_to_svg import typst_express
def typst_codeblock(code: str, position: tuple, name: str):
preamble = '''
#set page(width: 950pt, height: auto, margin: 0cm, fill: none)
#import "@preview/codelst:2.0.2": sourcecode
#import "@preview/tablex:0.0.8": tablex
'''
content = f"""{preamble}
#sourcecode[```python
{code.strip()}
```]
"""
return typst_express(
content=content,
origin_to_char=True,
position=position,
name=name,
scale_factor=300,
)
code1 = typst_codeblock(
code="""
def hi():
print("Hello, world!")
hi()
""",
position=(0, 0, 0),
name="Code1",
)
code2 = typst_codeblock(
code="""
def hi():
excited = True
if excited:
print("Hello, world!")
hi()
""",
position=(0, -5, -1),
name="Code2",
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment