sobjornstad / TiddlyRemember

Embed Anki notes in your TiddlyWiki
https://sobjornstad.github.io/TiddlyRemember/
MIT License
66 stars 7 forks source link

MathJax for math formatting in Anki (plugin link in details) #26

Closed aggoi1234 closed 4 years ago

aggoi1234 commented 4 years ago

Hi,

I thought you'd be interested because I was also looking into MathJax and saw a recent reply of yours. This formatting isn't exactly an issue in TiddlyRemember but I'm not sure where else to put it. Simply installing the online version of the MathJax plugin into the empty wiki file (not on Node JS) worked because the formatting showed, although there was one internal Javascript error:

Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'.

I used a blank wiki file (not Node JS) and installed the plugin by dragging it in. I used another blank file without the MathJax plugin installed and it synced with Anki. Upon installing it and not using MathJax formatting, I got this error:


Anki 2.1.35 (84dcaa86) Python 3.8.0 Qt 5.14.2 PyQt 5.14.2 Platform: Windows 10 Flags: frz=True ao=True sv=1 Add-ons, last update check: 2020-10-10 21:45:18

Caught exception: Traceback (most recent call last): File "C:\Users\Aqua8\AppData\Roaming\Anki2\addons21\60456529\twimport.py", line 58, in _invoke_tw_command proc = subprocess.run(cmd, cwd=wiki_path, stdout=subprocess.PIPE, File "subprocess.py", line 512, in run subprocess.CalledProcessError: Command '['C:\Users\Aqua8\AppData\Roaming\npm\tiddlywiki.cmd', '--output', 'C:\Users\Aqua8\AppData\Local\Temp\tmpihl0183i\render', '--render', '[tag[Anki]]', '[encodeuricomponent[]addsuffix[.html]]', 'text/html', '$:/plugins/sobjornstad/TiddlyRemember/templates/TiddlyRememberParseable']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\Aqua8\AppData\Roaming\Anki2\addons21\60456529__init.py", line 142, in join_thread raise self.extract_thread.exception File "C:\Users\Aqua8\AppData\Roaming\Anki2\addons21\60456529\init__.py", line 60, in run self.notes = twimport.find_notes( File "C:\Users\Aqua8\AppData\Roaming\Anki2\addons21\60456529\twimport.py", line 188, in find_notes _render_wiki(tw_binary, wiki_folder, renderlocation, filter) File "C:\Users\Aqua8\AppData\Roaming\Anki2\addons21\60456529\twimport.py", line 145, in _render_wiki _invoke_tw_command(cmd, wiki_path, "render wiki") File "C:\Users\Aqua8\AppData\Roaming\Anki2\addons21\60456529\twimport.py", line 69, in _invoke_tw_command raise Exception(f"Failed to {description}: return code {proc.returncode}.\n" Exception: Failed to render wiki: return code 1. $ C:\Users\Aqua8\AppData\Roaming\npm\tiddlywiki.cmd --output C:\Users\Aqua8\AppData\Local\Temp\tmpihl0183i\render --render [tag[Anki]] [encodeuricomponent[]addsuffix[.html]] text/html $:/plugins/sobjornstad/TiddlyRemember/templates/TiddlyRememberParseable

Error executing boot module $:/plugins/kantorsite/mathjax/init.js: {}

$:/plugins/kantorsite/mathjax/init.js:1 (function(){function e(e,t,n){var r=document.getElementsByTagName('head')[0]||document.documentElement;var i=document.createElement('script');if(typeof e=='function'){i[window.opera?'innerHTML':'text']='('+e.toString()+')()'}else if(typeof e=='string'){i.src=e}if(t){for(var s in t){if(t.hasOwnProperty(s)){i[s]=t[s]}}}var o=false;i.onload=i.onreadystatechange=function(){if(!o&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){o=true;i.onload=i.onreadystatechange=null;if(r&&i.parentNode){r.removeChild(i)}if(typeof n=='function'){n()}}};r.insertBefore(i,r.firstChild);return i}e(function(){MathJax.Hub.Config({tex2jax:{inlineMath:[['$','$'],['\(','\)']]}})},{type:'text/x-mathjax-config'});e('http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML',null,function(){e(function(){var e=window.MutationObserver||window.WebKitMutationObserver;if(!e){alert('MathJax plugin for TW5: Sorry, but current version of your browser is not supported!')}else{var t=new e(function(e,t){MathJax.Hub.Queue(['Typeset',MathJax.Hub])});var n=document.getElementsByClassName('story-river')[0];t.observe(n,{subtree:false,attributes:true,childList:true})}})})})() ^

ReferenceError: document is not defined at e ($:/plugins/kantorsite/mathjax/init.js:1:37) at $:/plugins/kantorsite/mathjax/init.js:1:607 at $:/plugins/kantorsite/mathjax/init.js:1:1193 at Script.runInContext (vm.js:130:18) at Script.runInNewContext (vm.js:135:17) at Object.runInNewContext (vm.js:302:38) at Object.$tw.utils.evalSandboxed (C:\Users\Aqua8\AppData\Roaming\npm\node_modules\tiddlywiki\boot\boot.js:530:5) at Object.$tw.modules.execute (C:\Users\Aqua8\AppData\Roaming\npm\node_modules\tiddlywiki\boot\boot.js:806:15) at C:\Users\Aqua8\AppData\Roaming\npm\node_modules\tiddlywiki\boot\boot.js:846:30 at Object.$tw.utils.each (C:\Users\Aqua8\AppData\Roaming\npm\node_modules\tiddlywiki\boot\boot.js:135:12)


The latest snapshot from the Wayback Machine: https://web.archive.org/web/20200221224233/http://mathjax-tw5.kantorsite.net/

Also, I tried just leaving the filter as the default and there was still a sync error. Not sure if it was the same one though.

sobjornstad commented 4 years ago

Thanks! #9 contains most of the previous discussion of MathJax. My offer continues to be open that if anyone can point me to a plugin where MathJax works without throwing an error when they launch TiddlyWiki, I'll look at making any necessary tweaks to TiddlyWiki to make math notation a first-class citizen there.