Hi Stan, On Thu, Mar 26, 2009 at 5:59 AM, Stan Schymanski <schym...@gmail.com> > It seems that you and Jason are getting a firm grip on this, which is > great. Just out of curiosity and my ignorance of the underlying code: Is > your aim to hard-code certain functions, or is your aim to provide the > users with the possibility of defining the latex representation of their > functions? I assume it is the latter, as there is an indefinite number > of possible function names. Could you confirm?
My current aim was to deal with the function names which are named after Greek letters, and possibly with suffixes. For example: function names such as "psi", "tau0", "alpha_mn" "Psi_alpha" etc. Could you please give some examples for the later case? May be I am missing your point. Jason: I am attaching the patch for enhancing typesetting of functions. I need to add doc-tests though. In the patch, I have implemented all the situations that I planned to do. Apart from the situations I mentioned earlier, it now also supports following types of function name (single letters with suffixes) --------------- (6) function('f1',x) => f_{1}\left(x\right) (7) function('T_sigma',x) => T_{\sigma}\left(x\right) (8) function('R_ab',x) => R_{ab}\left(x\right) ---------------- Currently, the major problem is to figure out: whats going wrong in typesetting "diff( psi(x), x)" even though "exp(psi(x))" works beautifully. Similar issue arises for "integrate", "conjugate"... Cheers, Golam --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---
# HG changeset patch # User Golam Mortuza Hossain <gmhoss...@gmail.com> # Date 1238095231 10800 # Node ID 194e7cf7dfe3ba07ac44a820341ae9ef47f30ddb # Parent 17fe77f21e21c79cb989aaab2e2fe128d16beaa1 Adds supoort for type-setting functions as Greek letters diff -r 17fe77f21e21 -r 194e7cf7dfe3 sage/calculus/calculus.py --- a/sage/calculus/calculus.py Thu Mar 26 15:00:42 2009 -0300 +++ b/sage/calculus/calculus.py Thu Mar 26 16:20:31 2009 -0300 @@ -297,7 +297,7 @@ from sage.structure.parent_base import ParentWithBase import operator -from sage.misc.latex import latex, latex_variable_name +from sage.misc.latex import latex, latex_variable_name, latex_function_name from sage.misc.misc import uniq as unique from sage.structure.sage_object import SageObject @@ -9749,6 +9749,9 @@ {{{\it \partial}}\over{{\it \partial}\,x}}\,\left \lceil x \right \rceil """ + name = latex_function_name(self._f._name) + if name is not False: + return "%s\\left(%s\\right)"%(name, ', '.join([latex(x) for x in self._args])) try: return latex(self._maxima_()) except: diff -r 17fe77f21e21 -r 194e7cf7dfe3 sage/misc/latex.py --- a/sage/misc/latex.py Thu Mar 26 15:00:42 2009 -0300 +++ b/sage/misc/latex.py Thu Mar 26 16:20:31 2009 -0300 @@ -756,6 +756,53 @@ 'omega', 'Omega'] +def latex_function_name(x): + """ + If possible return common function names such as alpha, beta1, + psi_00, R_mn, etc. as latex symbols otherwise return False. + + This function is based largely on latex_variable_name function. + """ + # For known names return them after preprending with "\\" + if x in common_varnames: + return "\\" + x + + underscore = x.find("_") + if underscore == -1: + import re + # * The "\d|[.,]" means "decimal digit" or period or comma + # * The "+" means "1 or more" + # * The "$" means "at the end of the line" + m = re.search('(\d|[.,])+$',x) + if m is None: + prefix = x + suffix = None + else: + prefix = x[:m.start()] + suffix = x[m.start():] + else: + prefix = x[:underscore] + suffix = x[underscore+1:] + if len(suffix)== 0: + return False + # If suffix contains underscores then don't process + if suffix and suffix.find("_") != -1: + return False + # If prefix is not a common name or a more-than-one letters word + # then don't process + if prefix not in common_varnames and len(prefix) != 1: + return False + + if prefix in common_varnames: + prefix = "\\" + prefix + + if suffix and len(suffix) > 0: + if suffix in common_varnames: + suffix = "\\" + suffix + return '%s_{%s}'%(prefix, suffix) + else: + return '%s'%(prefix) + def latex_varify(a): if a in common_varnames: return "\\" + a