4 * Description: Addon for Friendica to include MathJax (LaTeX math syntax)
6 * Author: Tobias Diekershoff <https://social.diekershoff.de/profile/tobias>
7 * Author: Hypolite Petovan <https://friendica.mrpetovan.com/profile/hypolite>
8 * License: 3-clause BSD license
12 use Friendica\Core\Hook;
13 use Friendica\Core\Renderer;
16 function mathjax_install()
18 Hook::register('footer' , __FILE__, 'mathjax_footer');
19 Hook::register('addon_settings' , __FILE__, 'mathjax_settings');
20 Hook::register('addon_settings_post', __FILE__, 'mathjax_settings_post');
23 function mathjax_uninstall()
25 Hook::unregister('footer' , __FILE__, 'mathjax_footer');
26 Hook::unregister('addon_settings' , __FILE__, 'mathjax_settings');
27 Hook::unregister('addon_settings_post', __FILE__, 'mathjax_settings_post');
30 Hook::unregister('load_config' , __FILE__, 'mathjax_load_config');
31 Hook::unregister('page_header' , __FILE__, 'mathjax_page_header');
32 Hook::unregister('template_vars' , __FILE__, 'mathjax_template_vars');
35 function mathjax_settings_post($a)
37 if (!local_user() || empty($_POST['mathjax-submit'])) {
41 DI::pConfig()->set(local_user(), 'mathjax', 'use', intval($_POST['mathjax_use']));
44 function mathjax_settings(App $a, &$s)
50 $use = DI::pConfig()->get(local_user(), 'mathjax', 'use', false);
52 $tpl = Renderer::getMarkupTemplate('settings.tpl', __DIR__);
53 $s .= Renderer::replaceMacros($tpl, [
54 '$title' => 'MathJax',
55 '$description' => DI::l10n()->t('The MathJax addon renders mathematical formulae written using the LaTeX syntax surrounded by the usual $$ or an eqnarray block in the postings of your wall,network tab and private mail.'),
56 '$mathjax_use' => ['mathjax_use', DI::l10n()->t('Use the MathJax renderer'), $use, ''],
57 '$savesettings' => DI::l10n()->t('Save Settings'),
61 function mathjax_footer(App $a, &$b)
63 // if the visitor of the page is not a local_user, use MathJax
64 // otherwise check the users settings.
65 if (!local_user() || DI::pConfig()->get(local_user(), 'mathjax', 'use', false)) {
66 DI::page()->registerFooterScript(__DIR__ . '/asset/MathJax.js?config=TeX-MML-AM_CHTML');
67 DI::page()->registerFooterScript(__DIR__ . '/mathjax.js');