19

I'm looking for a simple component that displays mathematical expressions in Delphi. When I started out I thought it would be easy to find something on the net, but it turns out it was harder than anticipated. There are lots and lots of components that will parse mathematical expressions, but few (none?) that will display them.

Ideally I would like a component as simple as a TLabel, where I could set the caption to some expression and it would be displayed correctly, but some sort of library that let's me draw expressions to a canvas would also be sufficient for my needs.

Update:

I'm not talking about plotting graphs of functions or something like that. I want to display (for instance)

(X^2+3)/X

like this:

enter image description here

Solution:

MBo's answer was just what I was looking for. Some people may be put off by the fact that all comments and documentation are in Russian, but don't let that scare you. It was really easy to use.

Installation: Unzip the files (at least "ExprMake.pas" and "ExprDraw.pas") to a directory in your library path. That's it.

Use: I haven't experimented extensively with it, but these few lines demonstrates how easy it is.

procedure TForm1.Button1Click(Sender: TObject);
var
  vExprC : TExprClass;
  vExprB : TExprBuilder;
begin
  vExprB := TExprBuilder.Create;
  try
    vExprC := vExprB.BuildExpr('(X^2+3)/X');
    vExprC.Canvas := Canvas;
    vExprC.Font.Size := 50;
    vExprC.Draw(10,10,ehLeft,evTop);
  finally
    vExprC.Free;
    vExprB.Free;
  end;
end;
Svein Bringsli
  • 5,640
  • 7
  • 41
  • 73

4 Answers4

16

Native Delphi module by Anton Grigoriev to draw mathematical expressions. Assistant program - in Russian. This is how it looks.

Addition about credits: Modules are free. The author asks only to mention (AboutBox etc) that mathematical expressions have been drawn by means of ExprDraw and ExprMake modules, written by Anton Grigoriev (raw translation from readme.txt)

MBo
  • 77,366
  • 5
  • 53
  • 86
  • @SveinBringsli, that's perfect! I'm gonna try it out, too. – Pateman Apr 13 '12 at 14:00
  • @Pateman I don't know exactly. It was developed for Delphi 5. But I've checked it with BDS XE, and assistant program has been successfully compiled (with some warnings about unicode stuff) and it works. – MBo Apr 13 '12 at 14:05
  • What's the licensing of this thing? I can't see a thing – Leonardo Herrera Mar 01 '13 at 19:27
  • @Leonardo Herrera It is free. I've added info about credits to the post. – MBo Mar 02 '13 at 09:48
4

I don't know of a native Delphi implementation, but maybe this question is helpful to you: How to render a formula in WPF or WinForms. It mentions some C/C# solutions which could possibly translated or used as DLL (see the OP's solution).

Another alternative could be this Formulator ActiveX Control.

Furthermore it may broaden your search results if you use some other search criteria, especially without the "Delphi" keyword. ;-)

renderer, formula, math, MathML, expression, engine, tex, ...

And as we can learn from MBo's answer, it could also be a good idea to search in other languages :-)

delphi математических формул рисования 

I'm sure you searched for something like that, but possibly there is one keyword that you have forgotten.

Community
  • 1
  • 1
splash
  • 13,037
  • 1
  • 44
  • 67
2

I was looking for a similar component for some time and MBo's solution would be acceptable.

I was convinced that it could be done also in another way: embedding a TWebBrowser and using an exixting javascript renderer for LaTex and MathML formulas, but...

I just tried QDSEquations and I think it's even a better solution!

⟪ Delphi component equation editor that allow you to enter and display math formulas of any complexity, from simple Greek symbols to matrixes and complex integral expressions. You can use the equation editor in your projects written in the Delphi environment, for example, in programs testing knowledge of different mathematics fields (mathematical analysis, discrete mathematics, probability theory and so on), physics and other.

It’s quite easy to enter formulas in it:

  • simple symbols are entered similarly to entering data in a text field
  • special symbols and formula elements are entered with the help of an additional menu ⟫

It's better because you can edit formula directly in a "textfield" component with the help of an additional button-menu component and/or using a math expression string and/or using predefined methods.

Hope it helped!

Derrick
  • 43
  • 5
0

I had the same problem several months ago, I solved it by getting a LaTeX renderer DLL which could be called from Delphi. Then you just called it, giving it the expression as a string, and it returned you a bitmap with the rendered expression in it.

I forgot the name unfortunately :( but you should be able to find it again by looking for "latex dll delphi"?

Thomas
  • 3,321
  • 1
  • 21
  • 44
  • I lost the source long ago. I do remember it was pretty simple to use, especially if you take the time to make a nice interface unit. – Thomas Apr 13 '12 at 17:23
  • Thank you for answering. Wasn'it *Ghostscript* by chance? – menjaraz Apr 13 '12 at 17:42
  • Don't think so. It was just a basic DLL which had an export of the form `function(Expression: PChar): HBITMAP;` and did all the rendering directly. But that's all I can recollect. Memory is not my strong point :p – Thomas Apr 13 '12 at 18:04