Spaces:
Running
Running
Commit
·
6024c83
1
Parent(s):
b4577d9
Fix use of full_prec in latex export
Browse files- pysr/export_latex.py +4 -6
pysr/export_latex.py
CHANGED
|
@@ -6,22 +6,20 @@ from sympy.printing.latex import LatexPrinter
|
|
| 6 |
class PreciseLatexPrinter(LatexPrinter):
|
| 7 |
"""Modified SymPy printer with custom float precision."""
|
| 8 |
|
| 9 |
-
def __init__(self, settings=None, prec=3
|
| 10 |
super().__init__(settings)
|
| 11 |
self.prec = prec
|
| 12 |
-
self.full_prec = full_prec
|
| 13 |
|
| 14 |
def _print_Float(self, expr):
|
| 15 |
# Reduce precision of float:
|
| 16 |
-
reduced_float = sympy.Float(expr, self.prec
|
| 17 |
return super()._print_Float(reduced_float)
|
| 18 |
|
| 19 |
|
| 20 |
def to_latex(expr, prec=3, full_prec=True, **settings):
|
| 21 |
"""Convert sympy expression to LaTeX with custom precision."""
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
printer = PreciseLatexPrinter(settings=settings, prec=prec, full_prec=full_prec)
|
| 25 |
return printer.doprint(expr)
|
| 26 |
|
| 27 |
|
|
|
|
| 6 |
class PreciseLatexPrinter(LatexPrinter):
|
| 7 |
"""Modified SymPy printer with custom float precision."""
|
| 8 |
|
| 9 |
+
def __init__(self, settings=None, prec=3):
|
| 10 |
super().__init__(settings)
|
| 11 |
self.prec = prec
|
|
|
|
| 12 |
|
| 13 |
def _print_Float(self, expr):
|
| 14 |
# Reduce precision of float:
|
| 15 |
+
reduced_float = sympy.Float(expr, self.prec)
|
| 16 |
return super()._print_Float(reduced_float)
|
| 17 |
|
| 18 |
|
| 19 |
def to_latex(expr, prec=3, full_prec=True, **settings):
|
| 20 |
"""Convert sympy expression to LaTeX with custom precision."""
|
| 21 |
+
settings["full_prec"] = full_prec
|
| 22 |
+
printer = PreciseLatexPrinter(settings=settings, prec=prec)
|
|
|
|
| 23 |
return printer.doprint(expr)
|
| 24 |
|
| 25 |
|