Skip to content
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

Allow for citation labels not to be surrounded by brackets #203

Closed
amichuda opened this issue Nov 10, 2020 · 5 comments
Closed

Allow for citation labels not to be surrounded by brackets #203

amichuda opened this issue Nov 10, 2020 · 5 comments
Assignees

Comments

@amichuda
Copy link

Would it be possible to have citations that around square brackets? I might not be pointing at the right part of the code right now, but square brackets are hardcoded:

node[0] = docutils.nodes.Text('[' + label + ']')

I know that we can create custom labels with pybtex, but that's just for what goes inside the brackets, correct? is there some way to get rid of the brackets or have them be replaced by parantheses if we wish?

@mcmtroffaes
Copy link
Owner

Docutils hardcodes the square brackets by convention for the citation role. I'm not sure if there's an easy way to change that in a way that does not break other things. Did you try if it works if you change the brackets in the bibtex/__init__.py code?

mcmtroffaes added a commit that referenced this issue Dec 20, 2020
Adds Weston Nielson’s sphinx-natbib extension from https://raw.githubusercontent.com/jterrace/sphinxtr/12e54683867a2d189e32af76a8160455c95826e0/extensions/natbib/__init__.py to the test suite, updates its implementation for latest sphinx, fixes a few bugs, and provides full test coverage.

This patch prepares for further work on #201 and #203.
@mcmtroffaes mcmtroffaes self-assigned this Dec 29, 2020
@mcmtroffaes
Copy link
Owner

The develop branch now supports natbib style inline citations with :cite:t: and :cite:p: with tons of variants, and with every aspect of inline citations fully customizable (whether to have brackets, what the brackets are, how to format separators, what part of the inline citation gets the link, ...). I'll write some documentation for this and then it will be included with the next release, hopefully not too long from now.

@amichuda
Copy link
Author

This looks awesome! Thank you so much

@choldgraf
Copy link

@mcmtroffaes this is really great! thank you 🙏🙏🙏

Please do ping when there's docs and I'm happy to give it a shot and provide feedback

@mcmtroffaes
Copy link
Owner

@choldgraf Thanks, it's much appreciated! There are some docs indeed. I've created new issue here for wider discussion: #232

delfanbaum added a commit to oreillymedia/jupyter-book-to-htmlbook that referenced this issue Jan 4, 2023
This is a first pass at handling jupyter book-style bibliographies.
There are a number of compromises made but we'll get to that.

As a commit:

* This adds tests around both end-of-book bibliographies as
  well as end-of-chapter and end-of-chapter-part-file bibliographies, as
  well as code to pass those tests.

* There was a small refactor in the
  `chapter_processing`-type functions to yank out the code that ultimately
  went into `get_main_section()` to avoid duplication. A chapter-file
  bibliography gets added as its own section, so we needed a way to
  capture that and doing it in one function as opposed to in both the
  chapter and chapter part processing functions made more sense.

* HTMLBook bibliographies are appendixes, so that data-type is added
  when the bib is a single file.

* The actual handling of the bibliography happens in the
  `process_citations` function, which rips out the <dt> pointers and leaves
  only the <dd> citations. Handling the actual citations to these
  bibliographical references will come in a later commit.

Some notes and caveats:

* There is not a good way to reformat the citations in this script. The
  way to do it would be to modify the Bibtex formatting, but that feels
  outside the scope of our current work. This means that bibliographies
  will have to be worked on after intake; this feels like an OK
  compromise for the time being.

  Should we go down that path, there is some discussion [here](link),
  and related [here](other_link).

