Closed WIZARDELF closed 9 years ago
Can you help me understand some of the options for doing this?
Have you already tried using MathJax on your site?
what options ? I can do sth if you need
Feel free to steal what you need from:
https://github.com/soegaard/mathbook/blob/master/mathbook/defaults.rkt#L22 https://github.com/soegaard/mathbook/blob/master/mathbook/mathjax.rkt
2015-06-28 5:16 GMT+02:00 WeweTom notifications@github.com:
what options ? I can do sth if you need
— Reply to this email directly or view it on GitHub https://github.com/greghendershott/frog/issues/129#issuecomment-116187127 .
Jens Axel Søgaard
I played with doing this with MathJax, and it works reasonably well. If no-one else has a better answer I can find the notes I made (but it's pretty much 'arrange for the MathJax stuff to be in the header'). The underlying problem is that I don't think there's a way of telling markdown processors that there's a bit of inline text that they should neither parse nor wrap in <pre>...</pre>
tags (it is easy for block-level elements). That's a design limitation of markdown I think (I haven't looked at frog's parser to see if it has a solution).
Well frog uses a markdown parser I wrote. I could tweak that as necessary.
But to back up, can you give me example(s) of markdown source with MathJax annotations, that could be a problem?
The MathJax docs say:
The default math delimiters are
$$...$$
and\[...\]
for displayed mathematics, and\(...\)
for in-line mathematics.
Do you mean for example that \( 2 * 3 * 4 \)
might get parsed to "\( 2 <emph> 3 </emph> 4 \)"
? Or that \(x^2)\)
might get parsed as "footnote 2 for x"? And so on?
If so I could tweak the markdown parser to prevent that -- to take as literal the text between the MathJax delimiters.
MathJax injects a little piece of JavaScript in the html-page. At load time it scans through the page and looks for [ ... ] and ( ... ) and replaces them with a rendering of the math formula.
The ... between delimeters need to be in standard LaTeX-format.
That is: It doesn't matter what you use to indicate math-start and math-end in the markdown.
/Jens Axel
2015-06-29 22:01 GMT+02:00 Greg Hendershott notifications@github.com:
Well frog uses a markdown parser I wrote https://github.com/greghendershott/markdown. I could tweak that as necessary.
But to back up, can you give me example(s) of markdown source with MathJax annotations, that could be a problem?
The MathJax docs say:
The default math delimiters are $$...$$ and [...] for displayed mathematics, and (...) for in-line mathematics.
Do you mean for example that ( 2 * 3 * 4 ) might get parsed to "( 2
3 4 )"? Or that (x^2)) might get parsed as "footnote 2 for x"? And so on? If so I could tweak the markdown parser to prevent that -- to take as literal the text between the MathJax delimiters. — Reply to this email directly or view it on GitHub https://github.com/greghendershott/frog/issues/129#issuecomment-116820312 .
Jens Axel Søgaard
I am not sure if I have looked at what Frog's parser does, but things like $$x_y$$
tend to be problematic, as the underscore gets turned into some HTML.
Although some examples aren't a problem as I expected, some are:
#lang racket
(require markdown)
;; OK
(parse-markdown "\\(1 * 2 * 3\\)") ;'((p () "(1 * 2 * 3)"))
(parse-markdown "\\(1*2*3\\)") ;'((p () "(1*2*3)"))
;; Oops
(parse-markdown "\\(1 *2* 3\\)") ;'((p () "(1 " (em () "2") " 3)"))
;; Also, looks like it needs to be \\( \\) in the markdown source:
(parse-markdown "\\\\(1 * 2 * 3\\\\)") ;'((p () "\\(1 * 2 * 3\\)"))
I thought you were going to modify the parser? Everything between ( and ) needs to be kept as-is.
2015-06-29 23:13 GMT+02:00 Greg Hendershott notifications@github.com:
Although some examples aren't a problem as I expected, some are:
lang racket
(require markdown)
;; OK (parse-markdown "(1 * 2 * 3)") ;'((p () "(1 * 2 * 3)")) (parse-markdown "(1_2_3)") ;'((p () "(1_2_3)")) ;; Oops (parse-markdown "(1 2 3)") ;'((p () "(1 " (em () "2") " 3)"))
;; Also, looks like it needs to be ( ) in the markdown source: (parse-markdown "\(1 * 2 * 3\)") ;'((p () "(1 * 2 * 3)"))
— Reply to this email directly or view it on GitHub https://github.com/greghendershott/frog/issues/129#issuecomment-116847839 .
Jens Axel Søgaard
I thought you were going to modify the parser?
I am. I was just sharing some examples of why it definitely will need to be modified.
Everything between
\(
and\)
needs to be kept as-is.
Yes. (And also between \[
and \]
delimiters, IIUC.)
Also I was sharing that I noticed that \(
parses to (
, and \[
to [
, and so on. This already has a meaning in markdown, for example when you want to say that []
and ()
are not markdown syntax for links. So probably I'll need to require people to use \\(
to get \(
for MathJax to see, annoying as that may be.
(I'm currently away from a machine where I can play with frog so this may be wrong or obvious.)
I think there are three things that matter about sections left as-is for MathJax:
\(...\)
for it to find);\
must not mean anything to the MD parser except for the closing delimiter (in particular it would be horrid if you had to type \\
to get \
as it would make TeX really hard to type).I'm fine with having to type \\(...\\)
and \\[...\\]
as pairs: it doesn't really take significantly longer to type a double \
than a single one. It would kind of be a nice addition even without MathJax to have a way of saying 'leave this section be for something else to eat'.
Yes, within the MathJax delimiters, in the formula text itself, you can still use single \
. The formula text will be parsed as literal text, not as markdown.
But I think I do need to use \\
on the delimiters themselves, because people may already be using for example \[foo\]
to mean "I just want brackets, don't try to parse this as a markdown link".
After experimenting with using this, I found it somewhat finicky to have MathJax recognize the text in the HTML. I noticed that PHP-markdown emits the MathJax <script>
directly. I decided to do that, too, in the markdown parser.
Once that update to the markdown package is live on the package server, I'll merge a change to frog itself (adding a widget, updating the README, and changing its info.rkt to require the newer markdown package version).
Although not yet merged to master, it's commit 4a0a156e
Yes, I am fine with pretty much any delimiter: the thing I care about is that I can take a wodge of TeX and drop it into the bit between them without having to reformat it all (unless it contains `]' or something which, while strictly legal TeX, is not something I can ever see occurring in practice).
Thanks for these changes!
it's useful to support rendering math formulas.