Robert Kern wrote:
> On Wed, Jan 7, 2009 at 18:31, Alan Bromborsky <abro...@verizon.net> wrote:
>   
>> Duh on my part.  I didn't even think about the documentation.  If you
>> use the 'math' directive you have to have latex.  If you are going to
>> use any latex math constructs in the documentation you need latex.
>> Considering what sympy is you will need math constructs at some point to
>> document it so latex is required to make html.
>>     
>
> No, sphinx.ext.jsmath can be used to generate HTML with LaTeX
> equations without needing a LaTeX installation.
>
>   
I have attached patch for revision of latex_ex and documentation for 
latex_ex so that LaTeXPrinter will not require the latex and xdvi 
program to run.  Of course if you don't have the programs or some 
equivalent you won't be able to view the output of LaTeXPrinter.  If you 
do have latex and xdvi the output will be displayed in a window when the 
function latex_ex.xdvi() is called.  See docs for details.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com
To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

>From da267dab4ca10ff9ed19e6bb8cd67205891ab650 Mon Sep 17 00:00:00 2001
From: Alan Bromborsky <bro...@ga.(none)>
Date: Thu, 8 Jan 2009 18:12:35 -0500
Subject: [PATCH] Update latex_ex and doc to work without latex and xdvi

---
 doc/src/galgebra/latex_ex/Maxwell.py   |   54 ++++++++-----------
 doc/src/galgebra/latex_ex/latex_ex.txt |   68 +++++++++++++++--------
 doc/src/galgebra/latex_ex/latexdemo.py |   14 +++---
 sympy/galgebra/examples/Dirac.py       |    4 +-
 sympy/galgebra/examples/Maxwell.py     |    2 +-
 sympy/galgebra/examples/coords.py      |    4 +-
 sympy/galgebra/latex_ex.py             |   92 ++++++++++++++++++++++++++++----
 7 files changed, 160 insertions(+), 78 deletions(-)

diff --git a/doc/src/galgebra/latex_ex/Maxwell.py b/doc/src/galgebra/latex_ex/Maxwell.py
index 97b70dd..ddac9b3 100755
--- a/doc/src/galgebra/latex_ex/Maxwell.py
+++ b/doc/src/galgebra/latex_ex/Maxwell.py
@@ -1,44 +1,45 @@
-#!/usr/bin/python
+import sys
+import sympy.galgebra.GAsympy as GA
+import sympy.galgebra.latex_ex as tex
 
-from sympy import *
-from GAsympy import *
-from latex_ex import *
-
-set_main(sys.modules[__name__])
+GA.set_main(sys.modules[__name__])
 
 if __name__ == '__main__':
-    
+
     metric = '1  0  0  0,'+\
              '0 -1  0  0,'+\
              '0  0 -1  0,'+\
              '0  0  0 -1'
 
-    vars = make_symbols('t x y z')
-    MV.setup('gamma_t gamma_x gamma_y gamma_z',metric,True,vars)
-    LaTeXPrinter.format(1,1,1,1)
-    I = MV(1,'pseudo')
+    vars = GA.make_symbols('t x y z')
+    GA.MV.setup('gamma_t gamma_x gamma_y gamma_z',metric,True,vars)
+    tex.Format()
+    I = GA.MV(1,'pseudo')
+    I.convert_to_blades()
     print '$I$ Pseudo-Scalar'
     print 'I =',I
-    B = MV('B','vector',fct=True)
-    E = MV('E','vector',fct=True)
+    B = GA.MV('B','vector',fct=True)
+    E = GA.MV('E','vector',fct=True)
     B.set_coef(1,0,0)
     E.set_coef(1,0,0)
     B *= gamma_t
     E *= gamma_t
-    J = MV('J','vector',fct=True)
-    F = E+I*B
-    print ' '
+    B.convert_to_blades()
+    E.convert_to_blades()
+    J = GA.MV('J','vector',fct=True)
     print '$B$ Magnetic Field Bi-Vector'
