question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Work out how to integrate GaLatexPrinter._print_Function upstream

See original GitHub issue

Our copy of this function seems to have originated from sympy/sympy@c1fdd853a9ef6a5553a7462ac8b338e0940472bb

The diff below shows the changes made in galgebra

diff --git a/galgebra/printer.py b/galgebra/printer.py
index 3d3b515..e5bb2b0 100644
+-- a/galgebra/printer.py
-++ b/galgebra/printer.py
@@ -763,31 +763,30 @@ class GaLatexPrinter(LatexPrinter):
     def _print_Function(self, expr, exp=None):
 
         func = expr.func.__name__
+        name = func
-
         if hasattr(self, '_print_' + func):
             return getattr(self, '_print_' + func)(expr, exp)
         else:
+            args = [str(self._print(arg)) for arg in expr.args]
+
-            args = [ str(self._print(arg)) for arg in expr.args ]
             # How inverse trig functions should be displayed, formats are:
             # abbreviated: asin, full: arcsin, power: sin^-1
+            #inv_trig_style = self._settings['inv_trig_style']
+            _inv_trig_style = GaLatexPrinter.inv_trig_style
-            inv_trig_style = self._settings['inv_trig_style']
             # If we are dealing with a power-style inverse trig function
             inv_trig_power_case = False
             # If it is applicable to fold the argument brackets
             can_fold_brackets = self._settings['fold_func_brackets'] and \
+                len(args) == 1 and not self._needs_function_brackets(expr.args[0])
-                len(args) == 1 and \
-                not self._needs_function_brackets(expr.args[0])
 
+            inv_trig_table = ["asin", "acos", "atan", "acot", "acosh", "asinh", "atanh"]
-            inv_trig_table = ["asin", "acos", "atan", "acot"]
 
             # If the function is an inverse trig function, handle the style
             if func in inv_trig_table:
+                if GaLatexPrinter.inv_trig_style == "abbreviated":
-                if inv_trig_style == "abbreviated":
                     func = func
+                elif GaLatexPrinter.inv_trig_style == "full":
-                elif inv_trig_style == "full":
                     func = "arc" + func[1:]
+                elif GaLatexPrinter.inv_trig_style == "power":
-                elif inv_trig_style == "power":
                     func = func[1:]
                     inv_trig_power_case = True
 
@@ -804,21 +803,15 @@ class GaLatexPrinter(LatexPrinter):
                 if func in accepted_latex_functions:
                     name = r"\%s^{%s}" % (func, exp)
                 else:
+                    name = latex(Symbol(func)) + ' '
+                    if '_' in func or '^' in func:
+                        name = r'{\left ( ' + name + r'\right ) }^{' + exp + '}'
+                    else:
+                        name += '^{' + exp + '}'
-                    # If the generic function name contains an underscore, handle it
-                    name = r"\operatorname{%s}^{%s}" % (
-                        func.replace("_", r"\_"), exp)
             else:
                 if func in accepted_latex_functions:
                     name = r"\%s" % func
                 else:
+                    name = latex(Symbol(func)) + ' '
+                    if exp is not None:
+                        if '_' in name or '^' in name:
+                            name = r'\left ( ' + name + r'\right )^{' + exp + '}'
+                        else:
+                            name += '^{' + exp + '}'
-                    # If the generic function name contains an underscore, handle it
-                    name = r"\operatorname{%s}" % func.replace("_", r"\_")
 
             if can_fold_brackets:
                 if func in accepted_latex_functions:
@@ -826,25 +819,14 @@ class GaLatexPrinter(LatexPrinter):
                     # with the function name itself
                     name += r" {%s}"
                 else:
+                    if not GaLatexPrinter.Fmode:
+                        name += r"%s"
-                    name += r"%s"
             else:
+                if func in accepted_latex_functions or not GaLatexPrinter.Fmode:
+                    name += r"{\left (%s \right )}"
-                name += r"{\left (%s \right )}"
 
             if inv_trig_power_case and exp is not None:
                 name += r"^{%s}" % exp
 
+            if func in accepted_latex_functions or not GaLatexPrinter.Fmode:
+                if len(args) == 1:
+                    name = name % args[0]
+                else:
+                    name = name % ",".join(args)
+
+            if 'det(g)' in name:
+                name = name.replace('det(g)', r'\det\left ( g \right )')
+
+            return name
-            return name % ",".join(args)
 
     def _print_Derivative(self, expr):
         dim = len(expr.variables)

We should work out ways to either integrate these upstream, or achieve them without modifying this function.

Listing the changes explicitly:

  • inv_trig_style moved from _settings to an attribute.
    • action: Switch galgebra to use settings if possible instead (gh-364)
  • more trig functions are supported in the inverse representation
  • subscripts / superscripts are parsed within function names
    • action: work out if we can spell this another way, which isn’t conflicting with the sympy meaning
  • extra parentheses are added around function names containing superscripts/subscripts
    • action: wait for the item above
  • special handling for printing det(g)
    • action: work out if we can spell this another way, perhaps with a Function subclass (#340)
  • .Fmode, to disable printing function arguments.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
eric-wiesercommented, Jul 20, 2020
0reactions
utensilcommented, Jun 4, 2020

It has no commits pushed to it though.

Oh, the local code is so ugly that I haven’t pushed it. Forget about it then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting up and using printers — SymPy tutorial at SciPy 2011 ...
Alternatively one can use SymPy's function init_printing(). This works only for pretty printer, but is the fastest way to setup this type of...
Read more >
Printing — SymPy 0.7.4.1 documentation - omz:software
Just change the “Output Format” in the settings. If you plan to work in an interactive calculator-type session, the init_session function will automatically ......
Read more >
Printing Using SAi FlexiPRINT HP Basic 100 Series Wizard on ...
Select the substrate type that are loaded on you HP Latex printer. ... jobs, manage the printer settings and control main RIP functions....
Read more >
Bug listing with status RESOLVED with resolution UPSTREAM ...
PREEXEC like function" status:RESOLVED resolution:UPSTREAM severity: ... "Printing to PDF doesn't allow other file name than default (output.pdf)" ...
Read more >
How to improve Poster Production printing with HP Latex ...
For the stated purpose of poster printing on paper-based media, ... While the 300 Series printers include an X-cut function to separate the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found