The right way to use a custom latex stylesheet in place sphinx.sty

890 views
Skip to first unread message

chip

unread,
Jun 26, 2009, 2:28:26 PM6/26/09
to sphinx-dev
Hello,

I made some tweaks to the latex stylesheet sphinx.sty and I am trying
to determine the right way to handle these changes. Of course I can
keep the modified sphinx.sty in my installation, but it seems like
there should be a better way to do this.

I've noticed that the latex builder copies over the stylesheet and the
other files in texinputs, so I am guessing that I should create and
register a new builder following the guidelines on the Sphinx
homepage. Can someone tell me if this is the right way to go about
it, or is there a better way?

Thanks,
Chip

Wolfram Riedel

unread,
Jun 26, 2009, 6:57:01 PM6/26/09
to sphinx-dev

Hi.
Much simpler. I put every style change into my own style file which I
bind from conf.py using the 'latex_elements' option's 'preamble'.

As example, you name your custom style file 'mycustomstyle.sty' and
make this definition in conf.py:

latex_elements = {
'preamble': '\\usepackage{mycustomstyle}'
}

Just copy the desired parts of the default style file over to your
custom style file and adjust it to your needs. The modificated
definitions will overwrite the default definitions. Maybe you
sometimes have to use \renewcommand{} instead of \newcommand{}, I
guess you'll figure this out.
Also, you need to add your style file to conf.py once more to
automatically let sphinx copy it to the build directory:

latex_additional_files = ['mycustomstyle.sty']

Should be all there is to it.

Cheers,
Wolfram

Chip Webber

unread,
Jun 29, 2009, 11:02:02 AM6/29/09
to sphin...@googlegroups.com
Wolfram,
Thanks for the help. That's exactly what I was looking for.

-Chip

Guenter Milde

unread,
Jun 29, 2009, 5:44:01 PM6/29/09
to sphin...@googlegroups.com
On 2009-06-26, Wolfram Riedel wrote:
> On Jun 26, 8:28 pm, chip <chipweb...@gmail.com> wrote:

>> I made some tweaks to the latex stylesheet sphinx.sty and I am trying
>> to determine the right way to handle these changes.  Of course I can
>> keep the modified sphinx.sty in my installation, but it seems like
>> there should be a better way to do this.

> Much simpler. I put every style change into my own style file which I


> bind from conf.py using the 'latex_elements' option's 'preamble'.

> As example, you name your custom style file 'mycustomstyle.sty' and
> make this definition in conf.py:

> latex_elements = {
> 'preamble': '\\usepackage{mycustomstyle}'
> }

If it's just some small tweaks, you can load the standard style and put
them in the LaTeX preamble instead (this can include loading of other
packages, overwriting definitions or additional commands and settings).

> Just copy the desired parts of the default style file over to your
> custom style file and adjust it to your needs. The modificated
> definitions will overwrite the default definitions. Maybe you
> sometimes have to use \renewcommand{} instead of \newcommand{}, I
> guess you'll figure this out.

> Also, you need to add your style file to conf.py once more to
> automatically let sphinx copy it to the build directory:

> latex_additional_files = ['mycustomstyle.sty']

This is not even necessary if you put the custom style file in the LaTeX
path (e.g. ~/texmf/tex/latex) on the system where you run latex.

Günter

Chip Webber

unread,
Jun 30, 2009, 11:24:42 AM6/30/09
to sphin...@googlegroups.com
Günter,
Thanks for the tips.

Guenter Milde wrote:
> On 2009-06-26, Wolfram Riedel wrote:
>> On Jun 26, 8:28 pm, chip <chipweb...@gmail.com> wrote:
>
>>> I made some tweaks to the latex stylesheet sphinx.sty and I am trying
>>> to determine the right way to handle these changes. Of course I can
>>> keep the modified sphinx.sty in my installation, but it seems like
>>> there should be a better way to do this.
>
>> Much simpler. I put every style change into my own style file which I
>> bind from conf.py using the 'latex_elements' option's 'preamble'.
>
>> As example, you name your custom style file 'mycustomstyle.sty' and
>> make this definition in conf.py:
>
>> latex_elements = {
>> 'preamble': '\\usepackage{mycustomstyle}'
>> }
>
> If it's just some small tweaks, you can load the standard style and put
> them in the LaTeX preamble instead (this can include loading of other
> packages, overwriting definitions or additional commands and settings).
>

Actually I redefined the admonitions to include a graphic for
note/warning/caution in the box along with the text, so it is a bit more
than a couple tweaks. If anyone is interested in the changes let me know.

>> Just copy the desired parts of the default style file over to your
>> custom style file and adjust it to your needs. The modificated
>> definitions will overwrite the default definitions. Maybe you
>> sometimes have to use \renewcommand{} instead of \newcommand{}, I
>> guess you'll figure this out.
>
>> Also, you need to add your style file to conf.py once more to
>> automatically let sphinx copy it to the build directory:
>
>> latex_additional_files = ['mycustomstyle.sty']
>
> This is not even necessary if you put the custom style file in the LaTeX
> path (e.g. ~/texmf/tex/latex) on the system where you run latex.
>

Actually I was trying to avoid this in order to make the build process
easily repeatable on another system. Admittedly this is much better
than modifying the style in the system install.

Many thanks,
Chip

> Günter
>
>
> >
>

stooj

unread,
Sep 4, 2016, 9:06:51 AM9/4/16
to sphinx-users, sphin...@googlegroups.com
So sorry to resurrect this thread, but I am trying to include graphics for admonitions and would *love* it if I could refer to a working one.

I know I am a little late, Chip, but if you still have the style sheet I would be really interested to see it.
Reply all
Reply to author
Forward
0 new messages