source: tol/tolbase/lib/mimetex/mimetex.tcl @ 8561735

1941-docker-image-to-testdevel
Last change on this file since 8561735 was a680983, checked in by Jorge Pérez <josp.jorge@…>, 15 years ago

refs #1347, hipertext widget extracted from Notebook App

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@3878 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 1.4 KB
Line 
1package require base64
2
3namespace eval mimetex {
4  variable cache
5  variable bin ""
6  variable defaultBin
7
8  array set cache {}
9
10  array set defaultBin {
11    Linux,4        linux32/mimetex
12    Windows\ NT,4  win32/mimetex.exe
13  }
14
15  proc SetBinPath { path } {
16    variable bin $path
17  }
18
19  proc RenderImage { latex { name "" } } {
20    variable cache
21    variable bin
22
23    puts "RenderImage $latex"
24    if { [ info exists cache($latex) ] } {
25      return $cache($latex)
26    }
27    if { [ file executable $bin ] } {
28      set p [open [list |$bin -d $latex] r]
29      fconfigure $p -translation binary -encoding binary
30      set rawData [base64::encode [read $p]]
31      close $p
32      if { $name eq "" } {
33        set cache($latex) [ image create photo -data $rawData ]
34      } else {
35        set cache($latex) [ image create photo $name -data $rawData ]
36      }
37      return $cache($latex)
38    } else {
39      error "could not execute mimetex, $bin is not executable"
40    }
41  }
42
43 
44  set os $::tcl_platform(os)
45  set wordSize $::tcl_platform(wordSize)
46  if { [ info exists defaultBin($os,$wordSize) ] } {
47    set _cwd [ file normalize [ file dir [ info script ] ] ]
48    SetBinPath [ file join $_cwd $defaultBin($os,$wordSize) ]
49  } else {
50    puts "There is no default mimetex.cgi for os = $os and wordSize = $wordSize. You should set it up with SetBinPath"
51  }
52}
53
54package provide mimetex 1.0
Note: See TracBrowser for help on using the repository browser.