Skip to content

Set LaTeX bibitem id to citation node id #4213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

jnothman
Copy link
Contributor

@jnothman jnothman commented Nov 2, 2017

Subject: LaTeX writer uses \bibitem[label]{label} when it should use \bibitem[id]{label}

Feature or Bugfix

  • Bugfix

Purpose

In the unusual case that the textual label differs from the ID, the ID should be preferred. This comes up in a proposed change to numpydoc.

These IDs are not currently used for referencing within sphinx-produced TeX documents, as sphinx explicitly adds a \label to reference text.

In the unusual case that the textual label differs from the ID, the ID should be preferred.
@jnothman
Copy link
Contributor Author

jnothman commented Nov 2, 2017

I could add a test, but it might involve hacking doctrees.

@@ -919,7 +919,7 @@ def depart_document(self, node):
target = self.hypertarget(bi[2] + ':' + bi[3],
withdoc=False)
self.body.append(u'\\bibitem[%s]{%s}{%s %s}\n' %
(self.encode(bi[0]), self.idescape(bi[0]),
(self.encode(bi[3]), self.idescape(bi[0]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the labels of \cite are not changed. Is this really correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, sorry. Please forget my comment above.

@tk0miya
Copy link
Member

tk0miya commented Nov 2, 2017

Please add a test for this. in addition, please rebase this to stable branch.

@tk0miya tk0miya added this to the 1.6.6 milestone Nov 2, 2017
@jnothman
Copy link
Contributor Author

jnothman commented Nov 2, 2017 via email

Copy link
Contributor

@jfbu jfbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can not be merged, as bi[3] has already been normalized (converted to lowercase, stripped of diacritics (é becomes e), ...) hence although indeed the link works, this normalizes too much the look of the reference tag in the bibliography in an unexpected by user way.

@jfbu
Copy link
Contributor

jfbu commented Dec 28, 2017

@jnothman for background could you add a comment here with a link to numpydoc relevant thread?

@jnothman
Copy link
Contributor Author

Sorry, perhaps I got this backwards. In [] should be the display text, i.e. bi[0], and in {} the ID? Does that make sense to you, @jfbu?

This relates to numpy/numpydoc#136

@jfbu
Copy link
Contributor

jfbu commented Dec 31, 2017

Sorry, perhaps I got this backwards. In [] should be the display text, i.e. bi[0], and in {} the ID? Does that make sense to you, @jfbu?

Yes it is \bibitem[citeKey]{citeID} actual bibliographic reference. It will print out in bibliography as

[citeKey] actual bibliographic reference

and the [citeKey] will also be used and be a link in the document text.

I observe that Sphinx

  • encloses in braces the actual bibliographic reference which appears unneeded,

  • does not use the \cite command, a citeID is produced (self.idescape(bi[0])) but not used. In a normal LaTeX document one would see \cite{citeID} to match \bibitem[citeKey]{citeID}.

a priori, this looks sub-optimal.

In bi[3] there is a Sphinx citeid which is used to produced a label which serves as target for an hyperlink located at reference location in document. It is not same thing as the citeID above which is escaped from bi[0].

The bi[0] which ends up in \bibitem[self.encode(bi[0])] gives the printed citeKey in LaTeX document, it undergoes a TeX-escaping which I think boils down only to replacement of the underscore _ which is allowed in reST citations into \_ for LaTeX, because other allowed characters need no LaTeX-escaping.

@jfbu
Copy link
Contributor

jfbu commented Dec 31, 2017

@tk0miya I have started to work on getting LaTeX to use standard \cite command. This is at https://github.com/jfbu/sphinx/tree/latex_use_cite and currently has two commits (on tip of stable). It works in simple test, but I needed to hack into _resolve_citation_xref of standard domain. I can't work on this in near future, but I mention it here in case you have an opinion whether this might be worthwile. For example

Lorem ipsum [RefTTT_éé]_ dolor sit amet.

.. [RefTTT_éé] Book or article reference, URL or whatever.

now generates in latex file:

Lorem ipsum \cite{\detokenize{RefTTT__xe9_xe9}} dolor sit amet.

and

\begin{sphinxthebibliography}{RefTTT\_éé}
\bibitem[RefTTT\_éé]{\detokenize{RefTTT__xe9_xe9}}
Book or article reference, URL or whatever.

\end{sphinxthebibliography}

which is much lighter mark-up than in current Sphinx, with same functionality.

@tk0miya
Copy link
Member

tk0miya commented Jan 1, 2018

@jfbu +1

@jfbu jfbu modified the milestones: 1.6.6, 1.6.7 Jan 5, 2018
@jfbu
Copy link
Contributor

jfbu commented Jan 20, 2018

@jnothman any other proposal on this PR? for reasons explained it can not be merged as is.

FYI, I will refactor latex writer to use standard LaTeX \cite command at some point in future; if using \cite helps in your problem it could be merged into 1.7.x series as bugfix; else it will go into 1.8.

@jfbu jfbu modified the milestones: 1.6.7, 1.7, 1.8 Jan 20, 2018
@jnothman
Copy link
Contributor Author

Sorry, I've not had much attention for this one. If you have an alternative fix, feel free to put one in.

@jfbu
Copy link
Contributor

jfbu commented Jan 23, 2018

@jnothman thanks for update, issue is that I don't know what is to fix from your point of view. As mentioned it is planned for LaTeX writer to use \cite as it looks the reasonable thing to do and may ease up further customizations on user side. But I have no a priori idea whether this will help solve numpy/numpydoc#136, which sounds related to some specific handling of references done at numpy.

@tk0miya
Copy link
Member

tk0miya commented May 13, 2018

Finally, in #4904, I replaced \hyperref with \cite.
As a result, this is also resolved.

Thanks,

@tk0miya tk0miya closed this May 13, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants