help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: octave to (la)tex conversion


From: Leo Butler
Subject: Re: octave to (la)tex conversion
Date: Tue, 02 Oct 2012 14:27:30 -0400
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/23.4 (gnu/linux)

Laurent Hoeltgen <address@hidden> writes:

> On 02/10/12 17:26, Leo Butler wrote:
>> Carnë Draug <address@hidden> writes:
>>
>>> On 2 October 2012 01:01, Leo Butler <address@hidden> wrote:
>>>> Maxima has the function 'tex' that lets one transform an object in
>>>> Maxima to a string of tex code. This is quite useful: an emacs mode
>>>> (imaxima) uses this to create a front end that looks really
>>>> professional; plus, with mathjax, it can be rolled into a nice web-based
>>>> frontend.
>>>>
>>>> Is there anything similar in Octave?
>>>>
>>>> ----------
>>>> What I have in mind is the following application: I am writing course
>>>> notes that have a lot of numerical examples in them. With \write18, I
>>>> can put these inside a LaTeX file and have Octave do the computations. I
>>>> would like to have Octave run a hook before quitting to dump all of the
>>>> user-defined variables into a tex file as tex macros. It doesn't need to
>>>> be fancy, something like
>>>>
>>>> x=1:2; ==>
>>>> \def\octavex#1{\ifnum#1=1{1}\else\ifnum#1=2{2}\else\relax\fi\fi}
>>>>
>>>> IPC on the cheap, if you like. It seems like someone might have already
>>>> written something like this.
>>>>
>>>> Leo
>>>
>>> Look in the miscellaneous packages in the function `publish'. It
>>> should do what you want though I'm not sure if free of bugs. You find
>>> any, please fix it and send us patches.
>>>
>>> There's also a very nice textable function that hasn't been released
>>> yet (also from miscellaneous package). Check it out at
>>>
>>> https://sourceforge.net/p/octave/code/11184/tree/trunk/octave-forge/main/miscellaneous/inst/textable.m
>>>
>>> Carnë
>>
>> Carnë, Juan, thanks for the replies.
>>
>> I am not interested in type-setting octave code in latex, there are a
>> few ways to do that. The reference to maxima was because maxima makes it easy
>> to customize the tex output via texput.
>>
>> Nor am I really interested in the approach taken by textable or
>> publish. What I want is a way to export 'stuff' from octave to tex that
>> preserves as much structure as possible. I want tex to do the
>> typesetting and octave to do the calculations.
>>
>>  From your responses, I infer that there is not a readily available way
>> to do this. So, I scratched something together to illustrate what I
>> want. Here is a snippet (apologies for the apalling code):
>>
>> ,----
>> | octave> x=rand(1,3)
>> | x =
>> |
>> |    0.40866   0.24822   0.95185
>> |
>> | octave> texit(x,"x")
>> | ans = 
>> \def\x(#1){\ifnum#1<1\relax\else\ifnum#1>3\relax\else\ifnum#1=1{0.408658}\else\ifnum#1=2{0.248223}\else\ifnum#1=3{0.951853}\fi\fi\fi\fi\fi}
>> `----
>>
>> In tex, the vector components are accessed by \x(1), etc.
>> To typeset \x as a vector just requires a simple tex macro to loop
>> over all the entries in \x.
>>
>>
>>
>> ----------
>> (All code is released under gplv3; varargin is there to provide 
>> customizations):
>>
>> function s = texit(object,name,varargin)
>>    if            isscalar(object),       
>> s=texit_scalar(object,name,varargin);
>>    elseif        isvector(object),       
>> s=texit_vector(object,name,varargin);
>>    elseif        ismatrix(object),       
>> s=texit_matrix(object,name,varargin);
>>    endif
>> endfunction
>>
>> function s=texit_scalar(object,name,varargin)
>>    s=sprintf("\\def\\%s{%f}",name,object);
>> endfunction
>>
>> function s=texit_vector(x,name,varargin)
>>    n=length(x);
>>    c=texit_check_bounds(1,n);
>>    s=cstrcat("\\def\\",name,"(#1){",c);
>>    f="";
>>    for i=1:n
>>      t=texit_accessor(x(i),i);
>>      s=cstrcat(s,"\\else",t);
>>      f=cstrcat(f,"\\fi");
>>    endfor
>>    s=cstrcat(s,f,"\\fi\\fi}");
>> endfunction
>>
>>
>> _______________________________________________
>> Help-octave mailing list
>> address@hidden
>> https://mailman.cae.wisc.edu/listinfo/help-octave
>>
>
> Hi,
>
> if you are an emacs user, you can achieve something similar using
> org-mode and the corresponding babel functionality. Basically you
> write the notes as an org file (the syntax is similar to markdown) and
> insert source blocks inbetween the notes. Once you are finished you
> export the whole thing to pdf (org-mode uses latex for this) and
> during the export, the source blocks are evaluated and replaced with
> their corresponding results. They support pretty much every popular
> programming language (ruby, python, lisp, octave, gnuplot, R, bash,
> ...)
> I use org-mode quite a lot, but so far I haven't had a look at the
> babel functionality, therefore, I can't tell you how good the results
> look. More information here:
>
> http://orgmode.org/
> http://orgmode.org/worg/org-contrib/babel/
>
> Regards,
> Laurent

Thanks, Laurent, I am an emacs user. I have dabbled with org-mode and
have used muse quite a bit (in the spring, I taught a 16 week course
using muse to publish everything). Muse has a babel-like functionality
built-in. My feeling was that simple things were done well, but for
more complicated things it felt like there were too many moving
parts. And org-mode is, I think, a couple of orders of magnitude more
intricate than muse.

Regardless of that, it is mid-semester and I don't want to change my
non-muse/non-org-mode workflow radically...However, in the longer run,
I may take a second look at org-mode.

Leo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]