Devlogs
The easiest way to display mathematical equations in Delphi (this solution will also work with any Windows application). the idea is to use TEX math syntax and mimeTEX application. all we have to do now is to call mimeTEX from Delphi with consol output redirected back to our application and display returned image. to display gif images in Delphi we can use - this component by Finn Tolderlund.
whole procedure (quick and dirty can look like this)
1 procedure TForm1.call_mimeTEX; 2 var 3 pR,pW : THANDLE; 4 si : TStartupInfo; 5 pi : TProcessInformation; 6 sa : SECURITY_ATTRIBUTES; 7 TextLine : array[0..$1000] of char; 8 j,k,l : word; 9 i,BytesReaded : longword; 10 gifstr : TStringStream; 11 g : TGIFimage; 12 begin 13 gifstr := TStringStream.Create(''); 14 //run mimeTEX 15 sa.nLength := sizeof(SECURITY_ATTRIBUTES); 16 sa.bInheritHandle := TRUE; 17 sa.lpSecurityDescriptor := nil; 18 CreatePipe(pR,pW,@sa,0); 19 ZeroMemory( @pi, sizeof(PROCESS_INFORMATION) ); 20 ZeroMemory( @si, sizeof(STARTUPINFO) ); 21 si.cb := sizeof(STARTUPINFO); 22 si.dwFlags := STARTF_USESTDHANDLES; 23 si.wShowWindow := SW_HIDE; 24 si.hStdOutput := pW; 25 si.hStdInput := pR; 26 if ( not CreateProcess( PChar('mimetex.exe'), PChar(' -d x^2+y^2'), 27 nil,nil,TRUE,CREATE_NO_WINDOW,nil,nil,si,pi) ) then 28 begin 29 MessageDlg('Error',mtError,[mbOK],0); 30 Exit; 31 end; 32 CloseHandle(pW); 33 WaitForSingleObject(pi.hProcess,INFINITE); 34 //read mimeTEX oputput (gif image) 35 while ReadFile( pR, TextLine, sizeOf(TextLine), BytesReaded, nil ) do 36 gifstr.Write(TextLine,BytesReaded); 37 CloseHandle( pR ); 38 gifstr.Seek(0,soBEginning); 39 //create gif image 40 g := TGifImage.Create; 41 g.LoadFromStream( gifstr ); 42 //draw gif 43 image1.Canvas.Draw(0,0,g); 44 g.free; 45 gifstr.Free; 46 end;
No comments as yet. Be first to comment.