Code Monkey home page Code Monkey logo

Comments (8)

robert-dodier avatar robert-dodier commented on September 25, 2024

Hi, thanks for your interest in maxima-jupyter.

Maxima-jupyter relies on Maxima's TeX output functions to generate TeX. It is possible to modify the way strings (or other elements) are handled, although for strings that would require some relatively low-level modifications (in Lisp) since Maxima is not set up to allow modifying TeX output for strings. (TeX output for expressions can be modified via texput, which see.)

Maybe what you are looking for is better addressed by figuring out how to put a program-generated TeX output into text. E.g. one would write "Equation A_1 is {{a}}" or something like that. If so, maybe this plugin will help? https://github.com/ipython-contrib/jupyter_contrib_nbextensions/tree/master/src/jupyter_contrib_nbextensions/nbextensions/python-markdown

Let me know what you think of that.

best,
Robert Dodier

from maxima-jupyter.

simonhallstroem avatar simonhallstroem commented on September 25, 2024

Thanks a lot for your fast response.

The python-markdown extension helped a lot: If I enter

eq:3*x+1=0;

in a code cell, and

The solution of {{eq;}}

in a markdown cell (without the semicolon I get a parsing error), the equation prints nicely in the markdown cell, but is still centered and not inline, probably there are still some $$ around it.

I tried
:lisp (setq tex-environment-default '("\(" . "\)"))
and
set_tex_environment (":", "$", "$");

but neither command removed these double dollars.

If I would try to understand these low level lisp modification you mentioned, where should I start reading?

However, I am very grateful for your help, and I really enjoy working with maxima-jupyter (and so do my students).

Kind regards,
Simon Hallström

from maxima-jupyter.

simonhallstroem avatar simonhallstroem commented on September 25, 2024

If I evaluate the following code in a code cell:

to_lisp();
(setq *tex-environment-default* '("\\(" . 
(setf (get 'mdefine 'tex-environment) *tex-environment-default*)
(setf (get 'mdefmacro 'tex-environment) *tex-environment-default*)
(setf (get 'mlabel 'tex-environment) *tex-environment-default*)
(defprop mlabel jupyter-mlabel tex)
(defun jupyter-mlabel (x l r)
  (tex (caddr x)
       (append l
	       (if (and (cadr x) *display-labels-p*)
		   (list (format nil "\\tag{$~A$}" (tex-stripdollar (cadr x))))
		   nil))
       r 'mparen 'mparen))

and in another code cell:

eq:3*x+1=0;
solve(eq);

and in a markup cell:

The solution is {{eq;}}

then, for a fraction of a second, the markup cells renders the equation inline but then switches to display math.

The above commands are from maxima-jupyter/src/overrides.lisp and I was just guessing.
So maybe a I was playing around with the wrong commands.

Kind regards, Simon

from maxima-jupyter.

robert-dodier avatar robert-dodier commented on September 25, 2024

Hi Simon, I'm glad to hear that maxima-jupyter is working for you and your students. That's exciting! I'm glad to hear that someone finds it useful. By the way, by what means are you installing it? Installation is always more than half the battle ....

About the display problem, one idea that comes to mind is this. Try :lisp (setq *display-labels-p* nil) Just guessing here.

I think that inline equations is a good feature so I will ask Tarn Burton who has done a lot of work on maxima-jupyter to take a look at it.

from maxima-jupyter.

yitzchak avatar yitzchak commented on September 25, 2024

@simonhallstroem You can construct results and send them to Jupyter using jupyter_latex. For instance

jupyter_latex(
  concat("The solution of \\(",
             tex1(eq), 
             "\\) is \\(", 
             tex1(solve(eq)[1]), "\\)"),
  true)$

Although this is kind off complex and really just what print should be doing. I think that your first instinct to use print was correct. In other words we need to override Maxima's default print funtion so that it operates correctly in Jupyter.

I'll submit a PR with a fix soon.

from maxima-jupyter.

robert-dodier avatar robert-dodier commented on September 25, 2024

Thanks a lot, Tarn, I've merged the PR. Can you give an example of how the new print function would be used?

What do you think about having an inline equation capability in addition to the print function? Can one use the print function to get the same effect, or is there something else that could be achieved with an inline equation?

from maxima-jupyter.

yitzchak avatar yitzchak commented on September 25, 2024

@robert-dodier I'll add an example to one of the worksheets, but basically you just use the print function as you would in Maxima. For example

eq:3*x+1=0$
sol:solve(eq)$
print("The solution of", eq, "is", sol[1])$

I agree that we should explore better inline equation capabilities. Probably as an option in the result rendering facilities. Although the fact that Maxima's TeX facilities don't really know the difference between inline and display equations kind of complicates the issue. Therefore some forms (like fractions) will look a bit odd. texify does have an inline equation style so maybe we should add an option to use it, or at least make it easier to switch?

from maxima-jupyter.

simonhallstroem avatar simonhallstroem commented on September 25, 2024

from maxima-jupyter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.