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

problem with whitespaces around = #53

Closed
HedvigS opened this issue Jan 14, 2022 · 9 comments
Closed

problem with whitespaces around = #53

HedvigS opened this issue Jan 14, 2022 · 9 comments

Comments

@HedvigS
Copy link
Contributor

HedvigS commented Jan 14, 2022

I've discovered that when I have an entry like this:

@book{fassberg2019modern,
  title      = {Languages of the Eastern Section: Great Lakes to Indian Ocean},
author={Fassberg, Steven E},
  lgcode={west2763},
  hhtype={overview},
  pages={632652},
  year={2019},
  publisher={Routledge}
}

I get a table that looks like this from bib2df::bib2df()

CATEGORY BIBTEXKEY ADDRESS ANNOTE AUTHOR BOOKTITLE CHAPTER CROSSREF EDITION EDITOR HOWPUBLISHED INSTITUTION JOURNAL KEY MONTH NOTE NUMBER ORGANIZATION PAGES PUBLISHER SCHOOL SERIES TITLE TYPE VOLUME YEAR AUTHOR..FASSBERG. LGCODE..WEST2763.. HHTYPE..OVERVIEW.. PAGES..632652.. YEAR..2019.. PUBLISHER..ROUTLEDGE.
BOOK fassberg2019modern                                         Languages of the Eastern Section: Great Lakes to Indian Ocean       Fassberg, Steven E west2763 overview 632652 2019 Routledge

I've isolated the problem down to the lack of whitespaces before and after the equal sign at the field assignment. It's an easy fix, I basically just inserted whitespaces before and after every equal sign before a curly bracket, but it was a bit frustrating to debug. Can this be included in the documentation, or fixed?

@agricolamz
Copy link

I've spent half an hour for figuring out that it was spaces, not the uppercase categories...

@HedvigS
Copy link
Contributor Author

HedvigS commented May 13, 2022

I've spent half an hour for figuring out that it was spaces, not the uppercase categories...

Haha oh no! I'm sorry!

@nucleic-acid
Copy link

Hi, could this be fixed by refining the regular expressions in bib2df_gather.R?
Would you accept a pull request on this?

@HedvigS
Copy link
Contributor Author

HedvigS commented Dec 6, 2022

Here's a hacky solution for desperate folks in the meantime ^^

https://hedvigsr.tumblr.com/post/702901773084524544/bib2df-bug-hacky-solution

@nguyentruonglt
Copy link

I have the same problem. But I have a bibtex file with 3000 citation. It's extremely exhausting to add spaces before and after equal signs (=) manually. Do you know any solution to do it automatically? Do R or any tools support us to do it?

@agricolamz
Copy link

The bib-files are plain texts, so you can do with it whatever you want. If I were you, I'd do something like this:

library(tidyverse)

read_lines("your_bib_file.bib") |> 
  str_replace_all("=", " = ") |> # add desired spaces
  str_replace_all("\\s{2,}", " ") |>  # remove double spaces in case you have it
  write_lines("your_bib_file.bib")

I didn't check the code on real files, but I'm pretty confident that it should work.

@HedvigS
Copy link
Contributor Author

HedvigS commented Aug 12, 2023

@nguyentruonglt here's my scripted solution:

Here's a hacky solution for desperate folks in the meantime ^^

https://hedvigsr.tumblr.com/post/702901773084524544/bib2df-bug-hacky-solution

@HedvigS
Copy link
Contributor Author

HedvigS commented Aug 12, 2023

@nguyentruonglt here's my scripted solution:

Here's a hacky solution for desperate folks in the meantime ^^
https://hedvigsr.tumblr.com/post/702901773084524544/bib2df-bug-hacky-solution

This is the function I used:

add_spaces_for_bib2df <- function(bib_fn){

new_fn <- paste0( str_replace(bib_fn, ".bib", ""), "_sep", ".bib")

  read_lines(bib_fn) %>% 
  str_replace_all(regex("\\=\\{"), regex(" \\= \\{")) %>% 
  write_lines(new_fn)
}

@HedvigS
Copy link
Contributor Author

HedvigS commented Apr 3, 2024

@giabaio I'd like to help by adjusting bib2df_gather and adjust one of the regexes and make a PR, like @nucleic-acid suggests. But, I'm struggling a bit with parsing the function and I'm concerned I'd cause problems unknowingly. I've made a suggesting in PR #59

@HedvigS HedvigS closed this as completed Apr 3, 2024
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

No branches or pull requests

4 participants