Hi David,

Thanks for this reply and for writing docutils. I will try to respond to your questions (to help you help me),  But bear with a me bit -- I don't think that I can directly comply with your comments other than to note that "yes I think that the rendered text and functionality" are different in the html and latex published versions so it really has to change depending on the output format.

First in overview. I am trying to write a sort of annotated bibliography wiki application using reST as the underlying markup language for the wiki pages.  In my view it provided a richer markup set than markdown and more natural and pythonic code base for extension. Unwinding my actual code is a little bit difficult because it is interwined with the python web framework "BottlePy" that I am using and its native simple template.  But I will try to provide more explanation to better help you help me.

It seems to me what I want to do is "publish" html and latex from the same reST input source and by using the doctree nodes  Actually the modality of producing the source to be published by the latex writer is along the lines that I think that you suggested ie producing transformed reST for further processing  But the translation to html is somewhat different because I am want to produce an interactive web page.

Now in detail. I have been trying to insert annotated bibliographies within my reST documents using a custom "bibentries" directive.

A more real example piece of my typical reST source would look like this:
.. bibentries::

    Bad85 This is a note for a single paper; the markup end delimiter
    is two semicolons allowing a single semicolon in the note;;
    PB94;;

    Dwy04;;

The custom role directive wraps a list of entries. A given document might have 4-5 of these lists. The entries are delimited by two ";;" and can be on the same or separate lines.  Each entry has two subfields separated by a space:  the first subfield is a citation key which identifies the reference for my bibtex databases and the second is a note to be attached to the paper.

Once this is gathered I can much it on my own  -- the directive snippet that I proved to be an exceptionally easy way of scooping up the bib entry data from the reST document.

I then produce somewhat more complex html: the entries become a list. The rendered page provides some form interaction options for the user.  This requires a translation to "fatten" the reST source. Here is a snippet of html that I produce via the "raw" approach using the custom directive coded in a very similar fashion to my note
.  This seems to run counter to the advice
<ol>

<li>
<!-- -->
<input type="checkbox" name="entries" value="Articles/Bad85" class="chkAll"/>
<!-- -->
[Articles/<a href = "/Bibs/Articles/Bad85">Bad85</a>:
<a href = "http://pubs.acs.org/doi/abs/10.1021/ar00109a003">url</a>
<a href = "/data/Pdfs/Articles/Bad85.pdf">pdf</a>]
Bader.
Atoms in molecules.
In <i>Accounts of Chemical Research</i>
<b>18</b> (1): p. 9-15, 1985
<blockquote class="abstract">
Approximate quantum mechanical state functions have recently been
obtained for the norbornyl cation. These calculations have yielded the
energy of its equilibrium geometry and the relative energies of
neighboring geometries. It is the purpose of this account to
illustrate that more chemical information than simply energies and
their associated geometries can be obtained directly from a state
function. A state function contains the necessary information to both
define the atoms in a molecule and determine their average properties.
It also enables one to assign a structure, that is, determine the
network of bonds linking the atoms in a molecule and determine whether
or not the structure is table. The state function further determines
where electronic charge is locally concentrated and depleted. Quantum
mechanics can be used to relate these properties to local energy
contributions, thereby providing an understanding of the geometry and
reactivity of a molecule. (Summary prepared by MGP 120530)
</blockquote>
<p>Note: This is a note for a single paper; the markup end delimiter is two semicolons allowing a single semicolon in the note</p>
</li>

This part worked fine for me.  But now I want to translate the page to latex both for pdf printing and possible collaborative documents.  I like the way the doctree scoops up the custom directive contents.  And in this case I just retranslate my original reST source to a new reST document with the bibliographic information for latexing -- actually easier. But I don't understand the right "Docutilic" idiom for coding this using the parsed doctree and then "publishing" from the same reST source to either html or latex as needed.

So right now I am just munching on the original reST source to extract the bibentries stuff, use it to create my annotated bibliography list, and then write it a reST document for latexing. (This part is also working) Here is a snippet of my retranslated resT which can be published to latex with the latex2e writer (and processed to pdf):

#.   
    [Articles/Bad85:
    url
    pdf]
    Bader.
    Atoms in molecules.
    In *Accounts of Chemical Research*
    **18**
    (1):
    p. 9-15,
    1985 

         Approximate quantum mechanical state functions have recently
         been obtained for the norbornyl cation. These calculations
         have yielded the energy of its equilibrium geometry and the
         relative energies of neighboring geometries. It is the
         purpose of this account to illustrate that more chemical
         information than simply energies and their associated
         geometries can be obtained directly from a state function. A
         state function contains the necessary information to both
         define the atoms in a molecule and determine their average
         properties. It also enables one to assign a structure, that
         is, determine the network of bonds linking the atoms in a
         molecule and determine whether or not the structure is table.
         The state function further determines where electronic charge
         is locally concentrated and depleted. Quantum mechanics can
         be used to relate these properties to local energy
         contributions, thereby providing an understanding of the
         geometry and reactivity of a molecule. (Summary prepared by
         MGP 120530)

    Note: This is a note for a single paper; the markup end delimiter is two semicolons allowing a single semicolon in the note

Once again thanks to you, the maintainers, and the list  for following through on reading my somewhat extended pposts. Docutils is a big project of immense and of self-evident value to the Python community and beyond.  I understand that you and your colleagues are volunteering your valuable to time to support this project.

Michael
 



On Tue, May 14, 2013 at 12:29 AM, David Goodger <goodger@python.org> wrote:
On Mon, May 13, 2013 at 8:13 PM, Michael Prisant
<michael.prisant@gmail.com> wrote:
> Yes this is a dumb example but I think it is enough to get started. How can
> this question be made more simple or specific?

You can start by giving us a minimal but *real* example of what you
want as output. I think you're over-complicating the issue by trying
to simplify it in an unnatural way.

Unnatural, because the it's the job of the Writer classes to translate
Docutils document trees (doctrees) into their final formats. Don't try
to do the job of Writers from within your directive, that's the wrong
approach. You should be trying to write correct doctree nodes from
your code.

Apart from the differences in markup/tagging/codes, do you really need
different output from the two writers? IOW, does the content itself
(the rendered text & functionality) have to change depending on the
output format?

Don't worry about the HTML or LaTeX output, except to illustrate what
you want. Show us some real input, and some real desired output.

> PS Hoping that this can be posted to list in under 5 days!

Are you talking about your message, or the reply? If your message, it
could be that the first time you posted, you weren't a member, and
somebody (me) had to approve the post first, and I was otherwise busy.
Sometimes it takes me a while to get to list moderation.

If you're talking about the reply, well, sorry, but sometimes it takes
a while for people to carve time out of their busy lives.

--
David Goodger <http://python.net/~goodger>



--
Michael G. Prisant