Customization of the bibliography in LaTeX output

278 views
Skip to first unread message

Sebastian Huber

unread,
Jan 3, 2019, 5:47:22 AM1/3/19
to sphinx-dev
Hello,

I use the sphinxcontrib-bibtex extension to generate the bibliography. In the LaTeX output the bibliography is placed at a fixed location (near the end of the document) with a fixed chapter name and without a chapter numbering. I would like to place the bibliography in a specific numbered chapter with a custom name. I can get this with a post-processing of the *.tex output of sphinx.

1. Move the \begin{sphinxthebibliography}...\end{sphinxthebibliography} content to the desired location in the file.

2. Add \renewcommand\bibname{Custom Name} to the file.

3. Add \usepackage[nottoc,numbib]{tocbibind} to the file.

4. Remove the \addcontentsline{toc}{chapter}{\bibname} in sphinxmanual.cls.

I don't know the sphinx internals, but would it be possible to change the LaTeX output generator to achieve this via the normal user interface, e.g. via bibliography directive options?

jfbu

unread,
Jan 3, 2019, 7:11:55 AM1/3/19
to sphin...@googlegroups.com

Hi Sebastian
About 2, 3, 4 you can achieve that via this

latex_elements = {
'preamble': r'''
\usepackage[nottoc,numbib]{tocbibind}
\addto\captionsenglish{\renewcommand\bibname{Custom Name}}
\renewenvironment{sphinxthebibliography}
{\begin{thebibliography}}
{\end{thebibliography}}
''',
}

in conf.py (adapt \captionsenglish to \captions<language> of document)

Regarding 1, the location is decided by the BibliographyTransform

https://github.com/sphinx-doc/sphinx/blob/7ff7dfc427209562cfc0e767be6717729e243e48/sphinx/builders/latex/transforms.py#L483-L523

which is part of the LaTeX transforms done there

https://github.com/sphinx-doc/sphinx/blob/7ff7dfc427209562cfc0e767be6717729e243e48/sphinx/builders/latex/__init__.py#L279-L288

Caveat: I have not looked whether sphinx.contrib.bibtex modifies this or adds own transform

(will try to help more if I can, but must go now)

Jean-François

jfbu

unread,
Jan 3, 2019, 8:23:22 AM1/3/19
to sphin...@googlegroups.com
Le 03/01/2019 à 13:11, jfbu a écrit :

about


>
> 1. Move the \begin{sphinxthebibliography}...\end{sphinxthebibliography} content to the desired location in the file.

The mismatch between HTML and LaTeX backends is well described in the sphinxcontrib-bibtex docs

https://sphinxcontrib-bibtex.readthedocs.io/en/latest/usage.html#mismatch-between-output-of-html-and-latex-backends

but although yes it reflects Sphinx default BibliographyTransform behaviour,
I would say that the sphinxcontrib-bibtex extension could be the place
to modify that behaviour, so it looks like a Feature Request to be made
to sphinxcontrib-bibtex project :)

... and lo and behold, that issue exists already

https://github.com/mcmtroffaes/sphinxcontrib-bibtex/issues/156

Best,

Jean-François

Sebastian Huber

unread,
Jan 3, 2019, 8:30:41 AM1/3/19
to sphinx-dev
Hello Jean-François,

thanks for the very helpful information. I have now a good starting point for further work.

Matthias Geier

unread,
Jan 3, 2019, 10:53:27 AM1/3/19
to sphin...@googlegroups.com
Thanks Sebastian for providing the link to this discussion!

Thanks Jean-François for your help!

The remaining question for me is:

Is there a better way to disable
sphinx.builders.latex.BibliographyTransform than what I've shown in
https://github.com/mcmtroffaes/sphinxcontrib-bibtex/issues/156?

Sphinx's usage of BibliographyTransform is hard-coded here:
https://github.com/sphinx-doc/sphinx/blob/7ff7dfc427209562cfc0e767be6717729e243e48/sphinx/builders/latex/__init__.py#L279-L288

If this feature is to be implemented in sphinxcontrib-bibtex, we need
some "official" way to disable BibliographyTransform.

Or does someone know another work-around?

cheers,
Matthias
> --
> You received this message because you are subscribed to the Google Groups "sphinx-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-dev+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Komiya Takeshi

unread,
Jan 4, 2019, 3:47:04 AM1/4/19
to sphin...@googlegroups.com
Hi Matthias,

Unfortunately, there is no proper way to disable it.
It is strongly coupled with LaTeX writer. So you need to replace it
with another transform.

Anyway, I can provide the option for the transform like "as is", "per
chapter" and "per document".
If you like it, please post a feature request. I'll work for it (in future).

Thanks,
Takeshi KOMIYA

2019年1月4日(金) 0:53 Matthias Geier <matthia...@gmail.com>:

Matthias Geier

unread,
Jan 5, 2019, 6:22:08 AM1/5/19
to sphin...@googlegroups.com
Thanks Takeshi!

I've created a feature request: https://github.com/sphinx-doc/sphinx/issues/5893

cheers,
Matthias
Reply all
Reply to author
Forward
0 new messages