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\L10n;
14 use Friendica\Core\PConfig;
15 use Friendica\Core\Renderer;
17 function mathjax_install()
19 Hook::register('footer' , __FILE__, 'mathjax_footer');
20 Hook::register('addon_settings' , __FILE__, 'mathjax_settings');
21 Hook::register('addon_settings_post', __FILE__, 'mathjax_settings_post');
24 function mathjax_uninstall()
26 Hook::unregister('footer' , __FILE__, 'mathjax_footer');
27 Hook::unregister('addon_settings' , __FILE__, 'mathjax_settings');
28 Hook::unregister('addon_settings_post', __FILE__, 'mathjax_settings_post');
31 Hook::unregister('load_config' , __FILE__, 'mathjax_load_config');
32 Hook::unregister('page_header' , __FILE__, 'mathjax_page_header');
33 Hook::unregister('template_vars' , __FILE__, 'mathjax_template_vars');
36 function mathjax_settings_post($a)
38 if (!local_user() || empty($_POST['mathjax-submit'])) {
42 PConfig::set(local_user(), 'mathjax', 'use', intval($_POST['mathjax_use']));
45 function mathjax_settings(App $a, &$s)
51 $use = PConfig::get(local_user(), 'mathjax', 'use', false);
53 $tpl = Renderer::getMarkupTemplate('settings.tpl', __DIR__);
54 $s .= Renderer::replaceMacros($tpl, [
55 '$title' => 'MathJax',
56 '$description' => 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.'),
57 '$mathjax_use' => ['mathjax_use', L10n::t('Use the MathJax renderer'), $use, ''],
58 '$savesettings' => L10n::t('Save Settings'),
62 function mathjax_footer(App $a, &$b)
64 // if the visitor of the page is not a local_user, use MathJax
65 // otherwise check the users settings.
66 if (!local_user() || PConfig::get(local_user(), 'mathjax', 'use', false)) {
67 $a->registerFooterScript(__DIR__ . '/asset/MathJax.js?config=TeX-MML-AM_CHTML');
68 $a->registerFooterScript(__DIR__ . '/mathjax.js');