@@ -1228,6 +1228,99 @@ def to_latex(
12281228 )
12291229 return save_to_buffer (latex , buf = buf , encoding = encoding )
12301230
1231+ @overload
1232+ def to_typst (
1233+ self ,
1234+ buf : FilePath | WriteBuffer [str ],
1235+ * ,
1236+ encoding : str | None = ...,
1237+ sparse_index : bool | None = ...,
1238+ sparse_columns : bool | None = ...,
1239+ max_rows : int | None = ...,
1240+ max_columns : int | None = ...,
1241+ ) -> None : ...
1242+
1243+ @overload
1244+ def to_typst (
1245+ self ,
1246+ buf : None = ...,
1247+ * ,
1248+ encoding : str | None = ...,
1249+ sparse_index : bool | None = ...,
1250+ sparse_columns : bool | None = ...,
1251+ max_rows : int | None = ...,
1252+ max_columns : int | None = ...,
1253+ ) -> str : ...
1254+
1255+ @Substitution (buf = buffering_args , encoding = encoding_args )
1256+ def to_typst (
1257+ self ,
1258+ buf : FilePath | WriteBuffer [str ] | None = None ,
1259+ * ,
1260+ encoding : str | None = None ,
1261+ sparse_index : bool | None = None ,
1262+ sparse_columns : bool | None = None ,
1263+ max_rows : int | None = None ,
1264+ max_columns : int | None = None ,
1265+ ) -> str | None :
1266+ """
1267+ Write Styler to a file, buffer or string in Typst format.
1268+
1269+ Parameters
1270+ ----------
1271+ %(buf)s
1272+ %(encoding)s
1273+ sparse_index : bool, optional
1274+ Whether to sparsify the display of a hierarchical index. Setting to False
1275+ will display each explicit level element in a hierarchical key for each row.
1276+ Defaults to ``pandas.options.styler.sparse.index`` value.
1277+ sparse_columns : bool, optional
1278+ Whether to sparsify the display of a hierarchical index. Setting to False
1279+ will display each explicit level element in a hierarchical key for each
1280+ column. Defaults to ``pandas.options.styler.sparse.columns`` value.
1281+ max_rows : int, optional
1282+ The maximum number of rows that will be rendered. Defaults to
1283+ ``pandas.options.styler.render.max_rows``, which is None.
1284+ max_columns : int, optional
1285+ The maximum number of columns that will be rendered. Defaults to
1286+ ``pandas.options.styler.render.max_columns``, which is None.
1287+
1288+ Rows and columns may be reduced if the number of total elements is
1289+ large. This value is set to ``pandas.options.styler.render.max_elements``,
1290+ which is 262144 (18 bit browser rendering).
1291+
1292+ Returns
1293+ -------
1294+ str or None
1295+ If `buf` is None, returns the result as a string. Otherwise returns `None`.
1296+
1297+ See Also
1298+ --------
1299+ DataFrame.to_typst : Write a DataFrame to a file, buffer or string in Typst format.
1300+
1301+ Examples
1302+ --------
1303+ >>> df = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
1304+ >>> df.style.to_typst()
1305+ '#table(\\ n columns: 3,\\ n [], [A], [B],\\ n\\ n [0], [1], [3],\\ n [1], [2], [4],\\ n)'
1306+ """
1307+ obj = self ._copy (deepcopy = True )
1308+
1309+ if sparse_index is None :
1310+ sparse_index = get_option ("styler.sparse.index" )
1311+ if sparse_columns is None :
1312+ sparse_columns = get_option ("styler.sparse.columns" )
1313+
1314+ text = obj ._render_typst (
1315+ sparse_columns = sparse_columns ,
1316+ sparse_index = sparse_index ,
1317+ max_rows = max_rows ,
1318+ max_cols = max_columns ,
1319+ )
1320+ return save_to_buffer (
1321+ text , buf = buf , encoding = (encoding if buf is not None else None )
1322+ )
1323+
12311324 @overload
12321325 def to_html (
12331326 self ,
0 commit comments