@@ -1171,6 +1171,111 @@ def to_latex(
11711171 )
11721172 return save_to_buffer (latex , buf = buf , encoding = encoding )
11731173
1174+ @overload
1175+ def to_typst (
1176+ self ,
1177+ buf : FilePath | WriteBuffer [str ],
1178+ * ,
1179+ encoding : str | None = ...,
1180+ sparse_index : bool | None = ...,
1181+ sparse_columns : bool | None = ...,
1182+ max_rows : int | None = ...,
1183+ max_columns : int | None = ...,
1184+ ) -> None : ...
1185+
1186+ @overload
1187+ def to_typst (
1188+ self ,
1189+ buf : None = ...,
1190+ * ,
1191+ encoding : str | None = ...,
1192+ sparse_index : bool | None = ...,
1193+ sparse_columns : bool | None = ...,
1194+ max_rows : int | None = ...,
1195+ max_columns : int | None = ...,
1196+ ) -> str : ...
1197+
1198+ @Substitution (buf = buffering_args , encoding = encoding_args )
1199+ def to_typst (
1200+ self ,
1201+ buf : FilePath | WriteBuffer [str ] | None = None ,
1202+ * ,
1203+ encoding : str | None = None ,
1204+ sparse_index : bool | None = None ,
1205+ sparse_columns : bool | None = None ,
1206+ max_rows : int | None = None ,
1207+ max_columns : int | None = None ,
1208+ ) -> str | None :
1209+ """
1210+ Write Styler to a file, buffer or string in Typst format.
1211+
1212+ .. versionadded:: 3.0.0
1213+
1214+ Parameters
1215+ ----------
1216+ %(buf)s
1217+ %(encoding)s
1218+ sparse_index : bool, optional
1219+ Whether to sparsify the display of a hierarchical index. Setting to False
1220+ will display each explicit level element in a hierarchical key for each row.
1221+ Defaults to ``pandas.options.styler.sparse.index`` value.
1222+ sparse_columns : bool, optional
1223+ Whether to sparsify the display of a hierarchical index. Setting to False
1224+ will display each explicit level element in a hierarchical key for each
1225+ column. Defaults to ``pandas.options.styler.sparse.columns`` value.
1226+ max_rows : int, optional
1227+ The maximum number of rows that will be rendered. Defaults to
1228+ ``pandas.options.styler.render.max_rows``, which is None.
1229+ max_columns : int, optional
1230+ The maximum number of columns that will be rendered. Defaults to
1231+ ``pandas.options.styler.render.max_columns``, which is None.
1232+
1233+ Rows and columns may be reduced if the number of total elements is
1234+ large. This value is set to ``pandas.options.styler.render.max_elements``,
1235+ which is 262144 (18 bit browser rendering).
1236+
1237+ Returns
1238+ -------
1239+ str or None
1240+ If `buf` is None, returns the result as a string. Otherwise returns `None`.
1241+
1242+ See Also
1243+ --------
1244+ DataFrame.to_typst : Write a DataFrame to a file,
1245+ buffer or string in Typst format.
1246+
1247+ Examples
1248+ --------
1249+ >>> df = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
1250+ >>> df.style.to_typst() # doctest: +SKIP
1251+
1252+ .. code-block:: typst
1253+
1254+ #table(
1255+ columns: 3,
1256+ [], [A], [B],
1257+
1258+ [0], [1], [3],
1259+ [1], [2], [4],
1260+ )
1261+ """
1262+ obj = self ._copy (deepcopy = True )
1263+
1264+ if sparse_index is None :
1265+ sparse_index = get_option ("styler.sparse.index" )
1266+ if sparse_columns is None :
1267+ sparse_columns = get_option ("styler.sparse.columns" )
1268+
1269+ text = obj ._render_typst (
1270+ sparse_columns = sparse_columns ,
1271+ sparse_index = sparse_index ,
1272+ max_rows = max_rows ,
1273+ max_cols = max_columns ,
1274+ )
1275+ return save_to_buffer (
1276+ text , buf = buf , encoding = (encoding if buf is not None else None )
1277+ )
1278+
11741279 @overload
11751280 def to_html (
11761281 self ,
0 commit comments