Skip to Content.
Sympa Menu

texmacs-users - Re: [TeXmacs] TeXmacs Python plugin

Subject: mailing-list for TeXmacs Users

List archive

Re: [TeXmacs] TeXmacs Python plugin


Chronological Thread 
  • From: Mark Arrasmith <address@hidden>
  • To: address@hidden
  • Cc: Álvaro Tejero Cantero <address@hidden>, Ero Carrera <address@hidden>
  • Subject: Re: [TeXmacs] TeXmacs Python plugin
  • Date: Fri, 19 Mar 2004 09:27:06 -0600
  • Organization: WSU Mathematics

> Would it be possible to add support in tmPython to capture the
> postscript output from PyX (http://pyx.sourceforge.net) in order to have
> python-driven publication-quality graphs in TeXmacs?

I made a PyX plugin in bash for myself awhile back. I don't know if it will
help, but I'm attaching the tm_pyx, init-pyx.scm, and an example file.

Set tm_pyx executable and place it in your path and place init-pyx.scm
in .TeXmacs/plugins/pyx/progs/. You should now have PyX as an option within
text -> session. Then you can create a python/pyx script ... for example ...

<script>
from math import pi
from pyx import *

g = graph.graphxy(width=8)
g.plot(graph.paramfunction("t" , 0, 2*pi, "x, y = sin(3*t), sin(4*t)"))
g.writetofile("pyxtmp")
</script>

Basically make sure to end your image with g.writetofile("pyxtmp"). tm_pyx
looks for that name to dump the postscript file back into TeXmacs.

- mark

Attachment: tm_pyx
Description: application/shellscript

<TeXmacs|1.0.3>

<style|generic>

<\body>
\;

I thought it would be interesting to interface to python with the PyX
library \ \ \ \ -mark

<with|prog-language|pyx|prog-session|default|<\session>
<\output>
TeXmacs interface to PyX.

\;
</output>

<\input|PyX] >
# Sierpinski triangle\

# contributed by Gerhard Schmid

\;

from math import sqrt\

from pyx import *

\;

# triangle geometry\

l = 10\

h = 0.5*sqrt(3) * l

\;

# base triangle path\

p = path.path(path.moveto(0, 0),

\ \ \ path.lineto(l, 0),

\ \ \ path.lineto(0.5 * l, h),

\ \ \ path.closepath())

\;

for i in range(6):\

\ \ \ # path is scaled down ...\

\ \ \ p = p.transformed(trafo.scale(0.5))\

\ \ \ # ... and three times plotted (translated accordingly)\

\ \ \ p += ( p.transformed(trafo.translate(0.5 * l, 0)) +

\ \ \ \ \ \ \ \ \ \ p.transformed(trafo.translate(0.25 * l, 0.5 * h)) )

\;

c = canvas.canvas()\

c.stroke(p, canvas.linewidth.Thin)\

c.writetofile("pyxtmp")
</input>

<\output>
\;

\;
</output>

<\input|PyX] >
# fractal tree\

# contributed by Gerhard Schmid and André Wobst

\;

from pyx import *

\;

# base tree length\

l = 5

\;

# base transformations for the left, center, and right part of the tree

\

ltrafo = trafo.rotate(65).scaled(0.4).translated(0, l * 2.0 / 3.0)\

ctrafo = trafo.rotate(-4).scaled(0.75).translated(0, l)\

rtrafo = trafo.mirror(90).rotated(-65).scaled(0.35).translated(0, l)

\;

def tree(depth):\

\ \ \ "return transformations for a recursive tree of given depth"\

\ \ \ r = [trafo.rotate(5)]\

\ \ \ if depth \<gtr\> 0:

\ \ \ \ \ \ subtree = tree(depth-1)

\ \ \ \ \ \ r.extend([t*ltrafo for t in subtree])\

\ \ \ \ \ \ r.extend([t*ctrafo for t in subtree])\

\ \ \ \ \ \ r.extend([t*rtrafo for t in subtree])\

\ \ \ return r

\;

c = canvas.canvas()\

for t in tree(7):\

\ \ \ # apply the transformation to a "sub" and insert into
"main"-canvas\