* Since we don't really have a good way to modify the bibliographical
  entries themselves, we likewise don't have a great way to organize
  combined bibliographies from multiple chapter sub-files. Right now
  we're doing a sort of "dumb" combine, appending one to the other
  (i.e., we're not sorting them in any way). While we could do some list
  sorting, I'm not confident it would be good enough or that the data
  will be standard enough to really do that in a reliable way, so for
  now this compromise feels not _great_ but worthwhile.

* As mentioned, handling for the citations themselves will come in a
  subsequent commit.

Sadly, we're starting to get to the brittler points wherein I'm
beginning to think that we ought to instead be writing some kind of a
backend against Jupyter Book/Sphinx like we do for asciidoc, but we're
in this far, so we'll just need to keep on top of Jupyter Book updates
and be careful about targeted version(s). This commit tries to honor
making the script "just work" while compromising enough that hopefully
what work done here is relatively durable (i.e., not making too much
assumptions about the formatting of things outside of the document
structure itself, which _in theory_ is going to be relatively stable
going forward.

link: jupyter-book/jupyter-book#1090
other_link: mcmtroffaes/sphinxcontrib-bibtex#203
delfanbaum added a commit to oreillymedia/jupyter-book-to-htmlbook that referenced this issue Jan 5, 2023
This is a first pass at handling jupyter book-style bibliographies.
There are a number of compromises made but we'll get to that.

As a commit:

* This adds tests around both end-of-book bibliographies as
  well as end-of-chapter and end-of-chapter-part-file bibliographies, as
  well as code to pass those tests.

* There was a small refactor in the
  `chapter_processing`-type functions to yank out the code that ultimately
  went into `get_main_section()` to avoid duplication. A chapter-file
  bibliography gets added as its own section, so we needed a way to
  capture that and doing it in one function as opposed to in both the
  chapter and chapter part processing functions made more sense.

* HTMLBook bibliographies are appendixes, so that data-type is added
  when the bib is a single file.

* The actual handling of the bibliography happens in the
  `process_citations` function, which rips out the <dt> pointers and leaves
  only the <dd> citations. Handling the actual citations to these
  bibliographical references will come in a later commit.

Some notes and caveats:

* There is not a good way to reformat the citations in this script. The
  way to do it would be to modify the Bibtex formatting, but that feels
  outside the scope of our current work. This means that bibliographies
  will have to be worked on after intake; this feels like an OK
  compromise for the time being.

  Should we go down that path, there is some discussion [here](link),
  and related [here](other_link).

* Since we don't really have a good way to modify the bibliographical
  entries themselves, we likewise don't have a great way to organize
  combined bibliographies from multiple chapter sub-files. Right now
  we're doing a sort of "dumb" combine, appending one to the other
  (i.e., we're not sorting them in any way). While we could do some list
  sorting, I'm not confident it would be good enough or that the data
  will be standard enough to really do that in a reliable way, so for
  now this compromise feels not _great_ but worthwhile.

* As mentioned, handling for the citations themselves will come in a
  subsequent commit.

Sadly, we're starting to get to the brittler points wherein I'm
beginning to think that we ought to instead be writing some kind of a
backend against Jupyter Book/Sphinx like we do for asciidoc, but we're
in this far, so we'll just need to keep on top of Jupyter Book updates
and be careful about targeted version(s). This commit tries to honor
making the script "just work" while compromising enough that hopefully
what work done here is relatively durable (i.e., not making too much
assumptions about the formatting of things outside of the document
structure itself, which _in theory_ is going to be relatively stable
going forward.

link: jupyter-book/jupyter-book#1090
other_link: mcmtroffaes/sphinxcontrib-bibtex#203

Update: check for existance of lis after processing
delfanbaum added a commit to oreillymedia/jupyter-book-to-htmlbook that referenced this issue Jan 5, 2023
This is a first pass at handling jupyter book-style bibliographies.
There are a number of compromises made but we'll get to that.

As a commit:

* This adds tests around both end-of-book bibliographies as
  well as end-of-chapter and end-of-chapter-part-file bibliographies, as
  well as code to pass those tests.

* There was a small refactor in the
  `chapter_processing`-type functions to yank out the code that ultimately
  went into `get_main_section()` to avoid duplication. A chapter-file
  bibliography gets added as its own section, so we needed a way to
  capture that and doing it in one function as opposed to in both the
  chapter and chapter part processing functions made more sense.

* HTMLBook bibliographies are appendixes, so that data-type is added
  when the bib is a single file.

* The actual handling of the bibliography happens in the
  `process_citations` function, which rips out the <dt> pointers and leaves
  only the <dd> citations. Handling the actual citations to these
  bibliographical references will come in a later commit.

Some notes and caveats:

* There is not a good way to reformat the citations in this script. The
  way to do it would be to modify the Bibtex formatting, but that feels
  outside the scope of our current work. This means that bibliographies
  will have to be worked on after intake; this feels like an OK
  compromise for the time being.

  Should we go down that path, there is some discussion [here](link),
  and related [here](other_link).

* Since we don't really have a good way to modify the bibliographical
  entries themselves, we likewise don't have a great way to organize
  combined bibliographies from multiple chapter sub-files. Right now
  we're doing a sort of "dumb" combine, appending one to the other
  (i.e., we're not sorting them in any way). While we could do some list
  sorting, I'm not confident it would be good enough or that the data
  will be standard enough to really do that in a reliable way, so for
  now this compromise feels not _great_ but worthwhile.

* As mentioned, handling for the citations themselves will come in a
  subsequent commit.

Sadly, we're starting to get to the brittler points wherein I'm
beginning to think that we ought to instead be writing some kind of a
backend against Jupyter Book/Sphinx like we do for asciidoc, but we're
in this far, so we'll just need to keep on top of Jupyter Book updates
and be careful about targeted version(s). This commit tries to honor
making the script "just work" while compromising enough that hopefully
what work done here is relatively durable (i.e., not making too much
assumptions about the formatting of things outside of the document
structure itself, which _in theory_ is going to be relatively stable
going forward.

link: jupyter-book/jupyter-book#1090
other_link: mcmtroffaes/sphinxcontrib-bibtex#203

Update: check for existance of lis after processing
delfanbaum added a commit to oreillymedia/jupyter-book-to-htmlbook that referenced this issue Jan 5, 2023
This is a first pass at handling jupyter book-style bibliographies.
There are a number of compromises made but we'll get to that.

As a commit:

* This adds tests around both end-of-book bibliographies as
  well as end-of-chapter and end-of-chapter-part-file bibliographies, as
  well as code to pass those tests.

* There was a small refactor in the
  `chapter_processing`-type functions to yank out the code that ultimately
  went into `get_main_section()` to avoid duplication. A chapter-file
  bibliography gets added as its own section, so we needed a way to
  capture that and doing it in one function as opposed to in both the
  chapter and chapter part processing functions made more sense.

* HTMLBook bibliographies are appendixes, so that data-type is added
  when the bib is a single file.

* The actual handling of the bibliography happens in the
  `process_citations` function, which rips out the <dt> pointers and leaves
  only the <dd> citations. Handling the actual citations to these
  bibliographical references will come in a later commit.

Some notes and caveats:

* There is not a good way to reformat the citations in this script. The
  way to do it would be to modify the Bibtex formatting, but that feels
  outside the scope of our current work. This means that bibliographies
  will have to be worked on after intake; this feels like an OK
  compromise for the time being.

  Should we go down that path, there is some discussion [here](link),
  and related [here](other_link).

* Since we don't really have a good way to modify the bibliographical
  entries themselves, we likewise don't have a great way to organize
  combined bibliographies from multiple chapter sub-files. Right now
  we're doing a sort of "dumb" combine, appending one to the other
  (i.e., we're not sorting them in any way). While we could do some list
  sorting, I'm not confident it would be good enough or that the data
  will be standard enough to really do that in a reliable way, so for
  now this compromise feels not _great_ but worthwhile.

* As mentioned, handling for the citations themselves will come in a
  subsequent commit.

Sadly, we're starting to get to the brittler points wherein I'm
beginning to think that we ought to instead be writing some kind of a
backend against Jupyter Book/Sphinx like we do for asciidoc, but we're
in this far, so we'll just need to keep on top of Jupyter Book updates
and be careful about targeted version(s). This commit tries to honor
making the script "just work" while compromising enough that hopefully
what work done here is relatively durable (i.e., not making too much
assumptions about the formatting of things outside of the document
structure itself, which _in theory_ is going to be relatively stable
going forward.

link: jupyter-book/jupyter-book#1090
other_link: mcmtroffaes/sphinxcontrib-bibtex#203

Update: check for existance of lis after processing

Update: typo fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants