From d7ebfdb85cf73c027fb928518004533e428f3893 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 4 Mar 2021 15:29:27 -0300 Subject: Feat: MathJax setup --- lib/IkiWiki/Plugin/mathjax.pm | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 lib/IkiWiki/Plugin/mathjax.pm (limited to 'lib') diff --git a/lib/IkiWiki/Plugin/mathjax.pm b/lib/IkiWiki/Plugin/mathjax.pm new file mode 100755 index 0000000..99b74c3 --- /dev/null +++ b/lib/IkiWiki/Plugin/mathjax.pm @@ -0,0 +1,74 @@ +package IkiWiki::Plugin::mathjax; + +use warnings; +use strict; +use IkiWiki 3.00; +use MIME::Base64; + +# Strategy: +## - filter replaces normal TeX delimiters with imath and dmath directives +## (perhaps while considering a mathconf directive); also, it adds a script +## block if there is any math on the page relevant. +## - preprocess handles the directives themselves. +## +## Later: config hooks for mathjax script tag and mathjax config block +## + +sub import { + hook(type => "filter", id => "mathjax", call => \&filter); + hook(type => "format", id=>"mathjax", call=> \&format); +} + +sub format { + my %params = @_; + my $content = $params{content}; + return $content unless $content =~ /\!\!mathjaxbegin/; #]/{{ + $content =~ s{\!\!mathjaxbegin-i!! (.*?)\s\!\!mathjaxend-i\!\!}{'\('.decode_base64($1).'\)'}ges; #{ + $content =~ s{\!\!mathjaxbegin-d!! (.*?)\s\!\!mathjaxend-d\!\!}{'\['.decode_base64($1).'\]'}ges; #{ + my $scripttag = _scripttag(); + $content =~ s{()}{$scripttag\n$1}i; #}{ + return $content; +} + +sub filter (@) { + my %params=@_; + my $content = $params{content}; + return $content unless $content =~ /\$[^\$]+\$|\\[\(\[][\s\S]+\\[\)\]]/; + # first, handle display math... + $content =~ s{(?/>/g; #{" + $directive .= encode_base64($formula, " "); + $directive .= "!!mathjaxend-$mode!!"; + return $directive; +} + +sub _scripttag { + my $config = 'TeX-AMS_HTML'; # another possibility: TeX-AMS-MML_HTMLorMML + return '' + . ''; +} + +1; -- cgit v1.2.3