-    print 'B =',B
-    print '$F$ Electric Field Bi-Vector'
-    print 'E =',E
+    print 'B = Bvec gamma_0 =',B
+    print '$E$ Electric Field Bi-Vector'
+    print 'E = Evec gamma_0 =',E
+    F = E+I*B
     print '$E+IB$ Electo-Magnetic Field Bi-Vector'
-    print 'F =',F
+    print 'F = E+IB =',F
     print '$J$ Four Current'
     print 'J =',J
     gradF = F.grad()
+    gradF.convert_to_blades()
     print 'Geometric Derivative of Electo-Magnetic Field Bi-Vector'
-    MV_format(3)
+    tex.MV_format(3)
     print '\\nabla F =',gradF
     print 'All Maxwell Equations are'
     print '\\nabla F = J'
@@ -46,13 +47,4 @@ if __name__ == '__main__':
     print '<\\nabla F>_1 -J =',gradF.project(1)-J,' = 0'
     print 'Curl $E$ and Div $B$ equations'
     print '<\\nabla F>_3 =',gradF.project(3),' = 0'
-    xdvi()
-
-
-
-
-
-
-
-
-
+    tex.xdvi(filename='Maxwell.tex')
diff --git a/doc/src/galgebra/latex_ex/latex_ex.txt b/doc/src/galgebra/latex_ex/latex_ex.txt
index 33fa68a..083a460 100644
--- a/doc/src/galgebra/latex_ex/latex_ex.txt
+++ b/doc/src/galgebra/latex_ex/latex_ex.txt
@@ -48,7 +48,7 @@
    :mod:`latex` (while preserving the  current capabilities) to geometric algebra
    multivectors, :mod:`numpy` array's, and extends the ascii formatting of greek
    symbols, accents, and subscripts and superscripts.   Additionally the module is
-   configured to use the print command to  generate a LaTeXoutput file and display
+   configured to use the print command to  generate a LaTeX output file and display
    it using xdvi.
 
 
@@ -80,7 +80,7 @@ follows::
 
 A single underscore denotes a subscript and a double undscore a superscript.
 
-In addition to all normal LaTeXaccents boldmath is supported so that
+In addition to all normal LaTeX accents boldmath is supported so that
 ``omegaomegabm``:math:`\rightarrow \Omega\bm{\Omega}` so an accent (or boldmath)
 only applies to the character (characters in the case of the string representing
 a greek letter) immediately preceeding the accent command.
@@ -95,12 +95,13 @@ setup when :func:`Format` is called.  In addition to setting format switches in
 :class:`LaTeXPrinter`, :func:`Format` does two other critical tasks. Firstly,
 the :mod:`sympy` function :func:`Basic.__str__` is redirected to the
 :class:`LaTeXPrinter` helper function :func:`LaTeX`.  If nothing more that this
-were done the  python print command would output LaTeXcode.  Secondly,
+were done the  python print command would output LaTeX code.  Secondly,
 *sys.stdout* is redirected  to a file until :func:`xdvi` is called.  This file
-is then compiled with the :program:`latex` program and the dvi output file is
-displayed with the :program:`xdvi` program.  Thus for :class:`LaTeXPrinter` to
-work both :program:`latex` and :program:`xdvi` must be installed on your system
-and in the execution path.
+is then compiled with the :program:`latex` program (if present) and the dvi
+output file is displayed with the :program:`xdvi` program (if present).  Thus
+for :class:`LaTeXPrinter` to display the output in a window both
+:program:`latex` and :program:`xdvi` must be installed on your system and in the
+execution path.
 
 
 LaTeXPrinter Functions
@@ -168,6 +169,9 @@ Helper Functions for Extending LatexPrinter Class
    |                |             | Do not use ``\operator{}``     |
    |                |             | format.                        |
    +----------------+-------------+--------------------------------+
