custom header / footer

2,307 views
Skip to first unread message

slafs

unread,
Jul 20, 2010, 11:57:13 AM7/20/10
to sphinx-dev
Hi there!

Currently sphinx generates me a pretty pdf through

> make latex
and
> make all-pdf

What I'm looking for is a way of customizing the header which now is a
concatenation of
project_name + ", " + release

Can I somehow declare my own header or footer in there?

Regards

Georg Brandl

unread,
Jul 21, 2010, 7:57:00 PM7/21/10
to sphin...@googlegroups.com

Yes; currently the header line is defined like this in sphinx.sty:

\fancyhf{}
\fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
\fancyfoot[LO]{{\py@HeaderFamily\nouppercase{\rightmark}}}
\fancyfoot[RE]{{\py@HeaderFamily\nouppercase{\leftmark}}}
\fancyhead[LE,RO]{{\py@HeaderFamily \@title, \py@release}}

You can customize this is latex_elements['preamble'] by using
these commands again (between \makeatletter and \makeatother).

Georg

slafs

unread,
Jul 22, 2010, 7:43:54 AM7/22/10
to sphinx-dev
Thanks it worked.

To clarify

i used this in my conf.py in latex_preamble variable:

\makeatletter
\fancypagestyle{normal}{
\fancyhf{}
\fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
\fancyfoot[LO]{{\py@HeaderFamily\nouppercase{\rightmark}}}
\fancyfoot[RE]{{\py@HeaderFamily\nouppercase{\leftmark}}}
\fancyhead[LE,RO]{{\py@HeaderFamily \@title}} % here's the change
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
}
\makeatother

Regards

Thomas De Wolf

unread,
Sep 30, 2013, 9:19:05 AM9/30/13
to sphinx...@googlegroups.com, sphinx-dev
Hi all,

I recently started to use sphinx and latex to create my documentation, but I need to update the default header and footer content. So I ended up here. The thing is that when I add your content to my 'preamble' key in the latex_elements dict of my conf.py file, it gives me the following error:

! LaTeX Error: Missing \begin{document}.

In my conf.py:
latex_elements = {
'papersize': 'a4paper',
'preamble': '''
\makeletter
...
\makeatother
'''
}

Any idea what can be wrong here?

I installed the default Sphinx 1.1.3 on an Ubuntu 13.04 64-bit. Any idea what I'm doing wrong?

Thomas De Wolf

unread,
Sep 30, 2013, 9:30:05 AM9/30/13
to sphinx...@googlegroups.com, sphinx-dev
I tried this solution, but in the generated tex file, the \f and \t are converted replaced with some windows like characters (^L or ^M) or even empty.
Any idea what can go wrong here?

I use Sphinx 1.1.3 on Ubuntu 13.04 (64-bit)

Carl Cerecke

unread,
Sep 30, 2013, 3:38:31 PM9/30/13
to sphinx...@googlegroups.com
Use a raw string by prefixing the string with an r character so it
doesn't interpret backslashes as escape sequences:

r'''\this string has a backslash at the start'''

'''\this string has a tab character at the start'''

In the second string, the \t is interpreted as a tab character. Not so
in the first string.

Cheers,
Carl.
> --
> 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...@googlegroups.com.
> To post to this group, send email to sphinx...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sphinx-users.
> For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages