forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-43855 Atto: Add an equation editor
This equation editor relies on whatever the currently configured filter is to do the rendering. If there is no filter that handles latex ($$ blah $$) - this plugin will not show up. This will not work with the solutions on the forums of adding MathJax in the header of the page, but it will work with a real mathjax filter written for Moodle (work in progress). It works with the existing tex filter.
- Loading branch information
Damyon Wiese
committed
Mar 26, 2014
1 parent
05843fd
commit 8bf5ad6
Showing
15 changed files
with
1,494 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Renders text with the active filters and returns it. Used to create previews of equations | ||
* using whatever tex filters are enabled. | ||
* | ||
* @package atto_equation | ||
* @copyright 2014 Damyon Wiese | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
define('AJAX_SCRIPT', true); | ||
|
||
require_once(dirname(__FILE__) . '/../../../../../config.php'); | ||
|
||
$contextid = required_param('contextid', PARAM_INT); | ||
$context = context::instance_by_id($contextid, MUST_EXIST); | ||
$PAGE->set_url('/lib/editor/atto/plugins/equation/ajax.php'); | ||
$PAGE->set_context($context); | ||
|
||
require_login(); | ||
require_sesskey(); | ||
|
||
$action = required_param('action', PARAM_ALPHA); | ||
|
||
if ($action === 'filtertext') { | ||
$text = required_param('text', PARAM_RAW); | ||
|
||
$result = filter_manager::instance()->filter_text($text, $context); | ||
echo $OUTPUT->header(); | ||
echo $result; | ||
|
||
die(); | ||
} | ||
|
||
print_error('invalidarguments'); |
39 changes: 39 additions & 0 deletions
39
lib/editor/atto/plugins/equation/lang/en/atto_equation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Strings for component 'atto_equation', language 'en'. | ||
* | ||
* @package atto_equation | ||
* @copyright 2013 Damyon Wiese <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
$string['editequation'] = 'Edit equation'; | ||
$string['editequation_desc'] = 'Equations are written in <a target="_blank" href="http://en.wikibooks.org/wiki/TeX" title="Link to wikipedia">TeX.</a>'; | ||
$string['librarygroup1'] = 'Operators'; | ||
$string['librarygroup1_desc'] = 'List of tex commands to list on the operators tab.'; | ||
$string['librarygroup2'] = 'Arrows'; | ||
$string['librarygroup2_desc'] = 'List of tex commands to list on the arrows tab.'; | ||
$string['librarygroup3'] = 'Greek Symbols'; | ||
$string['librarygroup3_desc'] = 'List of tex commands to list on the greek symbols tab.'; | ||
$string['librarygroup4'] = 'Advanced'; | ||
$string['librarygroup4_desc'] = 'List of tex commands to list on the advanced tab.'; | ||
$string['pluginname'] = 'Equation editor'; | ||
$string['preview'] = 'Equation preview (cursor position is indicated with a box)'; | ||
$string['saveequation'] = 'Save equation'; | ||
$string['settings'] = 'Equation editor settings'; | ||
$string['update'] = 'Update'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Atto text editor integration version file. | ||
* | ||
* @package atto_equation | ||
* @copyright 2013 Damyon Wiese <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Get the list of strings for this plugin. | ||
* @param string $elementid | ||
*/ | ||
function atto_equation_strings_for_js() { | ||
global $PAGE; | ||
|
||
$PAGE->requires->strings_for_js(array('saveequation', | ||
'editequation', | ||
'preview', | ||
'editequation_desc', | ||
'update', | ||
'librarygroup1', | ||
'librarygroup2', | ||
'librarygroup3', | ||
'librarygroup4'), | ||
'atto_equation'); | ||
} | ||
|
||
/** | ||
* Set params for this plugin. | ||
* | ||
* @param string $elementid | ||
* @param stdClass $options - the options for the editor, including the context. | ||
* @param stdClass $fpoptions - unused. | ||
*/ | ||
function atto_equation_params_for_js($elementid, $options, $fpoptions) { | ||
$texexample = '$$\pi$$'; | ||
|
||
// Format a string with the active filter set. | ||
// If it is modified - we assume that some sort of text filter is working in this context. | ||
$result = format_text($texexample, true, $options); | ||
|
||
$texfilteractive = ($texexample !== $result); | ||
$context = $options['context']; | ||
if (!$context) { | ||
$context = context_system::instance(); | ||
} | ||
|
||
// Tex example librarys. | ||
$library = array('group1' => get_config('atto_equation', 'librarygroup1'), | ||
'group2' => get_config('atto_equation', 'librarygroup2'), | ||
'group3' => get_config('atto_equation', 'librarygroup3'), | ||
'group4' => get_config('atto_equation', 'librarygroup4')); | ||
|
||
return array('texfilteractive' => $texfilteractive, 'contextid'=>$context->id, 'library'=>$library); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Settings that allow configuration of the list of tex examples in the equation editor. | ||
* | ||
* @package atto_equation | ||
* @copyright 2013 Damyon Wiese | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
$ADMIN->add('editoratto', new admin_category('atto_equation', new lang_string('pluginname', 'atto_equation'))); | ||
|
||
$settings = new admin_settingpage('atto_equation_settings', new lang_string('settings', 'atto_equation')); | ||
if ($ADMIN->fulltree) { | ||
// Group 1 | ||
$name = new lang_string('librarygroup1', 'atto_equation'); | ||
$desc = new lang_string('librarygroup1_desc', 'atto_equation'); | ||
$default = ' | ||
\cdot | ||
\times | ||
\ast | ||
\div | ||
\diamond | ||
\pm | ||
\mp | ||
\oplus | ||
\ominus | ||
\otimes | ||
\oslash | ||
\odot | ||
\circ | ||
\bullet | ||
\asymp | ||
\equiv | ||
\subseteq | ||
\supseteq | ||
\leq | ||
\geq | ||
\preceq | ||
\succeq | ||
\sim | ||
\simeq | ||
\approx | ||
\subset | ||
\supset | ||
\ll | ||
\gg | ||
\prec | ||
\succ | ||
\infty | ||
\in | ||
\ni | ||
\forall | ||
\exists | ||
\neq | ||
'; | ||
$setting = new admin_setting_configtextarea('atto_equation/librarygroup1', | ||
$name, | ||
$desc, | ||
$default); | ||
$settings->add($setting); | ||
|
||
// Group 2 | ||
$name = new lang_string('librarygroup2', 'atto_equation'); | ||
$desc = new lang_string('librarygroup2_desc', 'atto_equation'); | ||
$default = ' | ||
\leftarrow | ||
\rightarrow | ||
\uparrow | ||
\downarrow | ||
\leftrightarrow | ||
\nearrow | ||
\searrow | ||
\swarrow | ||
\nwarrow | ||
\Leftarrow | ||
\Rightarrow | ||
\Uparrow | ||
\Downarrow | ||
\Leftrightarrow | ||
'; | ||
$setting = new admin_setting_configtextarea('atto_equation/librarygroup2', | ||
$name, | ||
$desc, | ||
$default); | ||
$settings->add($setting); | ||
|
||
// Group 3 | ||
$name = new lang_string('librarygroup3', 'atto_equation'); | ||
$desc = new lang_string('librarygroup3_desc', 'atto_equation'); | ||
$default = ' | ||
\alpha | ||
\beta | ||
\gamma | ||
\delta | ||
\epsilon | ||
\zeta | ||
\eta | ||
\theta | ||
\iota | ||
\kappa | ||
\lambda | ||
\mu | ||
\nu | ||
\xi | ||
\pi | ||
\rho | ||
\sigma | ||
\tau | ||
\upsilon | ||
\phi | ||
\chi | ||
\psi | ||
\omega | ||
\Gamma | ||
\Delta | ||
\Theta | ||
\Lambda | ||
\Xi | ||
\Pi | ||
\Sigma | ||
\Upsilon | ||
\Phi | ||
\Psi | ||
\Omega | ||
'; | ||
$setting = new admin_setting_configtextarea('atto_equation/librarygroup3', | ||
$name, | ||
$desc, | ||
$default); | ||
$settings->add($setting); | ||
|
||
// Group 4 | ||
$name = new lang_string('librarygroup4', 'atto_equation'); | ||
$desc = new lang_string('librarygroup4_desc', 'atto_equation'); | ||
$default = ' | ||
\sum{a,b} | ||
\int_{a}^{b}{c} | ||
\iint_{a}^{b}{c} | ||
\iiint_{a}^{b}{c} | ||
\oint{a} | ||
(a) | ||
[a] | ||
\lbrace{a}\rbrace | ||
\left| \begin{matrix} a_1 & a_2 \\ a_3 & a_4 \end{matrix} \right| | ||
'; | ||
$setting = new admin_setting_configtextarea('atto_equation/librarygroup4', | ||
$name, | ||
$desc, | ||
$default); | ||
$settings->add($setting); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#atto_equation_library .yui3-tabview-list { | ||
border: none; | ||
} | ||
|
||
#atto_equation_library .yui3-tab-selected .yui3-tab-label, .yui3-skin-sam #atto_equation_library .yui3-tab-selected .yui3-tab-label:focus, .yui3-skin-sam #atto_equation_library .yui3-tab-selected .yui3-tab-label:hover { | ||
background: none; | ||
color: black; | ||
border-top-left-radius: 4px; | ||
border-top-right-radius: 4px; | ||
} | ||
|
||
#atto_equation_library button { | ||
margin: 4px; | ||
} | ||
|
||
#page-admin-setting-atto_equation_settings .form-defaultinfo { | ||
max-height: 10em; | ||
overflow: auto; | ||
padding: 5px; | ||
min-width: 206px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Atto text editor integration version file. | ||
* | ||
* @package atto_equation | ||
* @copyright 2013 Damyon Wiese <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
$plugin->version = 2014012800; // The current plugin version (Date: YYYYMMDDXX). | ||
$plugin->requires = 2013110500; // Requires this Moodle version. | ||
$plugin->component = 'atto_equation'; // Full name of the plugin (used for diagnostics). |
Oops, something went wrong.