+   |                |             | Suppress printing of function  |
+   |                |             | arguments.                     |
+   +----------------+-------------+--------------------------------+
    | :math:`3^{d}`  | partial     | 0: Use partial derivative      |
    |                |             | format in ``latex.py``.        |
    +----------------+-------------+--------------------------------+
@@ -205,6 +209,24 @@ Helper Functions for Extending LatexPrinter Class
 
 .. function:: xdvi(filename='tmplatex.tex',debug=False)
 
+   :func:`xdvi` postprocesses the output of the print statements and generates the
+   latex file with name *filename*.  If the :program:`latex` and :program:`xdvi`
+   programs are present on the system they are invoked to display the latex file in
+   a  window.  If *debug=True* the associated output of :program:`latex` is sent to
+   *stdout*, otherwise it is sent to  */dev/null*.  If :class:`LaTeXPrinter` has
+   not been initialized :func:`xdvi` does nothing.
+
+The functions :func:`sym_format`, :func:`fct_format`, :func:`pdiff_format`, and
+:func:`MV_format` allow one to change various formatting aspects of the
+:class:`LaTeXPrinter`.  They do not initialize the class and if the are called
+with the class not initialized they have no effect.  These functions and the
+function :func:`xdvi` are designed so that if the :class:`LaTeXPrinter` class is
+not initialized the program output is as if the :class:`LaTeXPrinter` class is
+not used. Thus all one needs to do to get simple ascii output (possibly for
+program debugging) is to comment out the one function call that initializes the
+:class:`LaTeXPrinter` class.  All other :mod:`latex_ex` function calls can
+remain in the program and have no effect on program output.
+
 
 .. function:: sym_format(sym_fmt)
 
@@ -227,9 +249,9 @@ Helper Functions for Extending LatexPrinter Class
    (see :math:`3^{d}` switch in Table I).
 
 
-.. function:: mv_format(mv_fmt)
+.. function:: MV_format(mv_fmt)
 
-   :func:`mv_format` allows one to change the latex format options for
+   :func:`MV_format` allows one to change the latex format options for
    :class:`sympy` partial derivative output independent of other format switches
    (see :math:`3^{d}` switch in Table I).
 
@@ -265,12 +287,12 @@ The program :program:`latexdemo.py` demonstrates the extended symbol naming
 conventions in :mod:`latex_ex`.   the statment ``Format()`` starts the
 :class:`LaTeXPrinter` driver with default formatting. Note that on the right
 hand side of the output that *xbm* gives :math:`\bm{x}`, *alpha_1* gives
-:math:`alpha_{1}` and  *delta__nugamma_r* gives :math:`\delta^{\nu\gamma}_{r}`.
+:math:`\alpha_{1}` and  *delta__nugamma_r* gives :math:`\delta^{\nu\gamma}_{r}`.
 Also the fraction is  printed correctly.  The statment ``print 'x =',x`` sends
 the string ``'x = '+str(x)`` to the output processor (:func:`xdvi`).  Because
 the string contains an :math:`=` sign the processor treats the string as an
-LaTeXequation (unnumbered).  If ``'x ='``  was not in the print statment a
-LaTeXerror would be generated.  In the case of a :class:`GAsympy` multivector
+LaTeX equation (unnumbered).  If ``'x ='``  was not in the print statment a
+LaTeX error would be generated.  In the case of a :class:`GAsympy` multivector
 one does not need the ``'x ='`` if the multivector has been given a name.  In
 the example the :class:`GAsympy` function :func:`make_symbols` has been used to
 create the :class:`sympy` symbols for convenience.  The :class:`sympy` function
@@ -399,16 +421,14 @@ End of Program Output
 
 The program :program:`Maxwell.py` demonstrates the use of the
 :class:`LaTeXPrinter` class with the :mod:`GAsympy` module multivector class,
