Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline LaTeX usage #8256

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions components/ILIAS/Accordion/resources/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,7 @@ il.Accordion = {
rerenderContent: function(acc_el) {

// rerender mathjax
if (typeof MathJax != "undefined" && typeof MathJax.Hub != "undefined") {
MathJax.Hub.Queue(["Reprocess",MathJax.Hub, acc_el[0]]);
}
// see http://docs.mathjax.org/en/latest/typeset.html
il.Util.renderMathJax([acc_el[0]]);

// rerender google maps
if (typeof ilMapRerender != "undefined") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Class ilObjExternalToolsSettingsGUI
*
* @author Sascha Hofmann <[email protected]>
* @ilCtrl_Calls ilObjExternalToolsSettingsGUI: ilPermissionGUI, ilMathJaxSettingsGUI
* @ilCtrl_Calls ilObjExternalToolsSettingsGUI: ilPermissionGUI
*/
class ilObjExternalToolsSettingsGUI extends ilObjectGUI
{
Expand Down Expand Up @@ -51,7 +51,6 @@ public function __construct(

$lng->loadLanguageModule("delic");
$lng->loadLanguageModule("maps");
$lng->loadLanguageModule("mathjax");
$lng->loadLanguageModule("wopi");
}

Expand All @@ -70,7 +69,7 @@ protected function getTabs(): void
$this->tabs_gui->addTarget(
"settings",
$this->ctrl->getLinkTarget($this, "view"),
array("editMaps", "editMathJax", ""),
array("editMaps", ""),
"",
""
);
Expand Down Expand Up @@ -192,7 +191,6 @@ public function saveMapsObject(): void
public function initSubTabs(string $a_cmd): void
{
$maps = $a_cmd === 'editMaps';
$mathjax = $a_cmd === 'editMathJax';
$wopi = $a_cmd === self::EDIT_WOPI;

$this->tabs_gui->addSubTabTarget(
Expand All @@ -203,14 +201,6 @@ public function initSubTabs(string $a_cmd): void
"",
$maps
);
$this->tabs_gui->addSubTabTarget(
"mathjax_mathjax",
$this->ctrl->getLinkTargetByClass('ilMathJaxSettingsGUI'),
"",
"",
"",
$mathjax
);
$this->tabs_gui->addSubTabTarget(
"wopi_settings",
$this->ctrl->getLinkTargetByClass(ilWOPIAdministrationGUI::class),
Expand All @@ -232,12 +222,6 @@ public function executeCommand(): void
}

switch ($next_class) {
case 'ilmathjaxsettingsgui':
$this->tabs_gui->setTabActive('settings');
$this->initSubTabs("editMathJax");
$this->ctrl->forwardCommand(new ilMathJaxSettingsGUI());
break;

case 'ilecssettingsgui':
$this->tabs_gui->setTabActive('ecs_server_settings');
$this->ctrl->forwardCommand(new ilECSSettingsGUI());
Expand Down
32 changes: 26 additions & 6 deletions components/ILIAS/COPage/classes/class.ilCOPageHTMLExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*
*********************************************************************/

use ILIAS\UI\Implementation\Render\MathJaxConfig;
use ILIAS\UI\Implementation\Render\ilResourceRegistry;

/**
* HTML export class for pages
*
Expand Down Expand Up @@ -46,6 +49,7 @@ class ilCOPageHTMLExport
protected int $content_style_id = 0;
protected ilObjUser $user;
protected ilLogger $log;
protected MathJaxConfig $mathjax_config;
protected \ILIAS\GlobalScreen\Services $global_screen;
protected \ILIAS\Skill\Service\SkillTreeService $skill_tree_service;
protected \ILIAS\Skill\Service\SkillPersonalService $skill_personal_service;
Expand All @@ -61,6 +65,7 @@ public function __construct(

$this->log = ilLoggerFactory::getLogger('copg');
$this->user = $DIC->user();
$this->mathjax_config = $DIC[MathjaxConfig::class];
$this->global_screen = $DIC->globalScreen();
$this->skill_tree_service = $DIC->skills()->tree();
$this->skill_personal_service = $DIC->skills()->personal();
Expand Down Expand Up @@ -171,6 +176,13 @@ public function exportSupportScripts(): void
}
// mediaelement.js
ilPlayerUtil::copyPlayerFilesToTargetDirectory($this->flv_dir);

// MathJax (resources are files and directories in public folder)
if ($this->mathjax_config->isMathJaxEnabled()) {
foreach ($this->mathjax_config->getResourcesToExport() as $resource) {
$this->exportResourceFile($this->exp_dir, $resource);
}
}
}

protected function exportResourceFile(
Expand All @@ -180,7 +192,14 @@ protected function exportResourceFile(
if (is_int(strpos($file, "?"))) {
$file = substr($file, 0, strpos($file, "?"));
}
if (is_file($file)) {
if (is_dir($file)) {
$dir = dirname($file);
ilFileUtils::makeDirParents($target_dir . "/" . $dir);
ilFileUtils::rCopy(
$file,
$this->exp_dir . "/" . $file
);
} elseif (is_file($file)) {
$dir = dirname($file);
ilFileUtils::makeDirParents($target_dir . "/" . $dir);
if (!is_file($target_dir . "/" . $file)) {
Expand Down Expand Up @@ -210,13 +229,14 @@ public function getPreparedMainTemplate(
/* @todo check
$scripts = [];
$scripts = array_merge($scripts, ilPlayerUtil::getJsFilePaths());
*/

$mathJaxSetting = new ilSetting("MathJax");
$use_mathjax = $mathJaxSetting->get("enable");
if ($use_mathjax) {
$scripts[] = $mathJaxSetting->get("path_to_mathjax");
if ($this->mathjax_config->isMathJaxEnabled()) {
$registry = new ilResourceRegistry($tpl);
foreach ($this->mathjax_config->getResources() as $resource) {
$registry->register($resource);
}
}
*/

$tpl->addCss(\ilUtil::getStyleSheetLocation());
$tpl->addCss(ilObjStyleSheet::getContentStylePath($this->getContentStyleId()));
Expand Down
12 changes: 6 additions & 6 deletions components/ILIAS/COPage/classes/class.ilPageObjectGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use ILIAS\COPage\Editor\EditSessionRepository;
use ILIAS\COPage\Page\EditGUIRequest;
use ILIAS\UI\Implementation\Render\MathJaxConfig;

/**
* Class ilPageObjectGUI
Expand Down Expand Up @@ -1550,7 +1551,8 @@ public function showPage(): string
}
$output = str_replace("&amp;", "&", $output);

$output = ilMathJax::getInstance()->insertLatexImages($output);
// enable latex in the content
$output = $this->ui->renderer()->render($this->ui->factory()->legacy($output)->withLatexEnabled());

// insert page snippets
//$output = $this->insertContentIncludes($output);
Expand Down Expand Up @@ -1719,6 +1721,7 @@ public static function getTinyMenu(
$lng->loadLanguageModule("copg");
$ctrl = $DIC->ctrl();
$ui = $DIC->ui();
$mathjax_config = $DIC[MathjaxConfig::class];

$style_service = $DIC->contentStyle()->internal();
$style_access_manager = $style_service->domain()->access(
Expand Down Expand Up @@ -1961,15 +1964,12 @@ public static function getTinyMenu(
if ($a_keywords) {
$menu["cont_more_functions"][] = ["text" => $lng->txt("cont_keyword"), "action" => "selection.keyword", "data" => []];
}
$mathJaxSetting = new ilSetting("MathJax");
if (ilPageEditorSettings::lookupSettingByParentType(
if ($mathjax_config->isMathJaxEnabled() && ilPageEditorSettings::lookupSettingByParentType(
$a_par_type,
"active_tex",
true
)) {
if ($mathJaxSetting->get("enable") || defined("URL_TO_LATEX")) {
$menu["cont_more_functions"][] = ["text" => 'Tex', "action" => "selection.tex", "data" => []];
}
$menu["cont_more_functions"][] = ["text" => 'Tex', "action" => "selection.tex", "data" => []];
}
if (ilPageEditorSettings::lookupSettingByParentType(
$a_par_type,
Expand Down
25 changes: 10 additions & 15 deletions components/ILIAS/COPage/templates/default/tpl.question_export.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
jQuery('div#container{VAL_ID}').autoRender(questions[{VAL_ID}]);
{HANDLE_IMAGES}

if (typeof MathJax != "undefined" && typeof MathJax.Hub != "undefined") {
MathJax.Hub.Queue(["Typeset",MathJax.Hub, "container{VAL_ID}"]);
}
const el = document.getElementById("container{VAL_ID}");
il.Util.renderMathJax([el]);
}
</script>
<!-- END singlechoice -->
Expand Down Expand Up @@ -54,9 +53,8 @@

question.init();

if (typeof MathJax != "undefined" && typeof MathJax.Hub != "undefined") {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, "container{VAL_ID}"]);
}
const el = document.getElementById("container{VAL_ID}");
il.Util.renderMathJax([el]);
};
</script>
<!-- END multiplechoice -->
Expand Down Expand Up @@ -107,9 +105,8 @@

{HANDLE_IMAGES}

if (typeof MathJax != "undefined") {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, "container{VAL_ID}"]);
}
const el = document.getElementById("container{VAL_ID}");
il.Util.renderMathJax([el]);

})(questions[{VAL_ID}]);
};
Expand All @@ -130,9 +127,8 @@
jQuery('div#container{VAL_ID}').autoRender(questions[{VAL_ID}]);
{HANDLE_IMAGES}
jQuery("#order{VAL_ID}").sortable({axis: 'y', containment: '#container{VAL_ID}'});
if (typeof MathJax != "undefined") {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, "container{VAL_ID}"]);
}
const el = document.getElementById("container{VAL_ID}");
il.Util.renderMathJax([el]);
}
</script>
<!-- END orderingquestion -->
Expand Down Expand Up @@ -303,9 +299,8 @@

questionData.engineInstance = question;

if (typeof MathJax != "undefined" && typeof MathJax.Hub != "undefined") {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, "container{VAL_ID}"]);
}
const el = document.getElementById("container{VAL_ID}");
il.Util.renderMathJax([el]);
}
);

Expand Down
2 changes: 0 additions & 2 deletions components/ILIAS/Export/HTML/class.Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public function exportSystemStyle(): void
*/
public function exportCOPageFiles(int $style_sheet_id = 0, string $obj_type = ""): void
{
\ilMathJax::getInstance()->init(\ilMathJax::PURPOSE_EXPORT);

// init co page html exporter
$this->co_page_html_export->setContentStyleId($style_sheet_id);
$this->co_page_html_export->createDirectories();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

declare(strict_types=1);

use ILIAS\UI\Implementation\Render\MathJaxConfig;

class ilForumThreadFormGUI extends ilPropertyFormGUI
{
public const ALIAS_INPUT = 'alias';
Expand All @@ -33,12 +35,14 @@ class ilForumThreadFormGUI extends ilPropertyFormGUI
public function __construct(
private readonly ilObjForumGUI $delegatingGui,
private readonly ilForumProperties $properties,
private readonly MathjaxConfig $mathjax_config,
private readonly bool $allowPseudonyms,
private readonly bool $allowNotification,
private readonly bool $isDraftContext,
private readonly int $draftId
) {
parent::__construct();
$this->lng->loadLanguageModule('ui');
}

private function addAliasInput(): void
Expand Down Expand Up @@ -71,9 +75,6 @@ private function addMessageInput(): void
$message->setRows(15);
$message->setRequired(true);
$message->setUseRte(true);
$message->addPlugin('latex');
$message->addButton('latex');
$message->addButton('pastelatex');
$message->addPlugin('ilfrmquote');
$message->usePurifier(true);
$message->setRTERootBlockElement('');
Expand All @@ -95,6 +96,9 @@ private function addMessageInput(): void
'formatselect'
]);
$message->setPurifier(ilHtmlPurifierFactory::getInstanceByType('frm_post'));
if ($this->mathjax_config->isMathJaxEnabled()) {
$message->setInfo($this->lng->txt('mathjax_edit_hint'));
}
$this->addItem($message);
}

Expand Down
8 changes: 6 additions & 2 deletions components/ILIAS/Forum/classes/class.ilForum.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class ilForum
public ilDBInterface $db;
public ilObjUser $user;
public ilSetting $settings;
private ILIAS\UI\Factory $ui_factory;
private ILIAS\UI\Renderer $ui_renderer;

public function __construct()
{
Expand All @@ -65,6 +67,8 @@ public function __construct()
$this->user = $DIC->user();
$this->settings = $DIC->settings();
$this->event = $DIC->event();
$this->ui_factory = $DIC->ui()->factory();
$this->ui_renderer = $DIC->ui()->renderer();
}

public function setForumId(int $a_obj_id): void
Expand Down Expand Up @@ -1484,8 +1488,8 @@ public function prepareText(string $text, int $edit = 0, string $quote_user = ''

if ($type !== 'export') {
if ($edit === 0) {
$text = ilMathJax::getInstance()->insertLatexImages($text, "\<span class\=\"latex\">", "\<\/span>");
$text = ilMathJax::getInstance()->insertLatexImages($text, "\[tex\]", "\[\/tex\]");
$text = ilRTE::replaceLatexSpan($text);
$text = $this->ui_renderer->render($this->ui_factory->legacy($text)->withLatexEnabled());
}

// workaround for preventing template engine
Expand Down
Loading
Loading