For PDF output, the "easiest" way is add a latex preamble that redefines 
the style.  The style names sometimes change from version to version (eg, 
I'm still on 1.4.4, I know they are different in 1.5).

I store the premble in a .tex file outside of the conf.py, like so:
PREAMBLE = string.Template(open(
                os.path.join(os.path.abspath('.'),
'latex_templates/preamble.tex')
                ).read())
latex_elements = {
    #....Other contents here
    'preamble': PREAMBLE
}

Eg, I did the following to make all the admonitions to be upper case and 
centered:
\renewenvironment{notice}[2]{
  \def\py@noticetype{#1}
  \csname py@noticestart@#1\endcsname
  % Make the admonition type be upper case and on its own line
  \begin{center}\strong{\MakeUppercase{#2}} \\\end{center}
}{\csname py@noticeend@\py@noticetype\endcsname}


Unfortunately, this involves learning latex and trying to figure out how 
the Sphinx styles work.

--Peter

On Saturday, August 19, 2017 at 7:38:13 AM UTC-7, Imre Deak wrote:
>
> Hi,
>
> I'd like to set the background color and font type for a block of text 
> that would be rendered correctly both in html and pdflatex outputs. What I 
> tried so far without success:
>
> - .. parsed-literal directive
>   This renders a gray background color only in the html output, the 
> pdflatex output renders the text on a white background which can't be 
> changed. Also I'd like to avoid having line breaks where the .rst version 
> has a line break, instead I'd like the lines to be automatically reflowed 
> based on available width as for normal text. (I know I can make long lines 
> break automatically, but this is not what I want.)
>
> - .. note/warning etc. directives
>   These add the "Note", "Warning" etc. captions which I don't want.
>
> - .. container:: class
>   This allows for a custom html syling by adding a .css style for "class", 
> but the pdflatex output won't have any markup that I could use (redefine) 
> for a custom style. .. role's emit a \DUrole markup which I think could be 
> used for custom styles, but I want something for a whole block of text, 
> that is for an rst directive.
>
> Is there some way (using the above or some other approach) to do what I 
> want?
>
> I believe it could be done with a sphinx extension, if so could someone 
> provide a sketch for this to get me started?
>
> Thanks.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to