[sage-support] Re: Mathematical Expression to latex-code-conversion

2007-10-24 Thread mabshoff



On Oct 24, 7:15 pm, marko [EMAIL PROTECTED] wrote:
 Hello,

 I am quite new to SAGE but I think I've found a problem with the
 latex(math-expression) command. I've tried with version 2.8.6, 2.8.7
 and 2.8.8.1:

 The problem seems to be the abs() command. Take any function like
 f(x)=2*abs(x) with a changing sign. Entering now latex(f) shows me as
 the result:
 x \ {\mapsto}\ {2 \cdot \abs \left( x \right)}

That looks like a bug to me.

ticket opened by mhansen: http://www.sagetrac.org/sage_trac/ticket/982

I opened #983, but mhansen was faster :O


 Compiling this with LaTeX I cannot see the mathematical sign for abs
 ( preferred \left| (...) \right| ), but simple brackets. Furthermore
 the LaTeX compilers tells me of errors: !undefined control sentence
 In fact, \abs is no known latex command to me. Deleting \abs removes
 the latex compiler error, of course, but thats not the correct latex
 code for my expression for f(x).

 The following packages have been included for compiling in latex:
 \usepackage{ngerman}
 \usepackage{color, framed}
 \usepackage{graphicx}
 \usepackage{amsmath, amsthm, amssymb}
 \usepackage[automark]{scrpage2}

 I don't know if I've done something wrong or if this is a bug or if
 its even supposed to be that way. So I'ld like to ask you: what can I
 do?

 How can I get the right result as latex code, if its neccessary to use
 absolut values of functions or parts of functions?

 Thanks for your help,


Well, thank you for reporting the issue.

 marko

Cheers,

Michael


--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~--~~~~--~~--~--~---



[sage-support] Re: Mathematical Expression to latex-code-conversion

2007-10-24 Thread Mike Hansen
Hello,

I've fixed this issue and have included the patch below.  It will be
in the next release which should be come out in the next few days.
Here is the behavior after the patch:

sage: g(x) = 2*abs(x)
sage: latex(g)
x \ {\mapsto}\ {2 \cdot \left| x \right|}


--Mike

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~--~~~~--~~--~--~---

# HG changeset patch
# User Mike Hansen [EMAIL PROTECTED]
# Date 1193248166 18000
# Node ID ff6836693992d0cdf8513083904cccafb5b9bfa5
# Parent  384cf32899ac4ad7e086bbc3ca53c577d68bd3f1
Fixed #982

diff -r 384cf32899ac -r ff6836693992 sage/calculus/calculus.py
--- a/sage/calculus/calculus.py	Tue Oct 23 21:05:54 2007 -0500
+++ b/sage/calculus/calculus.py	Wed Oct 24 12:49:26 2007 -0500
@@ -3818,6 +3818,11 @@ class SymbolicComposition(SymbolicOperat
 if not self.is_simplified():
 return self.simplify()._latex_()
 ops = self._operands
+
+#Check to see if the function has a _latex_composition method
+if hasattr(ops[0], '_latex_composition'):
+return ops[0]._latex_composition(ops[1])
+
 # certain functions (such as \sqrt) need braces in LaTeX
 if (ops[0]).tex_needs_braces():
 return r%s{ %s } % ( (ops[0])._latex_(), (ops[1])._latex_())
@@ -4033,7 +4038,17 @@ class Function_abs(PrimitiveFunction):
 return abs
 
 def _latex_(self):
-return \\abs
+return \\mathrm{abs}
+
+def _latex_composition(self, x):
+
+sage: f = sage.calculus.calculus.Function_abs()
+sage: latex(f)
+\mathrm{abs}
+sage: latex(abs(x))
+\left| x \right|
+
+return \\left|  + latex(x) +  \\right|
 
 def _approx_(self, x):
 return float(x.__abs__())