On Sphinx 2.x, I want to put a content that changes depending on the output 
format.


In any source document, say, index.rst, add the following lines:


.. role:: pdf(raw)
   :format: pdf

.. role:: latex(raw)
   :format: latex

.. role:: html(raw)
   :format: html

.. |foo| replace::
   :pdf:`PDF!`
   :latex:`LaTeX!`
   :html:`HTML!`

I am |foo|


I expect it shows *"I am HTML!"* when the output format is in HTML, *"I am 
LaTeX!"* if it's LaTeX (even after converting the product to PDF via 
pdflatex) and *"I am PDF!"* if it's PDF.


I make the HTML version using make html and I see only *"I am HTML!"* in a 
web browser as I expect:


[image: A make html result] <https://i.stack.imgur.com/rRHCc.png>


Install rst2pdf. Put the following lines in conf.py:


extensions = [
    'rst2pdf.pdfbuilder'
]

pdf_documents = [(
    'index',
    u'testRst2Pdf',
    u'Test Title',
    u'Sarah Author')]


Make the PDF version with


sphinx-build -b pdf ./source/ ./build/


I see *"I am PDF! LaTeX! HTML!"* that includes all the three items.

[image: An rst2pdf result] <https://i.stack.imgur.com/XRMbx.png>

Is there any way to get either *"I am PDF!"* or *"I am LaTeX!"* in the PDF 
file?


*Note.*

   - Before reporting this behavior as a bug, someone help me check if it's 
   unexpected behavior or as-designed.
   - This question is derived from the other I asked earlier: StackOverflow: 
   "Sphinx: Use a different directive for a different output format". 
   
<https://stackoverflow.com/questions/60439235/sphinx-use-a-different-directive-for-a-different-output-format/60440546?noredirect=1#comment106925678_60440546>
   - This question is from StackOverflow: "Sphinx rst2pdf and role 
   directives" <https://stackoverflow.com/questions/60444185>.
   

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sphinx-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sphinx-users/1956bc54-acf3-4b78-883b-4a37d3eb2cf3%40googlegroups.com.

Reply via email to