\ \ \ c.insert(canvas.canvas(t).stroke(path.line(0, 0, 0, l)))\

c.writetofile("pyxtmp")
</input>

<\output>
\;

\;
</output>

<\input|PyX] >
from math import pi\

from pyx import *

\;

g = graph.graphxy(width=8)\

g.plot(graph.paramfunction("t", 0, 2*pi, "x, y = sin(3*t), sin(4*t)"))

g.writetofile("pyxtmp")
</input>

<\output>
\;

\;
</output>

<\input|PyX] >
# contributed by Sigmund Kohler

\;

from math import pi, cos\

from pyx import *\

from pyx.canvas import barrow, earrow, linewidth, linestyle\

from pyx.graph import graphxy, linaxis, axispainter, function, line

\;

mypainter = axispainter(baselineattrs=earrow.normal, titlepos=1)\

def mycos(x): return -cos(x)+.10*x

\;

g = graphxy(height=5, x2=None, y2=None,\

\ \ \ \ \ x=linaxis(min=-2.5*pi, max=3.3*pi, part=None,\

\ \ \ \ \ \ \ \ \ painter=mypainter, title=r"$\\\\delta\\\\phi$"),\

\ \ \ \ \ y=linaxis(min=-2.3, max=2, painter=None))\

g.plot(function("y=mycos(x)", context=locals()),\

\ \ \ \ \ line(lineattrs=linewidth.Thick))\

g.finish()

\;

x1, y1 = g.pos(-pi+.1, mycos(-pi+.1))\

x2, y2 = g.pos(-.1, mycos(-.1))\

x3, y3 = g.pos(pi+.1, mycos(pi+.1))

\;

g.stroke(path.line(x1-.5, y1, x1+.5, y1), linestyle.dashed)\

g.stroke(path.line(x1-.5, y3, x3+.5, y3), linestyle.dashed)\

g.stroke(path.line(x2-.5, y2, x3+.5, y2), linestyle.dashed)\

g.stroke(path.line(x1, y1, x1, y3), barrow.normal, earrow.normal)\

g.stroke(path.line(x3, y2, x3, y3), barrow.normal, earrow.normal)\

g.text(x1+.2, 0.5*(y1+y3), r"$2\\\\pi\\\\gamma k\\\\Omega$",
text.vshift.middlezero)\

g.text(x1-.6, y1-.1, r"$E_{\\\\rm b}$", text.halign.right)\

g.text(x3+.15, y2+.20, r"$2J_k(\\\\varepsilon/\\\\Omega)+\\\\pi\\\\gamma
k\\\\Omega$")

\;

g.writetofile("pyxtmp")
</input>

<\output>
\;

\;
</output>

<\input|PyX] >
\;
</input>
</session>>

\;
</body>

<\initial>
<\collection>
<associate|page-even|1in>
<associate|page-reduce-bot|0.3in>
<associate|page-reduce-right|0.7in>
<associate|page-reduce-left|0.7in>
<associate|page-top|1in>
<associate|page-type|letter>
<associate|page-right|1in>
<associate|font-base-size|11>
<associate|par-width|6.5in>
<associate|page-odd|1in>
<associate|page-bot|1in>
<associate|language|english>
<associate|page-reduce-top|0.3in>
</collection>
</initial>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; MODULE : init-pyx.scm
;; DESCRIPTION : Initialize Python-PyX plugin
;; COPYRIGHT : (C) 2003 Joris van der Hoeven.
;;
;; This software falls under the GNU general public license and comes WITHOUT
;; ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for details.
;; If you don't have this file, write to the Free Software Foundation, Inc.,
;; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (pyx-serialize lan t)
(import-from (texmacs plugin plugin-cmd))
(with u (pre-serialize lan t)
(with s (texmacs->verbatim (object->tree u))
(string-append (escape-verbatim (string-replace s "\n" "~")) "\n"))))

(plugin-configure pyx
(:require (url-exists-in-path? "python"))
(:launch "tm_pyx --texmacs")
(:serializer ,pyx-serialize)
(:session "PyX"))



Archive powered by MHonArc 2.6.19.

Top of Page