openlab-at-city-tech / webworkqa

WeBWorK integration for WordPress and BuddyPress
GNU General Public License v2.0
4 stars 2 forks source link

Questions and responses should support TeX input #17

Closed boonebgorges closed 8 years ago

boonebgorges commented 8 years ago

It should be possible to reuse the existing code for rendering LaTeX to make this work.

I'll have to write some custom security policies, to avoid React escaping issues. This is more important when the TeX content comes not just from WW problems, but from user input.

We need to decide on start/end delimiters, so I can know what part of a question/response should be parsed as LaTeX. Here are some examples I've found: http://www.math.tamu.edu/%7Eboas/courses/math696/LaTeX-in-line-equations.html When we decide, we'll probably want a gloss under the input fields - something like "LaTeX-formatted contents should be surrounded by $$", or whatever.

I have a feeling that allowing TeX input is going to make it critical to introduce Edit functionality for questions and responses, something we haven't yet discussed.

boonebgorges commented 8 years ago

I opted for the verbose \begin{math}[TeX goes here]\end{math} for inline LaTeX and \begin{displaymath}[TeX goes here]\end{displaymath} for blocks of LaTeX. The verbose deliminators decrease the likelihood of false positives. The parsing is written to be pretty flexible, so this decision can be changed in the future.

jonasreitz commented 8 years ago

Thanks for opening this conversation, Boone - I think it's an important one. A couple of notes:

a) in traditional LaTeX, the delimiter is just a $, as in $[TeX goes here]$ for inline math stuff, and double dollar sign $$[TeX goes here]$$ for math typeset on its own line.

b) In the existing WP LaTeX plugin, there are two options:

Use either [latex]e^{\i \pi} + 1 = 0[/latex] or $latex e^{\i \pi} + 1 = 0$ syntax.

Although "I like the original version best" (as a traditional LaTeX user), I can see the strong possibility for false positives involved in just using a $. I don't have strong feelings either way about the verbose options you've provided for now - however, there may be some benefit to following the conventions coded into the WP LaTeX plugin, as our OpenLab users may already be using them in other courses and projects, and it's an added obstacle for them to have to keep multiple markup syntaxes straight in their heads.

Let's keep noodling on it as we go forward...

boonebgorges commented 8 years ago

I agree that the $ and $$ delimiters are the most elegant. There are two escaping issues:

a. If you have dollar signs in regular text ("Hey Jonas, you owe me $15"), it will start rendering LaTeX. b. If you have dollar signs inside LaTeX, it'll close the LaTeX renderer.

b. is pretty straightforward - we just require that dollar-sign literals are slashed ("Jonas owes Boone $x = \$1 \cdot 15")

We can do the same for a, though it's a bit more jarring - one is not likely to expect to have to do this sort of thing if the answer contains no LaTeX whatsoever.

It's not likely to be a significant issue in the context of questions/responses, so I'm happy to do whatever everyone thinks is best for students.

On 08/21/2016 04:16 PM, jonasreitz wrote:

Thanks for opening this conversation, Boone - I think it's an important one. A couple of notes:

a) in traditional LaTeX, the delimiter is just a $, as in |$[TeX goes here]$| for inline math stuff, and double dollar sign |$$[TeX goes here]$$| for math typeset on its own line.

b) In the existing WP LaTeX plugin, there are two options:

Use either [latex]e^{\i \pi} + 1 = 0[/latex] or $latex e^{\i \pi} +
1 = 0$ syntax.

Although "I like the original version best" (as a traditional LaTeX user), I can see the strong possibility for false positives involved in just using a $. I don't have strong feelings either way about the verbose options you've provided for now - however, there may be some benefit to following the conventions coded into the WP LaTeX plugin, as our OpenLab users may already be using them in other courses and projects, and it's an added obstacle for them to have to keep multiple markup syntaxes straight in their heads.

Let's keep noodling on it as we go forward...

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/livinglab/webwork-for-wordpress/issues/17#issuecomment-241282608, or mute the thread https://github.com/notifications/unsubscribe-auth/AAPDY-AoZ2UAjFVHNl1P3po-HSafZeN4ks5qiMA3gaJpZM4JeU5R.

moui72 commented 8 years ago

I don't feel like the need to escape $ in arbitrary contexts is worth the adherence to traditional markup, personally. What about something like [$ maths $] and [$] Lots of maths Many lines [/$] It's idiosyncratic, but reminiscent of the original, and less verbose than the actually LaTeX solution Boone already implemented (which in my opinion should stay in addition to a shorthand version).

boonebgorges commented 8 years ago

During our recent phone conversation, we decided to keep \begin{math}...\end{math} and \begin{displaymath}...\end{displaymath} as the official delimiters. We also decided to add non-advertised support for $latex...$.

moui72 commented 8 years ago

\begin{math}...\end{math} and \begin{displaymath}...\end{displaymath} are working nicely.

looks like $latex...$ isn't in yet (or else it's not working, let me know if it should be and I can gather details)

boonebgorges commented 8 years ago

Nope, not implemented yet, but thanks for the reminder :) I will go through this and other new issues in the next day or two.

On 09/12/2016 06:48 PM, Tyler J. Peckenpaugh wrote:

|\begin{math}...\end{math}| and |\begin{displaymath}...\end{displaymath}| are working nicely.

looks like |$latex...$| isn't in yet (or else it's not working, let me know if it should be and I can gather details)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/livinglab/webwork-for-wordpress/issues/17#issuecomment-246530816, or mute the thread https://github.com/notifications/unsubscribe-auth/AAPDY1xT8AbOfyA3t57RgEFv05k2MHdQks5qpeS-gaJpZM4JeU5R.

boonebgorges commented 8 years ago

$latex...$ is now implemented and ready to test. Should work in preview mode as well.

Since there's no explicit way to say whether this syntax is intended to display as block vs inline, I used the following heuristic: in $latexFOO$, if FOO contains any line breaks (\n), I assume that display mode is intended.

moui72 commented 8 years ago

$latex...$ works both for inline and block, in preview and for posted questions and "what have you tried"

I've just noticed that none of the latex modes work right for posted replies, although they work fine when previewed. See screenshots below.

Note that I tried this with all three of $latex...$, \begin{math}...\end{math} and \begin{displaymath}...\end{displaymath} and noticed no difference in behavior. I also tried $latex...$ with internal linebreaks.

Win7/Chrome 53+

In a reply, the text no because $latex r = \frac{x}{10}\% $ is rendered after posting as

r=LATEXESCAPECHARACTERfracx10LATEXESCAPECHARACTERr=LATEXESCAPECHARACTERfracx10LATEXESCAPECHARACTER 

The same text/formula works normally in a question. latex reply latex reply preview

boonebgorges commented 8 years ago

Oy, thanks, @moui72. In case you are curious what I'm up against here: https://teleogistic.net/2016/09/08/handling-latex-in-wordpress-and-react-js/

I'll take a look.

boonebgorges commented 8 years ago

OK, should be fixed by efa4052. Ready to test.

moui72 commented 8 years ago

seems to be fixed