fsavje / math-with-slack

Rendered math (MathJax) with Slack's desktop client
MIT License
431 stars 62 forks source link

Add an optional set of macros to the installation? #22

Closed dgleich closed 6 years ago

dgleich commented 6 years ago

Our slack group has a widely used set of macros we use to typeset equations. I imagine we can just hack the current script to insert these in, but it'd be really cool if the script could take another option -- given as a file name -- that would inject those macros for us.

e.g.

sudo bash math_with_slack.sh --preamble=ourmacros.tex

We may end up doing this, so there could be a follow-up pull request.

fsavje commented 6 years ago

That's a good idea and it should definitely be possible. I don't know exactly what you have in mind, but you can take a look at hwagyesa's fork for inspiration. (All macros are hardcoded there, however.)

Please let me know if you code this up. A pull request would be very welcomed.

sdbuch commented 6 years ago

This would be a nice solution, but one obstacle we encountered when trying to implement something similar with our own set of macros was the inherent difference between MathJax commands and regular .tex commands. In our case, most of the macros we were using for compiling with a local .tex distribution had to be changed to work with MathJax / math-with-slack.

There is a list of supported commands here: http://docs.mathjax.org/en/latest/tex.html#supported-latex-commands. It seems like it would be challenging to write a script to translate an arbitrary .tex preamble into a compatible set of MathJax macros. But if you're happy with writing the macros in MathJax-compatible TeX, you could certainly have them saved in a separate text file, and it probably wouldn't be too challenging to modify the math-with-slack script to read this text file and inject it, too, since after all math-with-slack is just injecting a large string into the Slack code somewhere.

For us it has been enough to have the macros hardcoded since there is an intrinsic difficulty due to users with different macros configured being unable to view the macros they do not have installed... but I can forsee your idea being very useful in an environment where the list of macros is prone to updates, and these updates need to be pushed uniformly to many users without too much trouble.

dgleich commented 6 years ago

I agree you'd need MathJax compatible macros. I also see that it could be difficult to add macros in the future, that's a good point that makes this trickier than I expected. I'm not an expert on some of the cross-site Javascript loading. But would it be possible to insert a load command to a web-page with macros instead?

fsavje commented 6 years ago

@dgleich Do you mean that a group could have a public website with all the macros? That might work. You would need to change the injector code to load a website rather than a file. This will, however, not be implemented in math-with-slack due to the risk of exploits.