Skip to content

Commit 7eced43

Browse files
cpitclaudelZimmi48
authored andcommitted
[doc] Create a separate zebibliography file for the LaTeX build
`.. bibliography::` puts the bibliography on its own page with its own title in LaTeX, but includes it inline without a title in HTML [1], so we need to maintain two separate copies of zebibliography.rst [1] https://sphinxcontrib-bibtex.readthedocs.io/en/latest/usage.html#mismatch-between-output-of-html-and-latex-backends
1 parent dc4fc03 commit 7eced43

File tree

6 files changed

+32
-18
lines changed

6 files changed

+32
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ doc/faq/axioms.eps_t
100100
doc/faq/axioms.pdf_t
101101
doc/faq/axioms.png
102102
doc/sphinx/index.rst
103+
doc/sphinx/zebibliography.rst
103104
doc/stdlib/Library.out
104105
doc/stdlib/Library.ps
105106
doc/stdlib/Library.coqdoc.tex

doc/sphinx/conf.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,34 @@
6666
# The encoding of source files.
6767
#source_encoding = 'utf-8-sig'
6868

69+
import logging
70+
from glob import glob
6971
from shutil import copyfile
7072

71-
SUPPORTED_FORMATS = { fmt: os.path.abspath("index-{}.rst".format(fmt))
72-
for fmt in ["html", "latex"] }
73-
MASTER_DOC = os.path.abspath("index.rst")
74-
7573
# Add extra cases here to support more formats
76-
def copy_master_doc(app):
77-
for fmt, rst_path in SUPPORTED_FORMATS.items():
74+
75+
SUPPORTED_FORMATS = ["html", "latex"]
76+
77+
def current_format(app):
78+
for fmt in SUPPORTED_FORMATS:
7879
if app.tags.has(fmt):
79-
copyfile(rst_path, MASTER_DOC)
80-
break
81-
else:
82-
MSG = """Unexpected builder; expected one of {!r}.
83-
Add support for this new builder in `copy_master_doc` in conf.py."""
84-
from sphinx.errors import ConfigError
85-
raise ConfigError(MSG.format(list(SUPPORTED_FORMATS.keys())))
80+
return fmt
81+
MSG = """Unexpected builder ({}); expected one of {!r}.
82+
Add support for this new builder in `copy_formatspecific_files` in conf.py."""
83+
from sphinx.errors import ConfigError
84+
raise ConfigError(MSG.format(list(app.tags.tags.keys()), SUPPORTED_FORMATS))
85+
86+
def copy_formatspecific_files(app):
87+
ext = ".{}.rst".format(current_format(app))
88+
for fname in sorted(os.listdir(app.srcdir)):
89+
if fname.endswith(ext):
90+
src = os.path.join(app.srcdir, fname)
91+
dst = os.path.join(app.srcdir, fname[:-len(ext)] + ".rst")
92+
app.info("Copying {} to {}".format(src, dst))
93+
copyfile(src, dst)
8694

8795
def setup(app):
88-
app.connect('builder-inited', copy_master_doc)
96+
app.connect('builder-inited', copy_formatspecific_files)
8997

9098
# The master toctree document.
9199
# We create this file in `copy_master_doc` above.
@@ -126,11 +134,10 @@ def setup(app):
126134
'Thumbs.db',
127135
'.DS_Store',
128136
'introduction.rst',
129-
'index-*.rst', # One of these gets copied to index.rst in `copy_master_doc`
130137
'refman-preamble.rst',
131138
'README.rst',
132139
'README.template.rst'
133-
]
140+
] + ["*.{}.rst".format(fmt) for fmt in SUPPORTED_FORMATS]
134141

135142
# The reST default role (used for this markup: `text`) to use for all
136143
# documents.
File renamed without changes.

doc/sphinx/index-latex.rst renamed to doc/sphinx/index.latex.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ Addendum
7777
addendum/miscellaneous-extensions
7878
addendum/universe-polymorphism
7979

80-
.. No need for an explicit bibliography entry in the toc: it gets picked up
81-
from ``zebibliography.rst``.
80+
.. toctree::
81+
zebibliography
File renamed without changes.

doc/sphinx/zebibliography.latex.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. See zebibliography.html.rst for details
2+
3+
.. _bibliography:
4+
5+
.. bibliography:: biblio.bib
6+
:cited:

0 commit comments

Comments
 (0)