Shortcut for a chunk of rest code

82 Views Asked by At

In sphinx I want to have a command, which would expand differently depending on withter I'm making an html build or a latex build. Example:

.. |noindent| replace::

   .. only:: latex

      .. raw:: latex

         \noindent

   .. only:: html

      .. rst-class:: noindent

The problem is that replace can't accept multiline string: it can only accept a single line string:

.. |noindent| replace:: with this

Is there a way to have a shortcut binded to a chunk of rest code?

Edit:

One can just include the source of course:

  • ReST:

    .. include:: _noindent.rst
    
  • _noindent.rst:

    .. only:: latex
    
       .. raw:: latex
    
          \noindent
    
    .. only:: html
    
       .. rst-class:: noindent
    

but the drawback is to keep track of _noindent.rst: either setting correct link, or copying the file to every content folder.

Edit 2:

Perhaps it won't be hard for guy experienced with sphinx to add a custom directive

text with indent

.. noindent::

text with no indent

which would expand to the above code.

0

There are 0 best solutions below