Math
From Dokeos
Contents |
Current situation
Dokeos 1.8.5 offers a Math equations editor using the MimeTex application and FCKEditor plugin. To enable it, please refer to the Dokeos 1.8.5 installation guide (inside your Dokeos package) or have a look at the "Installing MimeTex in Dokeos 1.8.5" at the bottom of this page.
A wel hidden feature of the Dokeos system is the possibility to use LaTeX code throughout Dokeos. Almost every text field can hold LaTeX code which is then parsed and translated to something that can be read by the free TechExplorer plugin (a plugin displays raw LaTeX code into mathematical formulas inside your browser). The end user needs (unfortunately) to install the free TechExplorer plugin to be able to see these mathematical formulas.
How use it? Using it is fairly simple. You just have to start your LaTeX Code with [tex] and end it with [/tex]
example: Wave equation of sound in matter
[tex]
{\frac{\displaystyle {\partial }^{{2}}\chi }{\partial \ {x}^{{2}}}=
\frac{\displaystyle 1}{{c}_{s}^{{2}}}\ \frac{\displaystyle {\partial }^{{2}}\chi }{\partial \ {t}^{{2}}}}
[/tex]
As it is now we only have one api function that is treating this LaTeX code: api_parse_tex (in lib/main_api.lib.php)
Improvement
the improvement would consist in a LaTeX renderer so that LaTeX code can be converted to gif images by the server. The main advantage is that the TechExplorer plugin would no longer be required (although advised for everyone that uses math symbols frequently). The techexplorer plugin delivers cleaner output. an example:To create the gif images of the LaTeX code we can use mimeTex (which is used by several other E-learning tools). There are some remarks to be made here. (see next points)
Javascript to check whether the TechExplorer plugin is installed or not
we should use a javascript check to check whether the end user has the TechExplorer plugin installed or not. The reason to do so is that TechExplorer returns much prettier mathematical symbols than the mimeTex solutions (especially when printing). The javascript needed for this can be found on http://www.integretechpub.com/docs/techexplorer/Help/Scripting/GettingStarted.html (section: Determining if techexplorer has been installed) This function api_parse_tex (in lib/main_api.lib.php) would then look something like this
function api_parse_tex($textext)
{
$techexplorer_installed=api_do_techexplorer_check() // api_do_techexplorer_check() returns true if the plugin is installed
if ($techexplorer_installed)
{
$textext=str_replace("[tex]","<EMBED TYPE='application/x-techexplorer' TEXDATA='",$textext);
$textext=str_replace("[/tex]","' width='200' height='50'>",$textext);
}
else
{
$textext=api_create_image_from_tex($textext);
// api_create_image_from_tex uses the mimTex tool to create the image, store it somewhere and return a normal html image tag
// see an overview of this function below
}
}
Image output caching
The images should not be created on the fly each time an end user requests a certain page that contains LaTeX code. This would produce much overhead for the server. The best way to solve this is to create the gif upon submission of the LaTex Code (when the course manager stores the LaTeX code), to save the gif somewhere inside the course (in a special folder inside the documents tool or in a cache folder on the same level as the documents folder) and to store a link between the source LaTex code and the image somewhere in a cache table (in the course database). The cache table would require two fields: the source LaTex in one field and the path to the image in the next field. The best place to do this check is inside the api_create_image_from_tex($textext) function. This function would look something like this
function api_create_image_from_tex($textext)
{
// step 1: we check if there is already a cached image for this LaTex code
$sql="SELECT * FROM coursecache WHERE sourcecode='$textext'";
$result=api_sql_query($sql)
if (mysql_num_rows($result)==0)
{
// there is NO cache image yet, so we create it
// the code to call mimeTex goes here
// and also the code that saves the gif to the cache folder
// and also the code that saves and entry in the coursecache table
}
else
{
// there is already a cached image so we find this
$row=mysql_fetch_array($result);
$image="<img src=\"".$row['rendered_image']."\">";
}
return $image;
}
Status
I have currently a very basic version running (without the javascript check, but I added a (temporary) profile setting on my development server where you can choose between TechExplorer or gif-rendering of math) that generates the gifs and stores them in a cache table. The gif is generated upon submission of the tex code by the course manager. When a student has a look at the page it will not generate a gif but it will retrieve a reference to the gif in the database and replace the math code with the gif that was generated before.
The dokeos campus has recently added a button to the htmlarea to add LaTeX code to your browser. It's a great idea to have a button there to add LaTeX so the current development was changed a little bit to continue this development. Below you can see an illustration of how everything works.
Remarks
- Where do we store the generated images? My first idea was to create a folder inside the documents tool, but maybe it is better to have a cache folder next to the document folder (at the same level). If we store them inside the documents the files might be re-used, but there is also the risk that they get deleted. The problem with deletion of the gifs is that the entry in the cache table is not deleted so the system assumes there is a cached gif. A solution would be to add an aditional check that would re-create the gif if the file does no longer exist. This is not really a problem but it is a decision to be made (which will add some additional lines of code).
- For the moment the javascript that checks if the TechExplorer plugin is installed is not yet implemented. I did foresee however the possibility to switch between the TechExplorer and the Gif Rendering method by adding an option to the 'my profile page'. By doing so you can check both possibilities (the TechExplorer option needs the TechExplorer plugin of course). This profile option will of course not be available in the final development of this feature.
Test
you can test it freely on my testserver: http://157.193.57.110/dokeos (login: test, password: test). As an example some LaTeX codes (but feel free to use different ones for testing purposes)
- $s=\sqrt{\displaystyle \frac{\displaystyle 1}{\displaystyle n}\ cdot {\sum}_{i=1}^{p}{{n}_{{i}}({x}_{{i}}-\bar{x} {)}^{{2}}}}$
- ${s}^{{2}}=\displaystyle \frac{\displaystyle 1}{\displaystyle n}\cdot {\sum }_{i=1}^{p}{{n}_{{i}}({x}_{{i}}-\bar{x} {)}^{{2}}}$
- \sqrt[n]{r}\cdot (\cos \displaystyle \frac{\displaystyle \theta +k\cdot {360}^{{\circ }}}{\displaystyle n}+i\,\sin \displaystyle \frac{\displaystyle \theta +k\cdot {360}^{{\circ }}}{\displaystyle n})\>\mbox{met} \>k\in \mbox{ $Z}
- co (\vec{V} )=({x}_{{1}},{y}_{{1}})
Installing MimeTex in Dokeos 1.8.5
The activation of the MimeTex plugin in Dokeos 1.8.5 is currently described in the Dokeos 1.8.5 installation guide shipped in the documentation/ directory of your Dokeos package. Here is the same documentation, feel free to update it to add more detailed information
You can enable mathematical equations writing inside the Dokeos online editor (FCKEditor) by applying the following steps:
1. Configure your Apache installation to add a cgi-bin directory that contains a symbolic link to the mimetex.cgi in dokeos/main/inc/lib/mimetex/(*see below)
2. Reload your Apache configuration
3. Edit the dokeos/main/inc/lib/fckeditor/myconfig.js and
3.1. Add FCKConfig.Plugins.Add("mimetex", "en", sOtherPluginPath ) ; at the end of the file
3.2. Add 'mimetex' at the end of the FCKConfig.ToolbarSets lines where you want the LaTeX icon to appear (there is one FCKConfig.ToolbarSets by tool). For example:
FCKConfig.ToolbarSets["Test"] = [
['Bold','Italic','Underline','StrikeThrough','Subscript','Superscript','Link','ImageManager','MP3','OrderedList','UnorderedList','Table','mimetex']
] ;
You can add it to all the tools, or only to the document and tests tools, for example
4. For Windows servers only, update dokeos/main/inc/lib/fckeditor/editor/plugins/mimetex/mimetex.html to replace mimetex.cgi by mimetex.exe
5. Clear your browser's cache to test it (very important). This can be done using your browser's settings page
Adding the corresponding cgi-bin directory to your Apache configuration could be done, in Apache 2, like this:
ScriptAlias /cgi-bin/ /var/www/cgi-bin/ <Directory "/var/www/cgi-bin"> AllowOverride None Options ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory>
Adding a symbolic link can be done, under Windows, by creating a shortcut to the mimetex.exe file from the cgi-bin directory, or under Linux by issuing the following command:
ln -s /var/www/dokeos/main/inc/lib/mimetex/mimetex.cgi /var/www/cgi-bin/mimetex.cgi
This procedure should make a new icon available in your Dokeos online editor, which will make it possible to insert mathematical formulas into your documents.
Discuss
There is a forum thread on this development: http://www.dokeos.com/forum/viewtopic.php?t=2924 . Feel free to post your remarks and questions there.

