pythontex icon indicating copy to clipboard operation
pythontex copied to clipboard

Add Matlab and Octave support

Open gpoore opened this issue 10 years ago • 5 comments

Starting development.

  • This will likely need a rewrite of the stderr parser (which is needed anyway).
  • Getting a full utilities class working may be more difficult than for other languages, given the restrictions of the languages (Matlab has classdef, which looks good, but Octave is still working with the older @classes).

Commit 29eef869d481fa5d03216a1ea7e370b19d9dc43b adds primitive Octave support.

Note on development

The template system for adding language support is only sparsely documented at present. This is because the system is subject to change as additional languages are added in the future. The system will stabilize at some point, but several different types of languages must be added first so that we can be sure that the system has a relatively complete feature set.

Note for Octave development

Initial solution for running scripts was a template command of the form

'{octave} -q --eval "cd \'{Outputdir}\'; more off; {file}"'

But that isn't ideal because it changes the working directory, which would then have to be changed again in {file} to whatever the user wants. A better option is something like

'{octave} -q "{File}.m"'

where the new {File} field is the name of the file to be executed, including the full path.

gpoore avatar Feb 15 '14 16:02 gpoore

Some discussion on Octave support got into another issue (see this and this).

After looking into Octave's @classes, I've decided not to implement a utilities class. Given how Octave classes work, something like

add_dependencies(octavetex, 'dep1', 'dep2', ... )

would be needed. But what I would really want, to parallel other languages, is something like

octavetex.add_dependencies('dep1', 'dep2', ... )

This is more object-oriented, and also avoids namespace collision issues.

The current solution uses functions instead of methods. So octavetex_add_dependencies() instead of octavetex.dependencies(), etc. All data is stored in an octavetex struct. So octavetex.context, etc., works. It's only the "methods" that must be accessed as functions. One significant advantage of this approach is that all functions may be defined in the Octave template. For a class, there would have to be a directory and one or more .m files, which would need to be added to Octave's search path.

Since Octave doesn't have associative arrays, octavetex.context is a struct. This means that the key-value pairs that can be passed (and then accessed without getfield()) will be somewhat limited. But there isn't an alternative.

Matlab has classdef and containers.Map, so it should be a nicer case to deal with.

gpoore avatar Feb 17 '14 20:02 gpoore

Octave support is essentially complete with 056c84c0379119889bf96c961befbcc9ac078cc2.

gpoore avatar Jul 03 '14 03:07 gpoore

Any progress on adding support for MATLAB? Octave is helpful, but MATLAB has a large set of additional toolboxes and functions not available in Octave.

Thank you very much for this excellent package!

fcdimitr avatar Feb 01 '23 02:02 fcdimitr

I haven't used MATLAB in a long time. If you want to try to get MATLAB working, using the Octave support as a template, you could look at pythontex_engines.py.

If you can work with Markdown instead, you might be able to use one of my other projects, Codebraid. It appears that a MATLAB Jupyter kernel has just been released (non-Windows only). Codebraid supports arbitrary Jupyter kernels. Codebraid currently only supports code execution in Markdown, but I'm exploring various ways to use it with LaTeX.

gpoore avatar Feb 01 '23 03:02 gpoore

Thanks! I will take a look at how to extend this package to include MATLAB and Codebraid.

fcdimitr avatar Feb 01 '23 03:02 fcdimitr