2002: 2003: 2004: 2005: 2006: 2007: 2008: 2009: 2010: 2011: 2012: 2013: Jan Feb Mar Apr May Jun Jul Aug (3) Sep (15) Oct (21) Nov (18) Dec (59) Jan (43) Feb (35) Mar (78) Apr (65) May (163) Jun (169) Jul (137) Aug (77) Sep (47) Oct (27) Nov (43) Dec (68) Jan (61) Feb (39) Mar (11) Apr (42) May (86) Jun (82) Jul (24) Aug (26) Sep (37) Oct (62) Nov (131) Dec (43) Jan (31) Feb (56) Mar (65) Apr (165) May (106) Jun (97) Jul (65) Aug (150) Sep (78) Oct (115) Nov (41) Dec (26) Jan (50) Feb (39) Mar (56) Apr (67) May (89) Jun (68) Jul (116) Aug (65) Sep (58) Oct (103) Nov (28) Dec (52) Jan (92) Feb (60) Mar (124) Apr (96) May (69) Jun (79) Jul (25) Aug (22) Sep (7) Oct (17) Nov (27) Dec (32) Jan (57) Feb (87) Mar (51) Apr (43) May (56) Jun (62) Jul (25) Aug (82) Sep (58) Oct (42) Nov (38) Dec (86) Jan (50) Feb (33) Mar (84) Apr (90) May (109) Jun (37) Jul (22) Aug (51) Sep (93) Oct (86) Nov (31) Dec (62) Jan (33) Feb (57) Mar (62) Apr (43) May (30) Jun (49) Jul (20) Aug (40) Sep (152) Oct (38) Nov (15) Dec (32) Jan (29) Feb (25) Mar (65) Apr (45) May (27) Jun (11) Jul (14) Aug (8) Sep (13) Oct (117) Nov (60) Dec (19) Jan (23) Feb (32) Mar (24) Apr (41) May (56) Jun (24) Jul (15) Aug (11) Sep (26) Oct (21) Nov (12) Dec (31) Jan (32) Feb (24) Mar (39) Apr (44) May (44) Jun (8) Jul (9) Aug (12) Sep (34) Oct (19) Nov (5) Dec
 [Docutils-users] parsing/transforming LaTeX with TTH From: Matthew Leingang - 2008-08-06 13:55 Hello again, Yesterday I wrote that I use RST to author web pages that contain math in them. I had been plugging in the latex_directive.py directive and role which runs their content through LaTeX and inserts images of the expressions into the document. I said that for small formulas this wasn't really worth it; who wants a picture of x^2 when x2 will do? Now I've got another idea and I need a little help to make it perfect. After I wrote I started thinking about TTH . It's a lightweight utility that converts TeX or LaTeX documents into a number of web formats. How lightweight? It's a single C file. It emulates TeX's parser, which means it won't match everything TeX can do, but all one needs for this case is the math typesetting, and it does a pretty good job of that. It's also very fast. I was able to hack up the latex_directive.py file to use TTH instead of LaTeX for converting LaTeX text. TTH can generate HTML text with italics for letters, upright for numbers, unicode characters (instead of glyphs from the symbol font--ugh!) for symbols, and tables for non- linear arrangements like fractions, matrices, or large symbols. It can also be configured to return just snippets of HTML instead of a complete document. A full diff is at the bottom. I need some help in attaching the right nodes, though. In the original latex_directive.py, the image nodes generated by dvippng are attached by this bit of code: - for pageno, name in enumerate(image_names): - - the_nodes.append(nodes.image(uri=name, alt=alt)) - alt = '' - I already have a string of HTML so used a raw node: + the_nodes.append(nodes.raw(tex,html,format='html')) And just like it's supposed to, the HTML string is written directly to the html file. I got this far reading source; now I need some help. I would rather the html be written to the output file surrounded by a ... element for further styling opportunities. I gather I need a different node type for that, or at least another attribute passed to the constructor. What would be best? Also, I would like to embed the tex source in the HTML document, perhaps as the title attribute to the containing span element. How would I do that? Oh, one more thing: sometimes an author wants an equation displayed (block-level) rather than inline. So perhaps the latex *directive* should use a div rather than a span? Thanks in advance for your help! --Matt --- latex_directive.py Tue Aug 5 15:46:33 2008 +++ latex_tth_directive.py Wed Aug 6 09:03:54 2008 @@ -1,5 +1,5 @@ """ -Implement latex directive. +Implement latex directive using tth instead of latex+dvip2png. """ import os @@ -12,18 +12,11 @@ from docutils.parsers.rst.directives import register_directive, flag from docutils.parsers.rst.roles import register_canonical_role - def latex_math(tex): - """ Process tex and produce image nodes. """ - image_names = latex_snippet_to_png(tex) - + """ Process tex and produce raw nodes. """ + html = latex_snippet_to_html(tex) the_nodes = [] - alt = tex - for pageno, name in enumerate(image_names): - - the_nodes.append(nodes.image(uri=name, alt=alt)) - alt = '' - + the_nodes.append(nodes.raw(tex,html,format='html')) return the_nodes @@ -67,29 +60,18 @@ # Restore working directory os.chdir(cwd) -latex_template = r''' -\documentclass[12pt]{article} -\pagestyle{empty} -%(prologue)s -\begin{document} -%(raw)s -\end{document} -''' -max_pages = 10 MAX_RUN_TIME = 5 # seconds latex_name_template = 'latex2png_%s' -latex = "latex" -dvipng = "dvipng" -latex_args = ("--interaction=nonstopmode", "%s.tex") -dvipng_args = ("-bgTransparent", "-Ttight", "--noghostscript", "-l%s" % max_pages, "%s.dvi") +latex = "tth" +latex_args = ("-L","-i","-u2","-r", "%s.tex") -def latex_snippet_to_png(inputtex, prologue=''): - """ Convert a latex snippet into a png. """ - - tex = latex_template % { 'raw': inputtex, 'prologue': prologue } - namebase = latex_name_template % sha.new(tex).hexdigest() - dst = namebase + '%d.png' +def latex_snippet_to_html(inputtex,prologue=''): + """ Convert a latex snippet into a snippet of HTML. """ + tex = inputtex + namebase = latex_name_template % sha.new(tex).hexdigest() + dst = namebase + '%d.html' + tmpdir = tempfile.mkdtemp() try: data = open("%s/%s.tex" % (tmpdir, namebase), "w") @@ -101,23 +83,10 @@ if not res is None: # FIXME need to return some sort of error return [] - args = list(dvipng_args) - args[-1] = args[-1] % namebase - res = call_command_in_dir(dvipng, args, tmpdir) - if not res is None: - # FIXME need to return some sort of error - return [] - - page = 1 - pagenames = [] - while os.access("%s/%s%d.png" % (tmpdir, namebase, page), os.R_OK): - pagename = dst % page - shutil.copyfile("%s/%s%d.png" % (tmpdir, namebase, page), pagename) - page += 1 - pagenames.append(pagename) + html=file("%s/%s.html" % (tmpdir, namebase)).read().replace('\n','') finally: # FIXME do some tidy up here pass + return html - return pagenames - + 

 Re: [Docutils-users] parsing/transforming LaTeX with TTH From: David Goodger - 2008-08-06 14:16 On Wed, Aug 6, 2008 at 09:55, Matthew Leingang wrote: > I got this far reading source; now I need some help. I would rather > the html be written to the output file surrounded by a ... span> element for further styling opportunities. I gather I need a > different node type for that, or at least another attribute passed to > the constructor. What would be best? Since you're already outputting raw HTML, why not just add some more HTML? That's the simplest way. To do it within Docutils, wrap the raw HTML with nodes.inline(classes=['docutils-tth']) (i.e., append the inline node to the_nodes, and append the raw node to the inline node). > Also, I would like to embed the tex source in the HTML document, > perhaps as the title attribute to the containing span element. How > would I do that? You'd have to do it with raw HTML. The Docutils HTML writer currently doesn't support title attributes. > Oh, one more thing: sometimes an author wants an equation displayed > (block-level) rather than inline. So perhaps the latex *directive* > should use a div rather than a span? Sure. It's great that you're doing all this, but please realize that an HTML-only math directive has zero chance of being added to core Docutils. Any addition to the core has to work with all output formats, current and future. Single-purpose extensions like this will stay in the sandbox. If you'd like write access to the repository, send me your SourceForge.net and BerliOS.de account names, and read http://docutils.sourceforge.net/docs/dev/policies.html -- David Goodger 

 Re: [Docutils-users] parsing/transforming LaTeX with TTH From: Alan G Isaac - 2008-08-06 16:57 Why aren't you using rst2mathml? Is it lacking any particular desired functionality? The result displays great under FireFox, there's a plugin for IE, and Opera is getting native support. Cheers, Alan Isaac PS http://www.dictionaryofeconomics.com/mathml_test 

 Re: [Docutils-users] parsing/transforming LaTeX with TTH From: Matthew Leingang - 2008-08-06 17:04 Thanks for your response. On Aug 6, 2008, at 10:16 AM, David Goodger wrote: > On Wed, Aug 6, 2008 at 09:55, Matthew Leingang > wrote: >> I got this far reading source; now I need some help. I would rather >> the html be written to the output file surrounded by a ...> span> element for further styling opportunities. I gather I need a >> different node type for that, or at least another attribute passed to >> the constructor. What would be best? > > Since you're already outputting raw HTML, why not just add some more > HTML? That's the simplest way. > > To do it within Docutils, wrap the raw HTML with > nodes.inline(classes=['docutils-tth']) (i.e., append the inline node > to the_nodes, and append the raw node to the inline node). Aha, thanks! >> Also, I would like to embed the tex source in the HTML document, >> perhaps as the title attribute to the containing span element. How >> would I do that? > > You'd have to do it with raw HTML. The Docutils HTML writer currently > doesn't support title attributes. Mm-hmm. putting it in the title attribute is probably an abuse anyway. > It's great that you're doing all this, but please realize that an > HTML-only math directive has zero chance of being added to core > Docutils. Any addition to the core has to work with all output > formats, current and future. Single-purpose extensions like this will > stay in the sandbox. Sure, I understand. I'm not exactly vying to be a core developer. If I got this working to the level of my own satisfaction, I would be happy to have it in the sandbox. But for the sake of discussion, what other output formats are we talking about? * XML? tth can output MathML instead of HTML * S5? There's also jsMath which parses latex and uses JavaScript to draw formulas on the page * LaTeX? Seems like a legitimate use for raw there. * Pseudo XML? Sorry, I don't know too much about that. Perhaps that should just leave the code as it is. There's also tex2mail , an ancient perl script that coverts to ASCII art. > If you'd like write access to the repository, send me your > SourceForge.net and BerliOS.de account names, and read > http://docutils.sourceforge.net/docs/dev/policies.html I've got too much else that I *should* be doing right now, but I'll let you know. --Matt 

 Re: [Docutils-users] parsing/transforming LaTeX with TTH From: Matthew Leingang - 2008-08-06 17:24 On Aug 6, 2008, at 12:56 PM, Alan G Isaac wrote: > Why aren't you using rst2mathml? > Is it lacking any particular desired functionality? > The result displays great under FireFox, there's > a plugin for IE, and Opera is getting native support. Hi Alan, Thanks for that. I was actually unaware of rst2mathml! I used MathML for a pretty large web application once, and it caused me huge headaches. At the time (2004), only Mozilla was trying to support it, and only spottily at best. I'm glad to hear you say that it works well under Firefox now. But is the IE plugin that you're talking of the one by Design Science? Again, last time I was checking, that was a bit of "nagware" that was free but kept pestering for a premium upgrade. --Matt -- Matthew Leingang Clinical Associate Professor of Mathematics leingang@... 

 Re: [Docutils-users] parsing/transforming LaTeX with TTH From: Alan G Isaac - 2008-08-06 18:01 On Wed, 6 Aug 2008, Matthew Leingang apparently wrote: > I'm glad to hear you say that > it works well under Firefox now. But is the IE plugin > that you're talking of the one by Design Science? Actually there are choices, and since I stay as far from IE as possible, I do not know which is best. But yes, the one I had in mind was MathPlayer (not, e.g., Formulator MathML IE Performer). I confess that my view is: anyohe who wants to view math on the web will be using a browswer with MathML support, so basically, authors don't have to worry about it. I grant that this is an academic rather than a commercial perspective. Cheers, Alan Isaac 

 Re: [Docutils-users] parsing/transforming LaTeX with TTH From: David Goodger - 2008-08-06 18:39 On Wed, Aug 6, 2008 at 12:21, Matthew Leingang wrote: >> It's great that you're doing all this, but please realize that an >> HTML-only math directive has zero chance of being added to core >> Docutils. Any addition to the core has to work with all output >> formats, current and future. Single-purpose extensions like this will >> stay in the sandbox. > > Sure, I understand. I'm not exactly vying to be a core developer. If > I got this working to the level of my own satisfaction, I would be > happy to have it in the sandbox. > > But for the sake of discussion, what other output formats are we > talking about? > > * XML? tth can output MathML instead of HTML > * S5? There's also jsMath which parses latex and uses JavaScript to > draw formulas on the page S5 is an application of HTML, so whatever works for HTML ought to work there too. > * LaTeX? Seems like a legitimate use for raw there. > * Pseudo XML? Sorry, I don't know too much about that. Perhaps that > should just leave the code as it is. PseudoXML is just for testing. As-is would be fine there. There is also an OpenDocument writer in the sandbox, close to ready for the core. Any feature must support that also. There are other writers in the sandbox as well: PDF, wordml, manpage. The point is that there are multiple output formats, and new feature must support all of them. There should at least be a fallback option, like graphical rendering. -- David Goodger 

 Re: [Docutils-users] parsing/transforming LaTeX with TTH From: - 2008-08-08 13:06 Alan G Isaac writes: > Why aren't you using rst2mathml? > Is it lacking any particular desired functionality? > The result displays great under FireFox, there's > a plugin for IE, and Opera is getting native support. Last time I checked, Mozilla/Firefox suppot for MathML required free-of-charge (but not DFSG-free) font(s) from Wolfram. Is this no longer the case? 

 Re: [Docutils-users] parsing/transforming LaTeX with TTH From: Alan G Isaac - 2008-08-08 13:36 Trent W. Buck wrote: > Last time I checked, Mozilla/Firefox suppot for MathML required > free-of-charge (but not DFSG-free) font(s) from Wolfram. Is this no > longer the case? http://www.mozilla.org/projects/mathml/fonts/ But even without installing the free Styx fonts, many symbols are available on modern systems. And all the formatting, of course. Alan Isaac