Discussion:
[Docutils-users] Class parameter is not effective in code directive (rst2latex)
Sébastien Dailly
2017-04-19 07:36:41 UTC
Permalink
Hello,

I'm stuck with rst2latex : I want to customize the code-block rendering
with a dark background. rst2latex translate this directive to a quote
environnment which I can't override because it is already used elsewhere
in the document.

I've tried to add a class parameter to the directive
.. code-block:: C
:class: darkBackground
// Comment
But this does not seems to work (the class parameter is discarded)
\begin{quote}
{\ttfamily \raggedright \noindent
\DUrole{comment}{\DUrole{single}{//~Comment\\
}}~\\
.. class:: darkBackground
.. code-block:: C
// Comment
But this does not give the expected result.

This seems to be a problem with the writer, because rst2html gives the
<pre class="code C darkBackground literal-block">
<span class="comment single">// Comment
Is this a known bug ? Is there a workaround for this ?

Thanks a lot !
--
Sébastien

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Docutils-users mailing list
Docutils-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/docutils-users

Please use "Reply All" to reply
Sébastien Dailly
2017-04-19 08:48:39 UTC
Permalink
Post by Sébastien Dailly
Hello,
I'm stuck with rst2latex : I want to customize the code-block rendering
with a dark background. rst2latex translate this directive to a quote
environnment which I can't override because it is already used
elsewhere
in the document.
I've tried to add a class parameter to the directive
.. code-block:: C
:class: darkBackground
// Comment
But this does not seems to work (the class parameter is discarded)
\begin{quote}
{\ttfamily \raggedright \noindent
\DUrole{comment}{\DUrole{single}{//~Comment\\
}}~\\
.. class:: darkBackground
.. code-block:: C
// Comment
But this does not give the expected result.
This seems to be a problem with the writer, because rst2html gives the
<pre class="code C darkBackground literal-block">
<span class="comment single">// Comment
Is this a known bug ? Is there a workaround for this ?
Thanks a lot !
$ diff -c5 __init__.py /cygdrive/t/__init__.py
*** __init__.py 2017-04-19 10:33:56.977196800 +0200
--- /cygdrive/t/__init__.py 2017-04-19 10:33:51.485961600 +0200
***************
*** 2450,2459 ****
--- 2450,2461 ----
'lstlisting': r'\usepackage{listings}',
'Verbatim': r'\usepackage{fancyvrb}',
# 'verbatim': '',
'verbatimtab': r'\usepackage{moreverb}'}
+ self.visit_inline(node)
self.out += ['\n'] + self.ids_to_labels(node)
# no quote inside tables, to avoid vertical space between
***************
*** 2493,2502 ****
--- 2495,2506 ----
self.literal = False
self.verbatim = False
self.alltt = False
self.out.append(self.context.pop())
self.out.append(self.context.pop())
+ self.depart_inline(node)
## self.out.append('[visit_meta]\n')
# TODO: set keywords for pdf?
It seems to be a bug in the writer (I'm ccing docutils-develop). I have
no idea if this change can break other construction… Can you check if
this change can be integrated in the project ?

Thanks !
--
Sébastien

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Docutils-users mailing list
Docutils-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/docutils-users

Please use "Reply A
Guenter Milde
2017-04-19 11:06:19 UTC
Permalink
Post by Sébastien Dailly
Hello,
I'm stuck with rst2latex : I want to customize the code-block rendering
with a dark background. rst2latex translate this directive to a quote
environnment which I can't override because it is already used elsewhere
in the document.
I've tried to add a class parameter to the directive
.. code-block:: C
:class: darkBackground
// Comment
But this does not seems to work (the class parameter is discarded)
Yes, up to Docutils 0.13.1, class values for (almost all) block-level
elements are ignored by the latex writer.

In the development version (and upcoming release 0.14) the latex writer
will support class values for most block level elements:

- Handle class arguments for block-level elements by wrapping them
in a "DUclass" environment. This replaces the special handling for
"epigraph" and "topic" elements.

your example input will then be converted to::

\begin{DUclass}{code}
\begin{DUclass}{C}
\begin{DUclass}{darkbackground}
\begin{quote}
{\ttfamily \raggedright \noindent
\DUrole{comment}{\DUrole{single}{//~Comment}}
}
\end{quote}
\end{DUclass}
\end{DUclass}
\end{DUclass}


Customization is done by defining matching macros or environments.
For details, see the latex writer documention docs/usre/latex.txt
in the SVN repo.
Post by Sébastien Dailly
.. class:: darkBackground
.. code-block:: C
// Comment
But this does not give the expected result.
Yes, this is converted to the same doctree (check with rst2xml or
rst2pseudoxml).
Post by Sébastien Dailly
Is this a known bug ?
It is a known limitation (per specification, Docutils writers are free to
ingore class values).

It is solved in the development version.
http://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils/


Günter


PS: Please don't cross-post, both lists are read by the developers.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Docutils-users mailing list
Docutils-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/docutils-users

Please use "R
Sébastien Dailly
2017-04-19 14:35:43 UTC
Permalink
Post by Guenter Milde
Yes, up to Docutils 0.13.1, class values for (almost all) block-level
elements are ignored by the latex writer.
In the development version (and upcoming release 0.14) the latex writer
- Handle class arguments for block-level elements by wrapping them
in a "DUclass" environment. This replaces the special handling for
"epigraph" and "topic" elements.
This is a good news ! Do you have an idea for the 0.14 release date ?
Post by Guenter Milde
Customization is done by defining matching macros or environments.
For details, see the latex writer documention docs/usre/latex.txt
in the SVN repo.
PS: Please don't cross-post, both lists are read by the developers.
Thanks. I've cross-post the message because I've took a look in the code
and found a simple patch which solve my problem.

Regards,
--
Sébastien

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Docutils-users mailing list
Docutils-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/docutils-users

Please use "Reply All" to reply to the
Loading...