Skip to content

Commit

Permalink
Suppress space before footnote citations, and document it. (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmtroffaes committed Jul 28, 2021
1 parent 724897e commit c2e456f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
* Allow specific warnings to be suppressed (see issue #255, contributed by
stevenrhall).

* Remove space between footnote and author for textual footnote citations in
the default foot referencing style.

* Document how to use a backslash escaped space to suppress space before
footnotes (see issue #256, reported by hagenw).

2.3.0 (1 June 2021)
-------------------

Expand Down
10 changes: 7 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,21 @@ represented by footnotes as follows:
.. code-block:: rest
See :footcite:t:`1987:nelson` for an introduction to non-standard analysis.
Non-standard analysis is fun :footcite:p:`1987:nelson`.
Non-standard analysis is fun\ :footcite:p:`1987:nelson`.
.. footbibliography::
which will get rendered as:

See Nelson [#Nel87b]_ for an introduction to non-standard analysis.
Non-standard analysis is fun [#Nel87b]_.
See Nelson\ [#Nel87b]_ for an introduction to non-standard analysis.
Non-standard analysis is fun\ [#Nel87b]_.

.. [#Nel87b] Edward Nelson. *Radically Elementary Probability Theory*. Princeton University Press, 1987.
Note the use of the
`backslash escaped space <https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#inline-markup>`_
to suppress the space that would otherwise precede the footnote.

Typically, you have a single ``footbibliography`` directive
at the bottom of each document that has footnote citations.
Advanced use cases with multiple ``footbibliography`` directives
Expand Down
10 changes: 7 additions & 3 deletions doc/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -278,19 +278,23 @@ Roles and Directives

.. code-block:: rest
We will make use of non-standard analysis :footcite:p:`1987:nelson`.
We will make use of non-standard analysis\ :footcite:p:`1987:nelson`.
which would be equivalent to the following LaTeX code:

.. code-block:: latex

We will make use of non-standard analysis \footcite{1987:nelson}.
We will make use of non-standard analysis\footcite{1987:nelson}.

Note the use of the
`backslash escaped space <https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#inline-markup>`_
to suppress the space that would otherwise precede the footnote.

As with all citation roles, multiple keys can be specified:

.. code-block:: rest
I love analysis :footcite:p:`1987:nelson,2001:schechter`!
I love analysis\ :footcite:p:`1987:nelson,2001:schechter`!
.. rst:role:: footcite:t
Expand Down
2 changes: 1 addition & 1 deletion src/sphinxcontrib/bibtex/style/referencing/foot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FootReferenceStyle(GroupReferenceStyle):
person: PersonStyle = PersonStyle()

#: Separator between text and reference for textual citations.
text_reference_sep: Union["BaseText", str] = ' '
text_reference_sep: Union["BaseText", str] = ''

def __post_init__(self):
self.styles.extend([
Expand Down
48 changes: 24 additions & 24 deletions test/test_footcite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ def test_footcite_roles(app, warning) -> None:
tests = [
("p", " [1] "),
("ps", " [1] "),
("t", " de Du *et al.* [1] "),
("ts", " de Du, Em, and Fa [1] "),
("ct", " De Du *et al.* [1] "),
("cts", " De Du, Em, and Fa [1] "),
("t", " de Du *et al.*[1] "),
("ts", " de Du, Em, and Fa[1] "),
("ct", " De Du *et al.*[1] "),
("cts", " De Du, Em, and Fa[1] "),
("p", " [2][3] "),
("ps", " [2][3] "),
("t", " al Ap [2], Be and Ci [3] "),
("ts", " al Ap [2], Be and Ci [3] "),
("ct", " Al Ap [2], Be and Ci [3] "),
("cts", " Al Ap [2], Be and Ci [3] "),
("t", " al Ap[2], Be and Ci[3] "),
("ts", " al Ap[2], Be and Ci[3] "),
("ct", " Al Ap[2], Be and Ci[3] "),
("cts", " Al Ap[2], Be and Ci[3] "),
("p", " [4][5][6] "),
("ps", " [4][5][6] "),
("t", " Ge [4], Hu [5], Ix [6] "),
("ts", " Ge [4], Hu [5], Ix [6] "),
("ct", " Ge [4], Hu [5], Ix [6] "),
("cts", " Ge [4], Hu [5], Ix [6] "),
("t", " Ge[4], Hu[5], Ix[6] "),
("ts", " Ge[4], Hu[5], Ix[6] "),
("ct", " Ge[4], Hu[5], Ix[6] "),
("cts", " Ge[4], Hu[5], Ix[6] "),
]
for role, text in tests:
escaped_text = re.escape(text)
Expand Down Expand Up @@ -76,22 +76,22 @@ def test_footcite_style_custom(app, warning) -> None:
tests = [
("p", " [1] "),
("ps", " [1] "),
("t", " de Du et al [1] "),
("ts", " de Du & Em & Fa [1] "),
("ct", " De Du et al [1] "),
("cts", " De Du & Em & Fa [1] "),
("t", " de Du et al[1] "),
("ts", " de Du & Em & Fa[1] "),
("ct", " De Du et al[1] "),
("cts", " De Du & Em & Fa[1] "),
("p", " [2][3] "),
("ps", " [2][3] "),
("t", " al Ap [2]; Be & Ci [3] "),
("ts", " al Ap [2]; Be & Ci [3] "),
("ct", " Al Ap [2]; Be & Ci [3] "),
("cts", " Al Ap [2]; Be & Ci [3] "),
("t", " al Ap[2]; Be & Ci[3] "),
("ts", " al Ap[2]; Be & Ci[3] "),
("ct", " Al Ap[2]; Be & Ci[3] "),
("cts", " Al Ap[2]; Be & Ci[3] "),
("p", " [4][5][6] "),
("ps", " [4][5][6] "),
("t", " Ge [4]; Hu [5]; Ix [6] "),
("ts", " Ge [4]; Hu [5]; Ix [6] "),
("ct", " Ge [4]; Hu [5]; Ix [6] "),
("cts", " Ge [4]; Hu [5]; Ix [6] "),
("t", " Ge[4]; Hu[5]; Ix[6] "),
("ts", " Ge[4]; Hu[5]; Ix[6] "),
("ct", " Ge[4]; Hu[5]; Ix[6] "),
("cts", " Ge[4]; Hu[5]; Ix[6] "),
]
for role, text in tests:
escaped_text = re.escape(text)
Expand Down

0 comments on commit c2e456f

Please sign in to comment.