On Mon, Sep 7, 2009 at 8:23 AM, John H Palmieri<jhpalmier...@gmail.com> wrote: > > On Sep 7, 12:54 am, Ondrej Certik <ond...@certik.cz> wrote: >> On Fri, Sep 4, 2009 at 2:28 PM, John H Palmieri<jhpalmier...@gmail.com> >> wrote: >> >> I tried your patch (I made a sphinx extension out of it), but it >> didn't work for me --- the backsubstitution to docstringlines failed >> in the extension (maybe sphinx is inconsistent here), but this can be >> fixed easily by just doing >> >> docstringlines[:] = [s] > > That's strange. Maybe the issue is that mine is interacting with the > Sphinx autodoc extension, which passes "docstringlines" as an > argument: this is a list of strings, the lines of the doc string that > autodoc has extracted. You're using "source-read" which passes a > list containing one element, the entire docstring. Maybe you can > change the first line of your code to > > s = source[0] > > and then the last line would be > > source[0] = s or source = [s] > > I couldn't figure out how to use "source-read" for the Sage reference > manual, since "source" in our case is some autogenerated string that > doesn't contain the actual docstring -- you have to interact with > autodoc to get that. > >> worse problem is that I want to change it to math:`sd`, not just `sdf` >> (I have not figured it out how to do that using your indices >> approach). In any case, I rewrote it so that it works for me, >> attached. > > Oh, I like your approach. I see that you're not worrying about `$ or > $` in the code, but there are strings like that in the Sage code -- > e.g., ``$SAGE_ROOT...`` -- so I had to test for this and not replace > such dollar signs.
Yeah, I will use \$ for that, if I ever need it. But yes, I agree it should be more clever --- I think we can even combine my and your approach. > >> So that's a very convenient solution, as I can ship it with my sphinx >> notes and it will just work. Later on, after I gain more experience, >> I'll ask on the sphinx list, if they want to ship this with sphinx >> itself. > > Sounds good. I'm curious: for your own use, why don't you use > > default_role = 'math' > > so you can use `x=y` instead of :math:`x=y` ? Maybe a better I just wasn't sure if this can't break other people's code, let's say if they take my .rst file and include it in their project (where they use a different definition for `...`). > question, which just occurred to me: is it worth adding some sort of > parameter to your extension so that it replaces $x=y$ by > either :math:`x=y` or `x=y`, depending on that parameter? Yeah, that should be easy to implement. Why would you ever need it though? I thought you always need :math:`...` at the end of the day. Btw, I just found a bug in my (and your) code, I have to change: - s = re.sub(r"({[^{}$]*\$[^{}$]*\$[^{}$]*})", repl, s) + s = re.sub(r"({[^{}$]*\$[^{}$]*\$[^{}]*})", repl, s) that's because there could be things like \mbox{adflj $x$ and $y$ and $z$}. After this, here I converted some of my notes (I had them in xml and used my own converter to generate latex or html, that was from before sphinx was born). So I just wrote a simple converter to rst and everything just works. It's awesome: http://certik.github.com/theoretical-physics/book/src/qft.html I will now convert all my physics and math notes into sphinx. Right now I have them scattered over dozens latex documents, sometimes I even lost the source, only have pdf. So this will now change, I put everything into one git repository, and host it on github. Ondrej --~--~---------~--~----~------------~-------~--~----~ To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---