## Maths in Dokeos with Latex (needs a plugin)

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 $$and end it with$$

example: Wave equation of sound in matter

$${\frac{\displaystyle {\partial }^{{2}}\chi }{\partial \ {x}^{{2}}}= \frac{\displaystyle 1}{{c}_{s}^{{2}}}\ \frac{\displaystyle {\partial }^{{2}}\chi }{\partial \ {t}^{{2}}}}$$


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)

## 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("$$","<EMBED TYPE='application/x-techexplorer' TEXDATA='",textext); textext=str_replace("$$","' 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;
}


# Remarks

1. 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).
2. 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.

# Installing MimeTex in Dokeos 2.1

The activation of the MimeTex plugin in Dokeos 2.1is currently described in the Dokeos 2.1 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)

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',
] ;


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

 ln -s /var/www/dokeos/main/inc/lib/mimetex/mimetex.cgi /var/www/cgi-bin/mimetex.cgi