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

LaTeX template: fix \CSLRightInline vertical space #9058

Closed
wants to merge 1 commit into from
Closed

LaTeX template: fix \CSLRightInline vertical space #9058

wants to merge 1 commit into from

Conversation

jpcirrus
Copy link
Contributor

@jpcirrus jpcirrus commented Sep 4, 2023

When using a CSL stylesheet with the citation-number attribute e.g. nature, when \CSLRightInline is only one line currently extraneous vertical space is added.

When using a CSL stylesheet with the `citation-number` attribute e.g. `nature`, when `\CSLRightInline` is only one line currently extraneous vertical space is added.
@jpcirrus
Copy link
Contributor Author

jpcirrus commented Sep 4, 2023

Currently, with indent: false, when \CSLRightInline is only one line, then the output has extraneous vertical space below that bibitem:

image

this change matches the document paragraph spacing:

image

and currently with indent: true:

20230905T101927-PDF Expert@2x

which this change corrects to:

20230905T102024-PDF Expert@2x

I have tested with the standard classes as well as with the KOMA-Script, APA and beamer classes.

Test file:

---
# indent: true
csl: nature
references:
- type: article-journal
  id: WatsonCrick1953
  author:
  - family: Watson
    given: J. D.
  issued:
    date-parts:
    - - 1953
      - 4
      - 25
  title: 'Molecular'
  container-title: Nature
  volume: 171
  issue: 4356
  page: 737-738
  DOI: 10.1038/171737a0
  note: Note this!
- id: francois2014
  type: article-journal
  title: >-
    ‘Exercise snacks’ before meals: a novel strategy to improve glycaemic
    control in individuals with insulin resistance
  container-title: Diabetologia
  page: 1437-1445
  volume: '57'
  issue: '7'
  DOI: 10.1007/s00125-014-3244-6
  author:
    - family: Williams
      given: Michael J. A.
    - family: Francois
      given: Monique E.
    - family: Baldi
      given: James C.
    - family: Manning
      given: Patrick J.
    - family: Lucas
      given: Samuel J. E.
    - family: Hawley
      given: John A.
    - family: Cotter
      given: James D.
  issued:
    date-parts:
      - - 2014
nocite: |
  @*
...

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.

\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1\\[-1.7ex]}}
Copy link
Owner

Choose a reason for hiding this comment

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

Can you explain why this change fixes the problem?

Copy link
Contributor Author

@jpcirrus jpcirrus Sep 5, 2023

Choose a reason for hiding this comment

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

To determine where the additional vertical space was coming from I wrapped the \parbox{} in an \fbox{}. This indicated that it was from the \break outside the \parbox. By moving that inside the \parbox results were consistent regardless of bibitem length, but without negative adjustment were too large. By iteration arrived at the value of -1.7ex. I had previously been using a custom template with \break replaced by \\[-0.7ex] to get spacing that matched the document. Technically why, I don't know.

Copy link
Owner

Choose a reason for hiding this comment

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

It just seems a bit "magic" and unprincipled...I wonder if there's a better way?

Copy link
Owner

Choose a reason for hiding this comment

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

What about just removing the \break? Is it needed?
It seems to work fine without it and I don't get the extra space.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

During my testing I had initially tried that, but when using a more complex document using article and scrartcl the linespacing was removed between bibitems:


20230905T141943-PDF Expert@2x
20230905T141542-PDF Expert@2x

but having used the above input file with article, scrartcl, apa6 (with the man class option) and beamer it works correctly, so there must be something (not obvious) in that document which is causing the issue which I will sort out.

Copy link
Owner

Choose a reason for hiding this comment

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

OK, done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm wondering whether, when entry spacing is set to 0, we should just use \parskip instead of actually using 0? In a document that has a \parskip of 6pt (default for pandoc), the bibliography may look odd with 0 space between entries. But maybe that's too opinionated a divergence.

No. I think it would be incorrect in terms of the CSL spec. I believe the current implementation is accurate.

With entry-spacing="0" and \setlength{\itemsep}{#2\baselineskip}}}:

20230908T103846-PDF Expert@2x

and entry-spacing="0" and \setlength{\itemsep}{\parskip}}}:

20230908T103936-PDF Expert@2x

The spacing is approaching what it is when entry-spacing="1". The paragraph spacing has nothing to do with the entry spacing, which had me confused until I read the spec more carefully

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, I agree it's more accurate this way. I just think it's a bit awkward that, with the default 6pt parskip that pandoc gives you without indent, you have a choice between a bigger or a smaller space between bib entries, but no way to get the same...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually prefer the way it is 😃.

20230908T160345-PDF Expert@2x

This is going to be the case with all documents where entry-spacing="0" and indent: false, regardless if using a KOMA class, the parskip package, or the pandoc default of 6pt plus 2pt minus 1pt. In my custom template I used to have the entry-spacing depend on indent. But, I was wrong, due to my ignorance from not having read the spec, assuming 0 meant zero spacing (not zero additional spacing), 1 was line spacing (actually 0)... and which clearly others do too e.g. #7296. But, I can appreciate the visual appeal:

20230908T160629-PDF Expert@2x

rather than moving up to entry-spacing="1":

20230908T160659-PDF Expert@2x

However, if you decide to implement this please don't make it the default, but rather an option, or better yet as a filter, so that at least the default is compliant with the spec. Of course, for those wanting something special, it is always possible to use header-includes:

\usepackage{etoolbox}
\AtBeginEnvironment{CSLReferences}[\setlength{\itemsep}{ANYTHING YOU WISH}

I have completed testing the latex CSL functionality. I have tested with the KOMA, APA, and standard classes, together with beamer. All combinations of linespacing (single, onehalf and double) work correctly with entry-spacing values of 0, 1 and 2, using bibliographies of approx 50–200 items. Thanks very much for your efforts with this, I am really happy with the results.

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks very much for the extensive testing! I'll close this.

jgm added a commit that referenced this pull request Sep 7, 2023
- Add a strut to avoid inconsistencies in spacing.
- Remove a break at the end of CSLRightInline to avoid
  inconsistencies in spacing. It shouldn't be necessary
  because the paragraph should extend to the right margin.

See #9058.
jgm added a commit that referenced this pull request Sep 7, 2023
According to the CSL manual, the default entry spacing is 1.
We were treating it as 0.

T.P.Citeproc:  always include an entry-spacing attribute
in the Div if the bibliography element contains an entry-spacing
attribute (previously we omitted it when it was 0).

LaTeX writer: use entry spacing 1 if no entry-spacing
attribute is present.

Update tests.

See #9058.
jgm added a commit that referenced this pull request Sep 7, 2023
jgm added a commit that referenced this pull request Sep 7, 2023
@jgm jgm closed this Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants