pbs-assess / csasdown

:book: An R package for creating CSAS reports in PDF or Word format with R Markdown and bookdown
Other
46 stars 16 forks source link

Bad margins for hyperlinks in references of ResDoc #261

Closed DylanMG closed 2 months ago

DylanMG commented 2 months ago

When I go to knit my ResDoc references with hyperlinks run into the margins.

See here: bad-margin

and here for a really bad one! bad-margin2

Not seeing other issues that address this when searching "margins". Link to my index.Rmd can be found here.

seananderson commented 2 months ago

I've seen this before, but I thought we'd resolved this. The demo resdoc doesn't have those margin issues on .bib URLs when I try it (example below). Internally, we replace the href links with \link{url-here}{link-text-here}. So, either you're on an older csasdown or something about your document is breaking that substitution.

i.e., this should work:

@article{swainbenoit2015,
 author = {Swain, D.P. and Benoît, H.P.},
 title = {Extreme increases in natural mortality prevent recovery of collapsed fish populations in a {N}orthwest {A}tlantic ecosystem},
 journal = {Mar. Ecol. Prog. Ser.},
 year = {2015},
 volume = {519},
 url = {https://www.int-res.com/abstracts/meps/v519/p165-182/},
 pages = {165-182}
}

Internally, this is what happens (so, it would be frustrating, but this is one solution)

@article{francis2011,
    author = {R. I. C. C. Francis},
    title = {\link{https://cdnsciencepub.com/doi/abs/10.1139/f2011-025}{Data weighting in statistical fisheries stock assessment models}},
  journal   = {Can. J. Fish. Aquat. Sci.},
    year = {2011},
    Volume = {68},
    Number = {6},
    Pages = {1124-1138},
}
image

Can you try building this example and see if it still happens for you?

demo.zip

DylanMG commented 2 months ago

When importing from Zotero, parts of the title that were in title case were imported like title = {How to write a {{Bad Title}}}, which would make R ignore the spacing of the text in the {{ }}. I just used a little hack title = {How to write a {B}ad {T}itle} and it seems to work. I guess it's an issue with how Zotero imports stuff to R, and then how csasdown renders it?

seananderson commented 2 months ago

Interesting, I didn't realize that. The usual best practice in a .bib file would be

title = {How to write a {Good} {Title}}

I.e., protect the whole word but don't connect them. That should work too, I would think. I didn't realize the stuff in the {} wouldn't wrap here. I'm sure there's some other solution but it's probably over my head.

seananderson commented 2 months ago

If you want my honest answer, I just quickly trash the DOIs and URL lines in my .bib file for CSAS reports (except for the few cases where a link is critical) because I can't be bothered with this type of thing. :)