8LWXpg / jupyter2typst

Jupyter to Typst converter with template support
MIT License
11 stars 0 forks source link

Convert sagemath's tables #3

Open Eloitor opened 11 months ago

Eloitor commented 11 months ago

Description

In my jupyter notebooks I construct tables with sagemath:

# Define table data
table_data = [
    ["Name", "Age", "City"],
    ["Alice", 25, "New York"],
    ["Bob", 30, "San Francisco"],
    ["Charlie", 35, "Los Angeles"]
]

# Create and display the table
table(table_data, header_row=True, frame=True)

This produces a table in the notebook, but it is not properly translated to typst.

#block[
#result-block("+---------+-----+---------------+
| Name    | Age | City          |
+=========+=====+===============+
| Alice   | 25  | New York      |
+---------+-----+---------------+
| Bob     | 30  | San Francisco |
+---------+-----+---------------+
| Charlie | 35  | Los Angeles   |
+---------+-----+---------------+")
]

Tables created manually in markdown get translated! :)

Use case

Display results using a table.

8LWXpg commented 11 months ago

That’s because the result block defaults to text/plain, so it ignores text/html and text/latex (and supporting these two is kind of complex).

if there's other text output format other than those three, please let me know.

Eloitor commented 11 months ago

I see, It is indeed an html table.

Eloitor commented 10 months ago

I think that the obvious way to deal with this might be by using pandoc to convert to typst the content of the text/html and text/latex specific cells. Am I oversimplifying?

8LWXpg commented 10 months ago

It's doable, since there is an existing package.

It might also be possible to replace KaTeX convert in Markdown with this package, but the performance impact is unclear.

I'm open for anyone who wants to submit a PR for this.