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_settings_post($a)
25 if (!local_user() || empty($_POST['mathjax-submit'])) {
29 DI::pConfig()->set(local_user(), 'mathjax', 'use', intval($_POST['mathjax_use']));
32 function mathjax_settings(App $a, &$s)
38 $use = DI::pConfig()->get(local_user(), 'mathjax', 'use', false);
40 $tpl = Renderer::getMarkupTemplate('settings.tpl', 'addon/mathjax');
41 $s .= Renderer::replaceMacros($tpl, [
42 '$title' => 'MathJax',
43 '$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.'),
44 '$mathjax_use' => ['mathjax_use', DI::l10n()->t('Use the MathJax renderer'), $use, ''],
45 '$savesettings' => DI::l10n()->t('Save Settings'),
49 function mathjax_footer(App $a, &$b)
51 // if the visitor of the page is not a local_user, use MathJax
52 // otherwise check the users settings.
53 if (!local_user() || DI::pConfig()->get(local_user(), 'mathjax', 'use', false)) {
54 DI::page()->registerFooterScript(__DIR__ . '/asset/MathJax.js?config=TeX-MML-AM_CHTML');
55 DI::page()->registerFooterScript(__DIR__ . '/mathjax.js');