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