Fletcher T.Penney
2006-Jun-10 17:02 UTC
MultiMarkdown and MathML - new feature and request for help
A lot of people have expressed interest in combining math features with Markdown, but I am not aware of any real developments from these requests. I was looking around and toying with [ASCIIMathPHP](http:// www.jcphysics.com/ASCIIMath/) and integrated it with MultiMarkdown and my xhtml2latex XSLT transforms. You can include math as an inline formula by using a markup similar to inline code, such as ``x^2 + y^2 = 1`` (note the double ``). You can include a formula as a separate paragraph in the same way, or with a leading tab like: `x_(1,2) = (-b+-sqrt(b^2-4ac))/(2a)` (Note the single use of ` when prefaced by a tab) The leading tab is not required, but is allowed as I suspect most people would like to be able to indent the formula to distinguish it from regular text, and don't want it interpreted as a code block. The processing occurs in a several steps: 1) ASCIIMathPHP is run on the source markdown document converting the formulas into MathML blocks. 2) MultiMarkdown is then run in the usual manner, with or without SmartyPants 3) You can then optionally use XSLT to transform the XHTML into LaTeX or whatever by using an updated version of my xhtml2latex, or your own XSLT files. This includes the use of [XSLT MathML Library] (http://xsltml.sourceforge.net/) to convert the MathML into LaTeX. This allows you to generate XHTML with embedded MathML, or to generate LaTeX source with the math properly displayed. More importantly, it allows you to use ASCIIMath to enter your formulas which is MUCH more human readable than either MathML or LaTeX. THE PROBLEM I have run into a couple of snags, that I am sure would be quite simple to fix if I knew more about XHTML and XSLT. To demonstrate, I have included a sample plain text file (.txt), as well as two versions of XHTML output - (.xhtml and .html) and a LaTeX file (.tex). These were all generated automatically from the source plain text file. The .xhtml setup was designed using the layout from http:// www.mozilla.org/projects/mathml/authoring-example.xhtml It renders properly in Firefox (with the exception of that ugliness in square root signs, but that is not my doing...), but I cannot use this to go through my xhtml2latex.xslt workflow. It appears that the problem lies in the xmlns attribute: <html xmlns="http://www.w3.org/1999/xhtml"> If I remove that attribute, the xsltproc stuff works fine. The .html file is built using the usual DOCTYPE etc from MultiMarkdown. It does not render properly in Firefox, but it DOES go through my xhtml2latex.xslt files properly, to generate valid LaTeX output (i.e. the .tex file). Also, if I take the .xhtml file and rename it with a .html extension, it no longer renders properly in Firefox. Once you have the .tex file, it goes without a snag through pdflatex to generate a pdf. REQUEST FOR HELP!!! I would appreciate any input available in how to smooth this process a bit, specifically: 1) How can I create a valid document with a .html extension? (requiring .xhtml is going to break a bunch of other stuff) 2) How do I fix my xhtml2latex stylesheets (http:// fletcher.freeshell.org/wiki/Markdown_and_XML) to work with a file that has the xmlns attribute applied to the html node? (Or with whatever comes out of an answer to #1 above) 3) Any suggestions on the markup syntax? I sort of arbitrarily chose the use of an extra `. I am sure there is a better way of doing this, and would love to hear input. 4) And less importantly, is there a perl version of ASCIIMath out there somewhere? It would be great to be able to combine the code, but this can be worked around. Definitely lower on the priority list. Once I get all of this working more smoothly, I will release the updated software for public use. For now, you can see how it works with sample documents Thanks in advance! Fletcher PS> Yes, I realize that the included mathematical equations are not all correct. It's just a demo... -- Fletcher T. Penney fletcher@alumni.duke.edu I'll go through life either first class or third, but never in second. - Noel Coward -------------- next part -------------- author: Fletcher T. Penney Format: complete Title: Sample MultiMarkdownMath Document # Math Testing # You can use math in-line, such as ``8 + 4 = 12`` and ``155 / 12 = 10 / 2``. Or you can use as paragraphs: ``155 / 12 = 10 / 2`` ``x^2 + y^2 = 1`` Or with a blockquote-like syntax: `x_(1,2) = (-b+-sqrt(b^2-4ac))/(2a)` Code is not translated: `x = pi` -------------- next part -------------- A non-text attachment was scrubbed... Name: test.xhtml Type: application/octet-stream Size: 2627 bytes Desc: not available Url : http://six.pairlist.net/pipermail/markdown-discuss/attachments/20060610/d951c2d8/test.obj -------------- next part -------------- An HTML attachment was scrubbed... URL: http://six.pairlist.net/pipermail/markdown-discuss/attachments/20060610/d951c2d8/test.html -------------- next part -------------- A non-text attachment was scrubbed... Name: test.tex Type: application/octet-stream Size: 1981 bytes Desc: not available Url : http://six.pairlist.net/pipermail/markdown-discuss/attachments/20060610/d951c2d8/test-0001.obj -------------- next part --------------
Michel Fortin
2006-Jun-10 19:18 UTC
MultiMarkdown and MathML - new feature and request for help
Le 10 juin 2006 ? 17:02, Fletcher T.Penney a ?crit :> 1) How can I create a valid document with a .html extension? > (requiring .xhtml is going to break a bunch of other stuff)MathML (or any other XML language for that matter) is not recognized when the browser parse the file with the HTML parser. So for MathML to work, you need ".xhtml" or a "application/xhtml+xml" MIME type. And yes, unfortunately, that can break other stuff.> 2) How do I fix my xhtml2latex stylesheets (http:// > fletcher.freeshell.org/wiki/Markdown_and_XML) to work with a file > that has the xmlns attribute applied to the html node? (Or with > whatever comes out of an answer to #1 above)Instead, try to answer this question: how to specify an XML namespace from the stylesheet?> 3) Any suggestions on the markup syntax? I sort of arbitrarily > chose the use of an extra `. I am sure there is a better way of > doing this, and would love to hear input.Well, if you want to be sure Markdown doesn't change the content of your expression, you could wrap it into a processing instruction tag: <?ascii2math x_(1,2) = (-b+-sqrt(b^2-4ac))/(2a) ?> This is less pretty, but has less chance to break too. With your syntax, what happens if you have some `<` in a formula? With the one above, only `?>` would be problematic, but you shouldn't see that too often in maths.> 4) And less importantly, is there a perl version of ASCIIMath out > there somewhere? It would be great to be able to combine the code, > but this can be worked around. Definitely lower on the priority list.I'm not aware of any. Michel Fortin michel.fortin@michelf.com http://www.michelf.com/
Dr. Drang
2006-Jun-10 22:49 UTC
MultiMarkdown and MathML - new feature and request for help
On 6/10/06, Fletcher T. Penney <fletcher@alumni.duke.edu> wrote:> A lot of people have expressed interest in combining math features > with Markdown, but I am not aware of any real developments from these > requests. > > I was looking around and toying with [ASCIIMathPHP](http:// > www.jcphysics.com/ASCIIMath/) and integrated it with MultiMarkdown > and my xhtml2latex XSLT transforms. > > You can include math as an inline formula by using a markup similar > to inline code, such as ``x^2 + y^2 = 1`` (note the double ``). > > You can include a formula as a separate paragraph in the same way, or > with a leading tab like: > > `x_(1,2) = (-b+-sqrt(b^2-4ac))/(2a)` > > (Note the single use of ` when prefaced by a tab) > > The leading tab is not required, but is allowed as I suspect most > people would like to be able to indent the formula to distinguish it > from regular text, and don't want it interpreted as a code block.As Fletcher may recall, I had a math-enabled version of MultiMarkdown going several months ago. It differed from his in that * it used $$ and $$$ as the inline and display equation delimiters, respectively; * the equations had to be written in LaTeX form, not ASCIIMathML; and * it output HTML that was to be interpreted by [jsMath][1], not ASCIIMathML. The double and triple dollar signs were chosen because they reminded me of the usual TeX delimiters, but left the single dollar sign with its usual, non-TeX, meaning. I chose jsMath over ASCIIMathML because it works on more browsers. jsMath is essentially a JavaScript rewrite of the TeX equation formatting engine. It works on browsers that don't understand MathML. True, the ASCIIMathML syntax is more Markdown-like, but TeX is pretty well established as an equation syntax (for those of you who are not native speakers of English, that's a bit of Midwestern understatement). One of the other advantages of jsMath is that it's easy to write XSLT for it. jsMath uses <span class="math">...</span> to delimit inline equations and <div class="math">...</div> for display equations. These are easy to convert into $ and $$ for LaTeX. <!-- inline math --> <xsl:template match="span[@class='math']"> <xsl:text>$</xsl:text> <xsl:value-of select="node()"/> <xsl:text>$</xsl:text> </xsl:template> <!-- display math --> <xsl:template match="div[@class='math']"> <xsl:text>$$</xsl:text> <xsl:value-of select="node()"/> <xsl:text>$$</xsl:text> <xsl:value-of select="$newline"/> <xsl:value-of select="$newline"/> </xsl:template> Recently, however, [I decided to give up on my fork of MultiMarkdown][2] and go back to the standard version. Fletcher is too damned prolific, and I didn't want to keep inserting my code into newer and newer versions of MultiMarkdown. To this end, I started delimiting my equations with \\( and \\) for inline and \\[ and \\] for display. Regular MultMarkdown (or Markdown itself) just turns the double backslash into a single. jsMath has a preprocessor, the tex2math plugin, that will take these LaTeX delimiters and convert them to <span class="math"> and <div class="math"> before the usual jsMath processing. This is what I use for equations in [my ongoing solutions manual][3] for Den Hartog's *Mechanics* textbook. For documents that are to be run through LaTeX for paper output, I pass them through 1. a preprocessor that converts the \\(..\\) and \\[...\\] to <span class="math">...</span> and <div class="math">...</div>; 2. MultiMarkdown 3. an XSLT processor using my stylesheet with the above stanzas for math. Having written this long message, how is it responsive to Fletcher's post? First, I'd prefer LaTeX syntax and jsMath to ASCIIMathML. My preference comes from the wider applicability of jsMath, but it turns out that XSL is easier, too. And since you're using LaTeX for final processing (if you're publishing to paper), it makes sense to use LaTeX syntax for the equations. As for delimiters, I'd prefer something a little more TeX-like than backquotes, but I'm flexible. I had about 20 posts up at the *Mechanics* site with the multiple dollar sign notation before I decided to give up on my fork of MultiMarkdown; now I have about 40 posts up using the \\( and \\[ notation. -- Dr. Drang [1]: http://www.math.union.edu/~dpvc/jsMath/welcome.html [2]: http://www.leancrew.com/all-this/2006/05/mechanics_blog_update.html [3]: http://www.leancrew.com/mechanics
John Gruber
2006-Jun-11 12:30 UTC
MultiMarkdown and MathML - new feature and request for help
Fletcher T.Penney <fletcher@alumni.duke.edu> wrote on 6/10/06 at 5:02 PM:> You can include math as an inline formula by using a markup similar > to inline code, such as ``x^2 + y^2 = 1`` (note the double ``).This conflicts with Markdown itself. In Markdown, you can use multiple backticks as code delimiters so that you can include literal backticks in the code span. Input: `` `backtick` `` Output: <code>`backtick`</code> -J.G.