MilesCranmer commited on
Commit
dafd19b
1 Parent(s): 96e5a0f

refactor: move more latex code to export_latex

Browse files
Files changed (2) hide show
  1. pysr/export_latex.py +12 -0
  2. pysr/sr.py +7 -9
pysr/export_latex.py CHANGED
@@ -153,3 +153,15 @@ def sympy2multilatextable(
153
  ]
154
 
155
  return "\n\n".join(latex_tables)
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  ]
154
 
155
  return "\n\n".join(latex_tables)
156
+
157
+
158
+ def with_preamble(table_string: str) -> str:
159
+ preamble_string = [
160
+ r"\usepackage{breqn}",
161
+ r"\usepackage{booktabs}",
162
+ "",
163
+ "...",
164
+ "",
165
+ table_string,
166
+ ]
167
+ return "\n".join(preamble_string)
pysr/sr.py CHANGED
@@ -31,7 +31,12 @@ from sklearn.utils.validation import check_is_fitted
31
  from .denoising import denoise, multi_denoise
32
  from .deprecated import DEPRECATED_KWARGS
33
  from .export_jax import sympy2jax
34
- from .export_latex import sympy2latex, sympy2latextable, sympy2multilatextable
 
 
 
 
 
35
  from .export_numpy import sympy2numpy
36
  from .export_sympy import assert_valid_sympy_symbol, create_sympy_symbols, pysr2sympy
37
  from .export_torch import sympy2torch
@@ -2410,14 +2415,7 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
2410
  "Expected a DataFrame or a list of DataFrames."
2411
  )
2412
 
2413
- preamble_string = [
2414
- r"\usepackage{breqn}",
2415
- r"\usepackage{booktabs}",
2416
- "",
2417
- "...",
2418
- "",
2419
- ]
2420
- return "\n".join(preamble_string + [table_string])
2421
 
2422
 
2423
  def idx_model_selection(equations: pd.DataFrame, model_selection: str):
 
31
  from .denoising import denoise, multi_denoise
32
  from .deprecated import DEPRECATED_KWARGS
33
  from .export_jax import sympy2jax
34
+ from .export_latex import (
35
+ sympy2latex,
36
+ sympy2latextable,
37
+ sympy2multilatextable,
38
+ with_preamble,
39
+ )
40
  from .export_numpy import sympy2numpy
41
  from .export_sympy import assert_valid_sympy_symbol, create_sympy_symbols, pysr2sympy
42
  from .export_torch import sympy2torch
 
2415
  "Expected a DataFrame or a list of DataFrames."
2416
  )
2417
 
2418
+ return with_preamble(table_string)
 
 
 
 
 
 
 
2419
 
2420
 
2421
  def idx_model_selection(equations: pd.DataFrame, model_selection: str):