wxMaxima
Loading...
Searching...
No Matches
Data Structures | Functions
MathImport.h File Reference

Turns maths written in LaTeX or in MathML into a Maxima command (GH #932, GH #760). More...

#include <wx/string.h>
Include dependency graph for MathImport.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  wxm::MathImportResult
 The outcome of converting a formula to a Maxima command. More...
 

Functions

MathImportResult wxm::LaTeXToMaxima (const wxString &latex)
 Converts LaTeX maths, with or without $...$, (...) or [...] around it.
 
MathImportResult wxm::MathMLToMaxima (const wxString &mathml)
 Converts a MathML <math> element (presentation markup, or an annotation)
 
bool wxm::LooksLikeMathML (const wxString &text)
 True if the text is a MathML document rather than anything else.
 
MathImportResult wxm::MathToMaxima (const wxString &text)
 Converts either: MathML if LooksLikeMathML(), LaTeX otherwise.
 

Detailed Description

Turns maths written in LaTeX or in MathML into a Maxima command (GH #932, GH #760).

Neither LaTeX nor presentation MathML says what a formula means, only how it looks: a fraction bar, a raised exponent, a d in front of an x. So the conversion happens in two stages, and both input languages share the second one:

  1. A front end reads the input into a small layout tree (MathNode): rows of identifiers, numbers and operators, plus fractions, roots, sub-/superscripts, fences and tables. LaTeX and presentation MathML describe exactly these things, so both map onto it almost one to one.
  2. The interpretation (in MathImport.cpp) reads a meaning into that layout, which is where all the guessing lives: implicit multiplication, "\sin x" taking an argument without parentheses, d/dx being a derivative, the "dx" ending an integral, e^x being e^x, and so on. It then prints the result with the fewest parentheses Maxima needs.

The guesses are conservative: anything that has no unambiguous reading (a plus-minus sign, an accent, text) fails with a message saying what it was, instead of producing a command that silently means something else. The result is shown to the user in a code cell before anything is evaluated anyway.

MathML that carries an <annotation encoding="application/x-maxima"> (wxMaxima's own "Copy as MathML" adds one) needs no guessing at all: that annotation is the command, and is used as it is.

Everything here is GUI-free and needs no Maxima, so it is unit-tested directly (test_MathImport).