#111 open
emime

mathtextile support?

Reported by emime | February 27th, 2009 @ 09:17 AM

Is it possible to support math?

Possible way:

Inside the plain textile, I can insert a tag (or something like) where insert latex math formulas.

When the converter to_html finds , it converts the latex into MATHML through MATHML library. When the convert to_latex finds , it just encloses math between a math environment.

What do you think about?

Thank you, Emi

Comments and changes to this ticket

  • Jason Garber

    Jason Garber February 27th, 2009 @ 09:34 AM

    • Tag set to latex
    • State changed from “new” to “open”

    Sure. Work up a patch (with good tests) and I'll include it. You can fork on github.

  • emime

    emime February 27th, 2009 @ 10:01 AM

    Great. I would like. But I don't know where to start (new to ruby).

    I had a look to the textile_doc.rb and formatter...not clear for me how to manage options and new tags.

    Some help? Thanks in advance. Emi

  • Jason Garber

    Jason Garber March 2nd, 2009 @ 10:27 AM

    • State changed from “open” to “invalid”
    • Milestone cleared.

    If you're new to Ruby, I'm guessing you're probably new to Ragel and C and Java extensions as well. Adding a feature like you're talking about would take quite a bit of expertise and effort in all of these, plus LaTeX. Unless you can find someone with the necessary expertise and inclination, this will probably have to be one feature we live without.

  • emime

    emime March 3rd, 2009 @ 07:37 AM

    Yes, you are true, I'm new to Ragel and C/Java ext as well. I didn't think a feature like that requires extensions... :(

    Anyway I dont want waste your time. I will send a link to this ticket to the guy that implement the latex formatter. May be he's intersted.

    I just attach the mathutil.rb file that does mathml by preprocessing the textile before using RedCloth.to_html. May be sometime someone finds it useful or you decide to impement the feature.

    To use it just...:

    get your string

    latextextile = "My textile with my mathml display formula: $$ x\rightarrow y $$"

    replace latex markup with mathml inside textile containing latex

    textile = MathmlUtil.replacelatex latextextile

    convert textile to xhtml

    xhtml = MathmlUtil.textile2xhtml textile

    write and save xhtml for displaying it in Mozilla

    xml = MathmlUtil.writexml xhtml

  • Jason Garber

    Jason Garber March 3rd, 2009 @ 07:56 AM

    • State changed from “invalid” to “open”

    Oh, I see. I was wrong. I thought it would need to recognize all the formula things, and that would require a lot of additions to the parser. I'll take a look at what you sent.

  • emime

    emime March 4th, 2009 @ 11:09 AM

    I've found (may be) a bug in to_html during conversion. Please explain the following behavior:

    I start writing this:

    
    Math $f(x)$ and math $f(x)$
    

    My code pre-processing code produces:

    
    Math <notextile><math display='inline' xmlns='http://www.w3.org/1998/Math/MathML'>
     <mi>f</mi>
     <mo>(</mo>
     <mi>x</mi>
     <mo>)</mo>
    </math></notextile> and math <notextile><math display='inline' xmlns='http://www.w3.org/1998/Math/MathML'>
     <mi>f</mi>
     <mo>(</mo>
     <mi>x</mi>
     <mo>)</mo>
    </math></notextile>
    

    That's fine...isn't? Now giving this to to_html I obtain the following:

    
    <p>Math <math display='inline' xmlns='http://www.w3.org/1998/Math/MathML'>
     <mi>f</mi>
     <mo>(</mo>
     <mi>x</mi>
     <mo>)<math display='inline' xmlns='http://www.w3.org/1998/Math/MathML'>
     <mi>f</mi>
     <mo>(</mo>
     <mi>x</mi>
     <mo>)</mo></p>
    <p></math></notextile> and math <math display='inline' xmlns='http://www.w3.org/1998/Math/MathML'>
     <mi>f</mi>
     <mo>(</mo>
     <mi>x</mi>
     <mo>)<math display='inline' xmlns='http://www.w3.org/1998/Math/MathML'>
     <mi>f</mi>
     <mo>(</mo>
     <mi>x</mi>
     <mo>)</mo></p>
    <p></math></notextile></p>
    

    Why this? It seems that to_html cuts a piece of text...

    Thanks Emi

  • emime

    emime March 4th, 2009 @ 11:17 AM

    I mean, I would expect this from to_html

    
    <p>Math <math display='inline' xmlns='http://www.w3.org/1998/Math/MathML'>
     <mi>f</mi>
     <mo>(</mo>
     <mi>x</mi>
     <mo>)</mo>
    </math></notextile> and math <math display='inline' xmlns='http://www.w3.org/1998/Math/MathML'>
     <mi>f</mi>
     <mo>(</mo>
     <mi>x</mi>
     <mo>)</mo></math></notextile></p>
    
  • emime

    emime March 4th, 2009 @ 11:20 AM

    Or better (forgot ) this is the expected result...

    
    <p>Math <math display='inline' xmlns='http://www.w3.org/1998/Math/MathML'>
     <mi>f</mi>
     <mo>(</mo>
     <mi>x</mi>
     <mo>)</mo>
    </math> and math <math display='inline' xmlns='http://www.w3.org/1998/Math/MathML'>
     <mi>f</mi>
     <mo>(</mo>
     <mi>x</mi>
     <mo>)</mo></math></p>
    
  • emime

    emime March 4th, 2009 @ 11:35 AM

    I've found the problem...it's due \n.... to work fine I need to use RedCloth like this....

    
    rc = RedCloth.new(mymathtextile)
    rc = rc.delete("\n")
    rc.hard_breaks = false
    xhtml = rc.to_html
    
  • emime

    emime March 5th, 2009 @ 09:22 AM

    Hello, I made a big stresstest starting from a textile+latex document and things seem now to work fine.

    The main problem in inline-mathml is that it comes with newlines and to_html interfers with it brokening the syntax (even if math is inside notextile..RedCloth bug?).

    So, finally, I had to remove newlines inside mathml trees from the RedcCloth object and disable hardbreaks like this.

    
    rc = RedCloth.new(textile)
    #puts "\nRedCloth object...\n" + rc
    rc = rc.gsub(/<math display(.+?)<\/math>/m) {|s| s.delete("\n")}
    #puts "\nRedCloth object without newlines" + rc
    rc.hard_breaks = false
    xhtml = rc.to_html
    

    With the hope you are interested in, I attach the new file modified, and the textile page I test with its output.

    Emi

  • emime

    emime March 9th, 2009 @ 11:59 AM

    I used '$' sign to delimit latex formulas (as latex itself uses)...but may be is not the right choice. Someone would like use '$' for its actual meaning (money).

    So...I'm in doubt..which sign is better to delimit formulas?

    Don't like the idea of a tag like latex because is heavy to write. I would like a simple delimiter like '$'.

    Any idea? May be this '\$'?

  • Jason Garber

    Jason Garber March 17th, 2009 @ 04:49 AM

    • Assigned user cleared.

    Bill, do you care to weigh in? I haven't had any time to look at this and I'm afraid I won't for quite awhile.

  • Bil Kleb

    Bil Kleb March 17th, 2009 @ 08:56 AM

    • Tag changed from latex to html, latex, standard
    • Assigned user set to “Bil Kleb”

    I took a look at mathmulti.zip and like what I saw. To me the biggest question is how do we incorporate it into Textile?

    I like the idea of LaTeX's shorthand: $inline math$ and \[display_math_block\] but I share emime's concern over muddying the waters for folks that care about money. (LaTeX requires one to escape dollar signs, e.g., \$.)

    Also there are other LaTeX math environments like a block-style environmment that numbers equation blocks, viz,

    
    \begin{equation}
    numbered_math_block
    \end{equation}
    

    I would like to see this added without breaking "standard" Textile markup. Also, it might behoove ourselves to mark such extensions some how or begin versioning Textile markup?

  • emime

    emime March 17th, 2009 @ 10:13 AM

    without breaking "standard" Textile markup

    The problem is that does not exist a textile (and html as well) for some (many) of latex markup. The willing is about extending textile markup to fit better latex...

    it might behoove ourselves to mark such extensions some how or begin versioning Textile markup?

    What you mean? Start a new (separate) project?

  • Bil Kleb

    Bil Kleb March 17th, 2009 @ 11:15 AM

    I'm up for extending Textile, but without breaking stock Textile and providing a means to find out whether you are using (or want to use) extensions or not.

    For example, if we adopted LaTeX's $inine_math$ convention, we would break standard Textile.

    So for the mathtextile question, we need to puzzle out a markup convention that doesn't break Textile (impossible?), or we need to tell RedCloth to use the math extensions (relatively easy).

    Given this last thought, maybe we create a math option and use LaTeX's inline markup conventions, e.g., $inline_math$ and \[display_math\], and include other LaTeX environments like you outlined in #133?

  • emime

    emime March 17th, 2009 @ 11:49 AM

    ok, I see.

    If we want embed mathtextile into RedCloth, I think that the "option" way is the best choice.

    May be we should proceed as follows...

    First, we need to tell RedCloth to use math ext. according to a friend option:

    
    rc = RedCloth.new(mathtextile)
    rc.mathext = true
    

    Second, because we don't want break standard methods, we could use overriden versions of the to_html and to_latex methods that assume extended textile is used and some pre-processing must be performed before invoking the original versions of to_html and to_latex.

    If this is acceptable (please confirm or complain), we should furtherly discuss whether use the parser (don't know Ragel and extensions) or simply regex.

  • Bil Kleb

    Bil Kleb March 17th, 2009 @ 12:29 PM

    Yes, and/or something like

    
    rc = RedCloth.new( mathtextile, :math_extensions => true )
    

    As far as the parser implementation, I'll defer to Jason...

    Looks like he just committed an EXTENSION_LANGUAGE option for possibly facilitating pluggable extensions?

    http://github.com/jgarber/redclo...

  • emime

    emime March 18th, 2009 @ 03:39 AM

    mmm...I had a look to it, but it's a little cryptic for me :(

    Do you know how does it work? Is there some documentation?

  • emime

    emime March 19th, 2009 @ 10:51 AM

    Hello, don't know really how redcloth uses .yml files but here there is a simple idea on how the things should be managed:

    
    name: theorem
    in: th. My theorem
    html: <div class='theorem_env'> <p class='theorem_lbl'> Theorem. <span class='theorem_txt'> My theorem </span><p/></div>
    latex: \begin{th} My theorem \end{th}
    

    with the latex command \newtheorem{th}{Theorem.} inserted in the preamble upon to_latex execution. Because math (and non-math) texts can contain similar custom-structures, there should be the possiblity of reading from an extension file my structures and have automatically implemented them in to_html and to_latex. This means that I would need to tell Redcloth:

    
    rc = RedCloth.new( mathtextile, :math_extensions => true )
    rc.import_math_extenstions(file)
    

    where file is something like:

    
    name: theorem
    extenstion: th.
    

    With the hope that what above is understandable...I would like to know if this feature can be easily achieved...really don't know what should be changed.

  • Tim Harper

    Tim Harper December 2nd, 2009 @ 10:29 AM

    I'm interested in this and can help implement it. What's the status on this?

  • emime

    emime December 4th, 2009 @ 03:44 AM

    • Tag changed from html, latex, standard to html, latex, mathml, standard

    I'm happy you're interested on it. At the moment the things stopped here, no implementation. Just the a "code-draft" (see attachment mathmlutil.zip in this same ticket).

    If you like, better..if you know redcloth you could fork and try to extend it with extension http://github.com/jgarber/redcloth/commit/f04cdbb645e0823def2a595cf... as suggested by Bill.

    I don't know why, but Bill stopped to discuss about this ticket.

    The mathml library, on which the idea is based, is in a good state and works fine.

    If you go on, please tell me, I would like to help you.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

RedCloth is a Ruby library for converting Textile into HTML

Shared Ticket Bins

People watching this ticket

Attachments

Referenced by

Pages