Skip to Content.
Sympa Menu

texmacs-users - RE: [TeXmacs] inline plots

Subject: mailing-list for TeXmacs Users

List archive

RE: [TeXmacs] inline plots


Chronological Thread 
  • From: "Bill Eaton" <address@hidden>
  • To: <address@hidden>
  • Subject: RE: [TeXmacs] inline plots
  • Date: Fri, 17 May 2013 14:05:18 -0700

> Every plugin would need similar code in the relevant language in the
appropriate
> file for that particular plugin.

Agreed. And that's what I'm trying to achieve. The ps_out function is not
especially difficult to implement.

> However, if you get this working using the Python session , you might
merely use
> this for all your plotting insertions by splitting the session between
Octave and
> Python for example

Oof. That's a lot less of a natural workflow. I did try to save to a file,
then Insert...Image outside of the session. That often doesn't work
correctly, and if you change the image, it is difficult to update without
closing TeXmacs and reopening. Once you get an inline image working, you'll
see how useful it is. Hopefully, I can get it working soon in Octave (or
someone can help me the last few steps to the finish line).

I think I'll take you up on your suggestion to cross post to the dev list.
This topic probably falls somewhere in between user land and dev land. I was
hoping someone more knowledgeable in Octave or Maxima might have some ideas
for those plugins. Octave should be more straightforward (I think).

Thanks again,

Bill Eaton

-----Original Message-----
From: David E. Miller [mailto:address@hidden]
Sent: Friday, May 17, 2013 12:16 PM
To: Bill Eaton
Cc: address@hidden
Subject: Re: [TeXmacs] inline plots

The ps_out function is located in the tm_python file
(/usr/lib/texmacs/TeXmacs/bin/tm_python on my Linux system). See code
snippet at the end.

Every plugin would need similar code in the relevant language in the
appropriate file for that particular plugin. However, if you get this
working using the Python session, you might merely use this for all your
plotting insertions by splitting the session between Octave and Python for
example. Unless of course, you are making the effort for the programming
challenge of adding this to as many plugins as possible. I am being
practical here.

Since there is an existing function for this included with the Python
plugin, you might start with that. However, if you want to go from there,
you might try the gnuplot plugin if you like using gnuplot, or one of the
other plugins for dedicated plotting programs. I mean, why go through
through another program merely to interface with a plotting program unless
there is some advantage? You might find when you start to to dig into this
that this task was easier to implement using Python than the others will be.
That is what I am guessing. These plugins are all different and can be
complicated. Usually those that developed these plugins are the ones that
are really familiar with how they work, There is no detailed documentation
outside the comments you might find in the relevant files and the general
info on plugins of the TeXmacs help. If you like solving puzzles, you'll
love this!

You might forward your email to the TeXmacs developer mail list, I am not
sure how much help you will get if any from the user list.

Don't charge me too much for the advice!

David Miller




def ps_out(ps_file):
"""Outputs Postscript within TeXmacs.

According the the type of the argument the following
scenarios can take place:

If the argument is a string and has more than one line, it
will be processed as raw Postscript data.

If the argument is a string, it's supposed to contain the
filename of a Postscript file which will be read ( if the
file has no extension, the defaults .ps and .eps will be
tried.)

If the argument is a file or other object which provides a
'read' method, data will be obtained by calling such
method.


Implemented from suggestion by Alvaro Tejero Cantero.
Implementation partially based on information provided
by Mark Arrasmith.
"""

if 'read' in dir(ps_file):
data = ps_file.read()
return chr(2)+'ps:'+data+chr(5)

if ps_file.find('\n')>0:
return chr(2)+'ps:'+ps_file+chr(5)

ext_list = ['', '.eps', '.ps']
if isinstance(ps_file, str):
for ext in ext_list:
if os.path.exists(ps_file+ext):
ps_fd = file(ps_file+ext, 'r')
data = ps_fd.read()
ps_fd.close()
break
else:
raise IOError('File \''+ps_file+'+'+str(ext_list)+'\' not
found.')
return chr(2)+'ps:'+data+chr(5)

On 5/17/2013 1:17 AM, Bill Eaton wrote:
> I'd like to solicit suggestions on how to do inline plots in various
> sessions. I've already figured out how to do it in one session and it
> doesn't look impossible for others.
>
> I know this is topic comes up often, but I have found few solutions.
> If you want to have a live mathematical scratchpad or notebook, its
> desirable to have live inline figures. If you're using the Maxima,
> Python, Octave, etc. plugin, you could invoke an extra command to
> insert an inline plot.
>
> In fact, this is already possible in the Python plugin, via the ps_out
> function. This ps_out function points the way how we might do it in
> other environments. Heck, maybe it's already possible in other
> environments but I just don't know how. In Python, here's a minimal
> example:
> import matplotlib
> matplotlib.use('ps')
> from pylab import *
> fig = figure(figsize=(3,2))
> ax=fig.add_subplot(111)
> ax.plot([1,2,3])
> ax.set_title('inline demo')
> savefig('demo.eps')
> ps_out('demo.eps')
> So from the session, you save an EPS file and then invoke the ps_out
> function to display it. The displayed plot behaves pretty well. You
> can go back and change things, overwrite the EPS figure and then
> reinvoke ps_out and you get a new plot. Pure magic.
>
> I looked inside ps_out and it just spits out the EPS file plus some
> extra stuff (here i use + for string concatenation:
> chr(2)+'ps:'+<EPS file contents>+chr(5)
>
> It should be easy to do the same thing in Octave. The ps_out function
> in Octave could be:
> function ps_out(fname)
> disp( [char(2); 'ps:'; fileread(fname) ; char(5)] )
> endfunction
>
> I'm dying to test this out and add more sophisticated error checking,
> but I don't know how to hack the appropriate file to look for the
> ps_out function. I think it would be in tmrepl.m. If someone can
> suggest the appropriate lines to modify, I would greatly appreciate
> and be happy to report my findings.
>
> Likewise, it would be really swell to have a similar functionality in
> Maxima. There I have less of a clue, but I'm guessing the
> texmacs-maxima-<ver>.lisp file is the one to hack. I'm willing to do
> some legwork if anyone has suggestions.
>
> --Bill Eaton
>
>
>





Archive powered by MHonArc 2.6.19.

Top of Page