Dear Group,

Let's say I have a custom restructured text directive of the following form in the string "content":

.. bibentries::
     
    BCC+87;;

For the purpose of this question when I call

print publish_string( source=content, writer_name='html',settings_overrides=overrides)

I would like to emit something similar to the following in my html stream:

<pre> This is the html bibdirective </pre>

and when I call:

print publish_string( source=content,writer_name='latex2e',settings_overrides=overrides)

to emit something similar to the following in my latex stream:

/begin{verbatim} This is the latex bibdirective /end{endverbatim}

Of course in my real code I do some munching on the content of bibdirective but for the purposes of this example/question  I'll work with this simplification.

In any case I have written code for a custom directive as follows::

class BibDirective(Directive):
    has_content = True
    def run(self):
        self.assert_has_content()
        text = '<pre> This is the html bibdirective </pre>'
        return [nodes.raw('', text, format='html')]

directives.register_directive("bibentries", BibDirective)

This idiom works fine if I am only interested in publishing the html part.

Now I want to be able to also publish latex output.  So I try adding something like this to my program:

class BibDirective(Directive):
    has_content = True
    def run(self):
        self.assert_has_content()
        text = '\begin{verbatim} This is the html bibdirective \end{verbatim}'
        return [nodes.raw('', text, format='latex')]


but I can't get this to work in a manner that I am able to appropriately choose the output depending on which writer is passed to the publisher.  So what is the proper "docutils" way of coding this?

Michael

--
Michael G. Prisant