ulyngs / oxforddown

Template for writing an Oxford University thesis in R Markdown; uses the OxThesis LaTeX template and was inspired by thesisdown.
https://ulyngs.github.io/oxforddown/
MIT License
220 stars 81 forks source link

In-text citation formatting inconsistent #62

Closed JanaMuschinski closed 1 year ago

JanaMuschinski commented 1 year ago

Love the template and package, thanks for putting so much work in!

I have been having trouble with in-line citation formatting.

No problem with this entry - shows up as "(Mercier et al. 2017)" in text (so when I use [@mercier2017])

@article{mercier2017,
    title = {Vervet monkeys greet adult males during high-risk situations},
    author = {Mercier, {Stéphanie} and Neumann, Christof and van de Waal, Erica and Chollet, Emmeline and Meric de Bellefon, Jade and {Zuberbühler}, Klaus},
    year = {2017},
    month = {10},
    date = {2017-10},
    journal = {Animal Behaviour},
    pages = {229--245},
    volume = {132},
    doi = {10.1016/j.anbehav.2017.07.021},
    url = {https://linkinghub.elsevier.com/retrieve/pii/S0003347217302336},
    langid = {en}
}

Too many names before et al. - This one on the other hand shows up as "(De Marco, Cozzolino, et al. 2011)" when I use [@demarco2011].

@article{demarco2011,
    title = {Collective arousal when reuniting after temporary separation in Tonkean macaques},
    author = {De Marco, Arianna and Cozzolino, Roberto and {Dessì-Fulgheri}, Francesco and Thierry, Bernard},
    year = {2011},
    date = {2011},
    journal = {American Journal of Physical Anthropology},
    pages = {457--464},
    volume = {146},
    number = {3},
    doi = {10.1002/ajpa.21606},
    url = {https://onlinelibrary.wiley.com/doi/abs/10.1002/ajpa.21606},
    note = {{\_}eprint: https://onlinelibrary.wiley.com/doi/pdf/10.1002/ajpa.21606},
    langid = {en}
}

I tried putting {} around "De Marco" and it still persists. Same issue in another De Marco citation and a bunch of other citations that have single-word last names, but weirdly not in others. I cannot find a pattern.

I've also found other instances where sources with three authors had all three listed. I really have no idea what is going on unfortunately.

Index file

The index file has the following as per the template. I have tried running it with natbib and it will not compile. The error it gives when attempting to use natbib is below.

# biblatex options #
# unless you run into 'biber' error messages, use biblatex as it lets you customise your bibliography directly
use-biblatex: true
bib-latex-options: "style=authoryear, sorting=nyt, backend=biber, maxcitenames=2, useprefix, doi=true, isbn=false, uniquename=false" #for science, you might want style=numeric-comp, sorting=none for numerical in-text citation with references in order of appearance

# natbib options #
# natbib runs into fewer errors than biblatex, but to customise your bibliography you need to fiddle with .bst files
use-natbib: false # to use natbib, set this to true, and change "output:bookdown::pdf_book:citation_package:" to "natbib"
natbib-citation-style: authoryear #for science, you might want numbers,square
natbib-bibliography-style: templates/ACM-Reference-Format.bst #e.g. "plainnat", unsrtnat, or path to a .bst file

Natbib error:

! Undefined control sequence.
l.339 ...esting of cooperative potential \autocite
                                                  {dalpesco2020,Eibl-Eibesfe... 

Error: LaTeX failed to compile _main.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See _main.log for more info.
In addition: Warning message:
Warning: fonts used in `flextable` are ignored because the `pdflatex` engine is used and not `xelatex` or `lualatex`. You can avoid this warning by using the `set_flextable_defaults(fonts_ignore=TRUE)` command or use a compatible engine by defining `latex_engine: xelatex` in the YAML header of the R Markdown document. 
Execution halted

The flextable warning is fine - but I'm not sure what's happening above that. There is one point in the text where the phrase "testing of cooperative potential" is used, but those citations do not come after it and there is no where in the text where those two citations happen together.

When I compile the whole thing to Word rather than a PDF, the De Marco citations show up fine, as do all the others it looks like. However, citations of up to three names remain as three full names rather than being shortened to First et al.

Thank you for any help!! I am meant to submit my CoS this week and the citations are really throwing me some curve balls.

Bookdown version 0.26 Tinytex version 0.41 R studio version 2022.07.1 Build 554 R version

JanaMuschinski commented 1 year ago

Further update - I went back to your index file on the repository and saw there were some differences in the citation section, so replaced everything about bibliography/citations down to the end in my index file with the most up to date version from yours. Biblatex is still the only option compiling, pandoc and natbib are not. The issue continues with biblatex.

Updated index file section:

######################
## bibliography path ##
#######################
bibliography: [bibliography/test.bib]

########################
## PDF layout options ###
#########################
### submitting a master's thesis ###
# set masters-submission: true for an alternative, anonymous title page with 
# candidate number and word count
masters-submission: false
candidate-number: 123456
word-count: "10,052"

# if you want to use a different title page altogether, provide a path to a 
# .tex file here and it will override the default Oxford one
# alternative-title-page: templates/alt-title-page-example.tex

### abbreviations ###
abbreviations-width: 3.2cm
abbreviations-heading: List of Abbreviations

### citation and bibliography style ###
# heading title for the references section
params:
  insertReferencesHeadingInPDF: true
  insertReferencesHeadingInOtherOutput: true
  referenceHeading: "References"

# citation and reference options (pandoc) #
csl: bibliography/apa.csl # try csl: bibliography/transactions-on-computer-human-interaction.csl for numerical citations
refs-line-spacing: 6mm
refs-space-between-entries: 1mm

## biblatex options ##
#use-biblatex: true # set to true, and set "output:bookdown::pdf_book: citation_package: biblatex"
#bib-latex-options: "style=authoryear, sorting=nyt, backend=biber, maxcitenames=2, useprefix, doi=true, isbn=false, uniquename=false" #for science, you might want style=numeric-comp, sorting=none for numerical in-text citation with references in order of appearance

## natbib options ##
#use-natbib: true # set to true, and set "output:bookdown::pdf_book: citation_package: natbib"
#natbib-citation-style: authoryear #for science, you might want numbers,square
#natbib-bibliography-style: templates/ACM-Reference-Format.bst #e.g. "plainnat", unsrtnat, or path to a .bst file

### correction highlighting ###
corrections: true

# and the rest of the index file...

When compiling with pandoc:

I made sure I had the apa.csl file in my bibliography folder.

It won't compile with just pandoc - it gives the following error: "! LaTeX Error: Command \bibfont undefined."

The _main.log file says the following:

! LaTeX Error: Command \bibfont undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.178 \renewcommand*{\bibfont}
                              {\raggedright\small}

When trying with biblatex

I made sure to change the citation_package under output as well. It compiles but continues to have the issue and gives the following messages:


Warning: Package inputenc Warning: inputenc package ignored with utf8 based engines.
Warning: Package fancyhdr Warning: \fancyhead's `E' option without twoside option is useless on input line 131.
Warning: LaTeX Warning: Command \@parboxrestore  has changed.
Warning:                Check if current package is valid.
Warning: Package fvextra Warning: csquotes should be loaded after fvextra, to avoid a warning from the lineno package on input line 37.
Warning: Package biblatex Warning: Language 'latin' not supported.
Warning: (biblatex)                Using dummy definitions on input line 217.

When trying with Natbib:

It does not compile and gives the following:

Error: Failed to build the bibliography via bibtex
In addition: Warning message:
bibtex seems to have failed:

This is BibTeX, Version 0.99d (TeX Live 2022)
Capacity: max_strings=200000, hash_size=200000, hash_prime=170003
The top-level auxiliary file: _main.aux
The style file: templates/ACM-Reference-Format.bst.bst
Case mismatch error between cite keys Colmenares1991 and colmenares1991
---line 317 of file _main.aux
 : \citation{dalpesco2020,colmenares1991,Colmenares1991
 :                                                     ,dalpesco2018,Smuts1990}
I'm skipping whatever remains of this command
Case mismatch error between cite keys Colmenares1991 and colmenares1991
---line 320 of file _main.aux
 : \citation{Pelaez1982,Colmenares1990,colmenares1991,Colmenares1991
 :                                                                  ,Fraser2007,kummer1968}
I'm skipping whatever remains of this command
Case mismatch error between cite keys Colmenares1991 and colmenares1991
---line 565 of file _main.aux
 : \citation{Colmenares1990,Colmenares1991
 :                        [... truncated] 
Warning: Package inputenc Warning: inputenc package ignored with utf8 based engines.
Warning: Package fancyhdr Warning: \fancyhead's `E' option without twoside option is useless on input line 131.
Warning: LaTeX Warning: Command \@parboxrestore  has changed.
Warning:                Check if current package is valid.
Warning: Package fvextra Warning: csquotes should be loaded after fvextra, to avoid a warning from the lineno package on input line 37.
Warning: Package minitoc Warning: W0010
Warning: (minitoc)                No file _main.toc. 
Warning: (minitoc)                MINITOCS NOT PREPARED on input line 289.
Warning: Package natbib Warning: Citation `dalpesco2020' on page 1 undefined on input line 341.

And then continues to list off a warning for every single citation.

I spoke with a friend today who is using the template and she also has the same issues with in-text citation inconsistencies.

I've tried to look into the error messages, but am unfortunately quite new to csl and LaTeX so am struggling.

Thanks for any help!

JanaMuschinski commented 1 year ago

Issue solved! Hope this may help someone else in the future.

I replaced my index page and templates with the most recent ones on the repository. It would then run with pandoc again instead of only biblatex, but the problem persisted, but only in specific circumstances.

After much combing through my .bib file I realized three things:

  1. If there are two "X et al." publications from the same year it will include the second author in the in-text citation to differentiate between them rather than adding an a/b to the year.
  2. If you have multiple citations from the same author, double check that the first and middle name are all entered in exactly the same way, otherwise it will think they are different authors and use initials to differentiate them. If there are actually two authors with the same last name, it will use initials to differentiate in in-text citations.
  3. Check the .bib file for stray punctuation between author names - a stray comma between author names instead of being separated by "and" as they should be caused a lot of grief.