[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Behavior of octave and ans
From: |
c. |
Subject: |
Re: Behavior of octave and ans |
Date: |
Wed, 16 Jul 2014 11:44:01 +0200 |
On 16 Jul 2014, at 10:52, François Poulain <address@hidden> wrote:
> Le Fri, 11 Jul 2014 21:23:58 +0200,
> "c." <address@hidden> a écrit :
>
>> Is that what you need to do?
>
> As far as I understand, PAGER can help me to capture Octave's
> text output. But what is needed for our purpose is to get octaves
> objects. Because the simplest way to prettyprint Octave's object into
> any presentation format (think e.g. LaTeX, MathML) is to do it from
> Octave's side; not from a string output flow.
OK, now I understand better.
To put it simply I think what you want to do is not possible
at such high level.
You may try communicating with Octave via pipes or sockets, this
has been tried before for old unofficial GUI implementation, but never
worked reliably.
It will probably require patching Octave to make a reliable implementation
of this functionality, if you wish to go this route I suggest you bring up
the topic on the maintainers mailing list.
On the other hand, a simple approach would be to override the "display"
method for each class you want to pretty-print.
for example, if you save the following code:
----------
function display (a)
nd = ndims (a);
if (isa (a, 'double') && nd == 2)
printf ('\\begin{array}{|');
for ii = 1:columns (a), printf ('c|'); endfor
printf('}\\hline\n');
for ii = 1:rows (a) - 1
printf ('%g & ', a(ii, 1:end-1));
printf ('%g \\\\', a(ii, end));
printf ('\n\\hline ')
endfor
printf ('%g & ', a(end, 1:end-1));
printf ('%g \\\\', a(end, end));
printf ('\n')
printf ('\\hline\\end{array}\n')
endif
endfunction
----------
in a file named "@double/display.m" and add the parent
directory of "@double" to Octave's path, 'display (a)'
will then print a in LaTeX format:
----------
>> a = randn (5);
>> display (a)
\begin{array}{|c|c|c|c|c|}\hline
-1.11913 & 0.899339 & -0.746382 & 0.660301 & -0.62277 \\
\hline 2.31856 & 0.250639 & -1.18873 & 0.720844 & 0.845834 \\
\hline 2.37525 & 1.05243 & 0.814089 & -0.24478 & 0.733138 \\
\hline 0.351581 & -0.299835 & 1.07454 & -1.86589 & -0.980407 \\
\hline -0.412194 & -0.707724 & 0.132697 & 1.05254 & -0.611644 \\
\hline\end{array}
>>
----------
That will of course only happen if the user explicitely invokes
'display', if you want this method to be invoked each time an object
is output to screen that will require patching Octave.
> François
c.
- Behavior of octave and ans, François Poulain, 2014/07/07
- Re: Behavior of octave and ans, Mike Miller, 2014/07/07
- Re: Behavior of octave and ans, François Poulain, 2014/07/07
- Re: Behavior of octave and ans, Mike Miller, 2014/07/07
- Re: Behavior of octave and ans, François Poulain, 2014/07/10
- Message not available
- Re: Behavior of octave and ans, François Poulain, 2014/07/11
- Re: Behavior of octave and ans, c., 2014/07/11
- Re: Behavior of octave and ans, François Poulain, 2014/07/16
- Re: Behavior of octave and ans,
c. <=