Automattic / sensei

Sensei LMS - Online Courses, Quizzes, & Learning
https://senseilms.com
GNU General Public License v2.0
543 stars 197 forks source link

Add filters for LaTeX support #659

Closed danjjohnson closed 9 years ago

danjjohnson commented 9 years ago

There's a filter on multiple-choice questions called 'sensei_answer_text' which we used to trigger the JetPack function (using " add_filter( 'sensei_answer_text', 'latex_markup' ); "). Looking back it does seem as that will won't cover question titles, nor gap fill fields (thinking before and after only), nor even the helptext on file upload questions. Adding filters to those and then adding a couple of add_filters like we did will then allow support for JetPack LaTeX. As for JS based LaTeX that should run regardless I would have thought.

danjjohnson commented 9 years ago

@davidpagepsycle was there a reason you didn't include those fields? Do you think it's worth adding support for them?

davecpage commented 9 years ago

It was more because of how the client was using the system. LaTeX wasn't being added to question titles, instead it was getting added to the (optional) question description, which has 'the_content' filters applied so it was covered. Multiple choice seemed to be the only time they use LaTeX, it had never been used on the gap fill questions. Those are used instead as text based answers. And there has never been a use of the file upload type so far.

The JetPack module adds it's function "latex_markup" to the filters "the_content" and "comment_text". You could apply one of those to Sensei questions/answers to ensure LaTeX support, but that could cause knock-on effects. Thus my creation of the filter 'sensei_answer_text'.

It's possible that someone else might consider using LaTeX in a question title, on the file upload help, or the gap fill fields.

I'll create a PR for this idea. It would mean that all someone would have to do is to add Jetpack and active the Beautiful Maths module and they'd be ready to go.

hlashbrooke commented 9 years ago

This all sounds great to me - happy with all of your proposed changes.

Only thing I'd be wary of is adding add_filter( 'the_title', 'latex_markup', 9 ); as that would affect all titles on the site. It might be better to just apply the filter directly to the question titles. Maybe a custom filter sensei_question_title that simply applies the latex_markup filter, but it would also allow us (and users) to do further processing of question titles in the future.