-:class:`MV`.  In this case we used the statement
-``LaTeXPrinter.format(1,1,1,1)`` which is equivalent to  ``Format('1 1 1 1')``
-or the default version of ``Format()``.  The only other explicit :mod:`latex_x`
-module formatting statement used is ``MV_format(3)``.  This statment changes the
-multivector latex format so that instead of printing the entire multivector on
-one line, which would run off the page, each multivector base and its
-coefficient are printed on individual lines using the latex align environment.
-Another option used is that the printing of function arguments is suppressed
-since :math:`E`, :math:`B`, :math:`J`, and :math:`F` are multivector fields and
-printing out the argument, :math:`(t,x,y,z)`, for every field component would
-greatly lengthen the output and make it more difficult to format in a pleasing
-way.
+:class:`MV`.  The :func:`Format` call initializes :class:`LaTeXPrinter`.  The
+only other explicit :mod:`latex_x`  module formatting statement used is
+``MV_format(3)``.  This statment changes the multivector latex format so that
+instead of printing the entire multivector on one line, which would run off the
+page, each multivector base and its coefficient are printed on individual lines
+using the latex align environment.  Another option used is that the printing of
+function arguments is suppressed since :math:`E`, :math:`B`, :math:`J`, and
+:math:`F` are multivector fields and printing out the argument,
+:math:`(t,x,y,z)`, for every field component would greatly lengthen the output
+and make it more difficult to format in a pleasing way.
 
diff --git a/doc/src/galgebra/latex_ex/latexdemo.py b/doc/src/galgebra/latex_ex/latexdemo.py
index aa7949b..d1a8d2c 100644
--- a/doc/src/galgebra/latex_ex/latexdemo.py
+++ b/doc/src/galgebra/latex_ex/latexdemo.py
@@ -1,16 +1,16 @@
-from GAsympy import *
-from latex_ex import *
-from sympy import *
+import sys
+import sympy.galgebra.GAsympy as GA
+import sympy.galgebra.latex_ex as tex
 
-set_main(sys.modules[__name__])
+GA.set_main(sys.modules[__name__])
 
 if __name__ == '__main__':
 
-    Format()
-    make_symbols('xbm alpha_1 delta__nugamma_r')
+    tex.Format()
+    GA.make_symbols('xbm alpha_1 delta__nugamma_r')
     
     x = alpha_1*xbm/delta__nugamma_r
     
     print 'x =',x
     
-    xdvi(debug=True)
\ No newline at end of file
+    tex.xdvi()
diff --git a/sympy/galgebra/examples/Dirac.py b/sympy/galgebra/examples/Dirac.py
index 310b0a5..53fe564 100755
--- a/sympy/galgebra/examples/Dirac.py
+++ b/sympy/galgebra/examples/Dirac.py
@@ -18,7 +18,7 @@ if __name__ == '__main__':
     GA.MV.setup('gamma_t gamma_x gamma_y gamma_z',metric,True,vars)
 
     parms = GA.make_symbols('m e')
-    tex.Format('1 1 1 1')
+    tex.Format()
     I = GA.MV(GA.ONE,'pseudo')
     nvars = len(vars)
     psi = GA.MV('psi','spinor',fct=True)
@@ -37,6 +37,6 @@ if __name__ == '__main__':
     print 'Dirac equation in terms of real geometric algebra/calculus '+\
           r'$\lp\nabla \bm{\psi} I \sigma_{z}-eA\bm{\psi} = m\bm{\psi}\gamma_{t}\rp$'
     print 'Spin measured with respect to $z$ axis'
-    tex.Format('mv=3')
+    tex.MV_format(3)
     print r'\nabla \bm{\psi} I \sigma_{z}-eA\bm{\psi}-m\bm{\psi}\gamma_{t} = ',dirac_eq,' = 0'
     tex.xdvi(filename='Dirac.tex')
\ No newline at end of file
diff --git a/sympy/galgebra/examples/Maxwell.py b/sympy/galgebra/examples/Maxwell.py
index ade0363..fd81645 100755
--- a/sympy/galgebra/examples/Maxwell.py
+++ b/sympy/galgebra/examples/Maxwell.py
@@ -15,7 +15,7 @@ if __name__ == '__main__':
 
     vars = GA.make_symbols('t x y z')
     GA.MV.setup('gamma_t gamma_x gamma_y gamma_z',metric,True,vars)
-    tex.LaTeXPrinter.format(1,1,1,1)
+    tex.Format()
     I = GA.MV(1,'pseudo')
     I.convert_to_blades()
     print '$I$ Pseudo-Scalar'
diff --git a/sympy/galgebra/examples/coords.py b/sympy/galgebra/examples/coords.py
index 4580386..7bda55f 100755
--- a/sympy/galgebra/examples/coords.py
+++ b/sympy/galgebra/examples/coords.py
@@ -13,7 +13,7 @@ if __name__ == '__main__':
              '0 0 1'
 
     GA.MV.setup('gamma_x gamma_y gamma_z',metric,True)
-    tex.Format('1 1 1 1')
+    tex.Format()
 
     coords = GA.make_symbols('r theta phi')
     x = r*(sympy.cos(theta)*gamma_z+sympy.sin(theta)*\
@@ -38,7 +38,7 @@ if __name__ == '__main__':
     divA = A.grad_int()
     curlA = -I*A.grad_ext()
     print '\\nabla \\cdot A =',divA
-    tex.Format('mv=3')
+    tex.MV_format(3)
     print '-I\\lp\\nabla \\W A\\rp =',curlA
 
     tex.xdvi(filename='coords.tex')
diff --git a/sympy/galgebra/latex_ex.py b/sympy/galgebra/latex_ex.py
index 311d4fe..29041f2 100644
--- a/sympy/galgebra/latex_ex.py
+++ b/sympy/galgebra/latex_ex.py
@@ -9,6 +9,39 @@ import re as regrep
 import sympy.galgebra.GAsympy
 import numpy
 
+def find_executable(executable, path=None):
+    """Try to find 'executable' in the directories listed in 'path' (a
+    string listing directories separated by 'os.pathsep'; defaults to
+    os.environ['PATH']).  Returns the complete filename or None if not
+    found
+    """
+    if path is None:
+        path = os.environ['PATH']
+    paths = path.split(os.pathsep)
+    extlist = ['']
+    if os.name == 'os2':
+        (base, ext) = os.path.splitext(executable)
+        # executable files on OS/2 can have an arbitrary extension, but
+        # .exe is automatically appended if no dot is present in the name
+        if not ext:
+            executable = executable + ".exe"
+    elif sys.platform == 'win32':
+        pathext = os.environ['PATHEXT'].lower().split(os.pathsep)
+        (base, ext) = os.path.splitext(executable)
+        if ext.lower() not in pathext:
+            extlist = pathext
+    for ext in extlist:
+        execname = executable + ext
+        if os.path.isfile(execname):
+            return execname
+        else:
+            for p in paths:
+                f = os.path.join(p, execname)
+                if os.path.isfile(f):
+                    return f
+    else:
+        return None
+
 def debug(tstr):
     return
 
@@ -873,6 +906,34 @@ class LaTeXPrinter(Printer):
         return tex
 
 def LaTeX(expr, inline=True):
+    """
+    Convert the given expression to LaTeX representation.
+
+    You can specify how the generated code will be delimited.
+    If the 'inline' keyword is set then inline LaTeX $ $ will
+    be used. Otherwise the resulting code will be enclosed in
+    'equation*' environment (remember to import 'amsmath').
+
+    >>> from sympy import *
+    >>> from sympy.abc import *
+
+    >>> latex((2*tau)**Rational(7,2))
+    '$8 \\sqrt{2} \\sqrt[7]{\\tau}$'
+
+    >>> latex((2*mu)**Rational(7,2), inline=False)
+    '\\begin{equation*}8 \\sqrt{2} \\sqrt[7]{\\mu}\\end{equation*}'
+
+    Besides all Basic based expressions, you can recursively
+    convert Pyhon containers (lists, tuples and dicts) and
+    also SymPy matrices:
+
+    >>> latex([2/x, y])
+    '$\\begin{bmatrix}\\frac{2}{x}, & y\\end{bmatrix}$'
+
+    The extended latex printer will also append the output to a
+    string (LaTeXPrinter.body) that will be processed by xdvi()
+    for immediate display one xdvi() is called.
+    """
     xstr = LaTeXPrinter(inline).doprint(expr)
     return (xstr)
 
@@ -1009,11 +1070,16 @@ def xdvi(filename='tmplatex.tex',debug=False):
     latex_file = open(filename,'w')
     latex_file.write(body)
     latex_file.close()
-    if debug: #Display latex excution output for debugging purposes
-        os.system('latex '+filename[:-4])
-    else: #Works for Linux don't know about Windows
-        os.system('latex '+filename[:-4]+' > /dev/null')
-    os.system('xdvi '+filename[:-4]+' &')
+
+    latex_str = find_executable('latex')
+    xdvi_str = find_executable('xdvi')
+
+    if latex_str != None and xdvi_str != None:
+        if debug: #Display latex excution output for debugging purposes
+            os.system(latex_str+' '+filename[:-4])
+        else: #Works for Linux don't know about Windows
+            os.system(latex_str+' '+filename[:-4]+' > /dev/null')
+        os.system(xdvi_str+' '+filename[:-4]+' &')
     LaTeXPrinter.LaTeX_flg = False
     return
 
@@ -1023,7 +1089,8 @@ def MV_format(mv_fmt):
     2      - Print each multivector grade on one line
     3      - Print each multivector base on one line
     """
-    LaTeXPrinter.fmt_dict['mv'] = mv_fmt
+    if LaTeXPrinter.LaTeX_flg:
+        LaTeXPrinter.fmt_dict['mv'] = mv_fmt
     return
 
 def fct_format(fct_fmt):
@@ -1034,7 +1101,8 @@ def fct_format(fct_fmt):
         Use enhanced symbol nameing for arbitrary functions.
         Use new names for standard functions (acos -> Cos^{-1})
     """
-    LaTeXPrinter.fct = fct_fmt
+    if LaTeXPrinter.LaTeX_flg:
+        LaTeXPrinter.fct = fct_fmt
     return
 
 def pdiff_format(pdiff_fmt):
@@ -1042,7 +1110,8 @@ def pdiff_format(pdiff_fmt):
     0 - Use default sympy partial derivative format
     1 - Contracted derivative format (no fraction symbols)
     """
-    LaTeXPrinter.fmt_dict['pdiff'] = pdiff_fmt
+    if LaTeXPrinter.LaTeX_flg:
+        LaTeXPrinter.fmt_dict['pdiff'] = pdiff_fmt
     return
 
 def sym_format(sym_fmt):
@@ -1052,7 +1121,8 @@ def sym_format(sym_fmt):
         basic symbol (symbol precceeding sub and superscripts)and in
         sub and superscripts of basic symbol and accents in basic symbol
     """
-    LaTeXPrinter.fmt_dict['sym'] = sym_fmt
+    if LaTeXPrinter.LaTeX_flg:
+        LaTeXPrinter.fmt_dict['sym'] = sym_fmt
     return
 
 def str_format(str_fmt):
@@ -1062,9 +1132,9 @@ def str_format(str_fmt):
         basic symbol (symbol precceeding sub and superscripts)and in
         sub and superscripts of basic symbol and accents in basic symbol
     """
-    LaTeXPrinter.fmt_dict['str'] = str_fmt
+    if LaTeXPrinter.LaTeX_flg:
+        LaTeXPrinter.fmt_dict['str'] = str_fmt
     return
 
 def ext_str(xstr):
     return(LaTeXPrinter.extended_symbol(xstr))
-
-- 
1.5.6.3

Reply via email to