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

Beautify bibtex #291

Open
thorade opened this issue Apr 28, 2015 · 11 comments
Open

Beautify bibtex #291

thorade opened this issue Apr 28, 2015 · 11 comments

Comments

@thorade
Copy link

thorade commented Apr 28, 2015

Title says it all: Would be nice to be able to beautify Bibtex files so that all braces are aligned.

@Glavin001
Copy link
Owner

It's unlikely I will personally have time to implement this beautifier in Atom Beautify, however I am always accepting Pull Requests.

Here are some potential options for beautifiers that may lead to designing a solution for Atom Beautify:

@Glavin001 Glavin001 changed the title wishlist: beautify bibtex Beautify bibtex Apr 28, 2015
@thorade
Copy link
Author

thorade commented May 4, 2015

Thanks for the links. As I have to beautify only one (large) file, I guess I will also not implement a beautifier right now.
Look like emacs can also format bib files, and biber can also format bib files:
https://tex.stackexchange.com/questions/186733/a-utility-for-auto-formatting-bib-files
https://tex.stackexchange.com/questions/2793/formatting-bibtex-entries-using-auctex
I have both tools installed and hope one of the two will work for me,
so feel free to close this as wont-fix

@Glavin001
Copy link
Owner

I could add biber as a supported beautifier for Bibtex 😄.

Does this command work for you?

biber --tool --output_align --output_indent=2 --output_fieldcase=lower <filename>.bib

Let me know what works for you and I can add support for it so you can stay in Atom and not use the Terminal.

@thorade
Copy link
Author

thorade commented May 4, 2015

Here is a list of options that biber in tool mode knows:

  • --output_align
  • --output_indent=2
  • --output_fieldcase=upper / title / lower
  • --output_safechars
  • --output_encoding=UTF8 / ascii
  • --output_file=filename2.bib
  • --configfile=biber-tool.conf.

Not sure what to use as default for --output_safechars .
I filed some issues with biber that might be relevant here:
plk/biber#67
plk/biber#68
plk/biber#101

@Glavin001 Glavin001 added this to the v0.28.0 milestone May 4, 2015
@Glavin001 Glavin001 self-assigned this May 4, 2015
@thorade
Copy link
Author

thorade commented May 5, 2015

I am not sure if biber is the best choice for pretty printing, so I kept searching and found two more tools, bibtool and bibclean (also see https://tex.stackexchange.com/a/242215/8569).
bibclean is no longer maintained, it seems.
bibtool is actively developedon github: https://github.com/ge-ne/bibtool
I seems to support quite a lot of options, which can be put into a resource file (named .bibtoolrsc).
Here is a copy of my .bibtoolrsc file:

# define input and output files
input references.bib
output.file references.bib

# load additional resource files
resource braces

# pretty printing options in alphabetical order
key.format = short
preserve.keys=on 
preserve.key.case=on
print.align=0
print.align.key=0
print.align.string=0
print.indent=2
print.line.length=999999
print.use.tab=off
print.wide.equal=on
sort = on
suppress.initial.newline=on
verbose = on

For atom-beautify, one might might have to adopt these, e.g. turn off sorting, turn off verbosity, etc

Only disadvantage is that bibtool is hard to install on Windows, because it is distributed as source code only. On Ubuntu installation is as easy as sudo apt-get install bibtool.
https://tex.stackexchange.com/q/180840/8569

@Glavin001 Glavin001 modified the milestones: v0.29.0, v0.28.0 Jun 6, 2015
@Glavin001
Copy link
Owner

See #300 (comment) for how to add a new language and/or beautifier.

Update: I will be maintaining this documentation on adding languages and beautifiers: https://github.com/Glavin001/atom-beautify/blob/master/docs/add-languages-and-beautifiers.md

@Glavin001 Glavin001 modified the milestones: v0.30.0, v0.29.0 Mar 30, 2016
@douglasrizzo
Copy link

AFAIK, latexindent, which is already used to beautify .tex files, also supports .bib files.

@Glavin001
Copy link
Owner

Awesome to hear latexindent may work! All we need is someone to submit a Pull Request with this working and tested. Thanks in advance!

@Glavin001 Glavin001 removed their assignment Jan 1, 2017
@Glavin001 Glavin001 removed the feature label Jan 1, 2017
@Glavin001 Glavin001 modified the milestones: v0.30.0, v0.31.0 Jun 22, 2017
@douglasrizzo
Copy link

douglasrizzo commented Oct 9, 2017

Since this issue is not yet closed, I'd like to recommend BibTool for beautifying .bib files. It has a lot more formatting options than latexindent for .bib files. I have an example of a resource file used to customized the behavior of BibTool over at my Gist.

For example, a bib entry like the following

@article{mnih_human-level_2015,
 title = {Human-level control through deep reinforcement learning},
 volume = {518},
 issn = {0028-0836, 1476-4687},
 url = {https://www.nature.com/doifinder/10.1038/nature14236},
 doi = {10.1038/nature14236},
 pages = {529--533},
 number = {7540},
 journaltitle = {Nature},
 author = {Mnih, Volodymyr and Kavukcuoglu, Koray and Silver, David and Rusu, Andrei A. and Veness, Joel and Bellemare, Marc G. and Graves, Alex and Riedmiller, Martin and Fidjeland, Andreas K. and Ostrovski, Georg and Petersen, Stig and Beattie, Charles and Sadik, Amir and Antonoglou, Ioannis and King, Helen and Kumaran, Dharshan and Wierstra, Daan and Legg, Shane and Hassabis, Demis},
 urldate = {2016-05-12},
 date = {2015-02-25},
 file = {Mnih et al. - 2015 - Human-level control through deep reinforcement lea.pdf:/home/dodo/Zotero/storage/QKDB7DAZ/Mnih et al. - 2015 - Human-level control through deep reinforcement lea.pdf:application/pdf}
}

Is formatted as such by latexindent, apparently without any option for customization

@article{mnih_human-level_2015,
	title = {Human-level control through deep reinforcement learning},
	volume = {518},
	issn = {0028-0836, 1476-4687},
	url = {https://www.nature.com/doifinder/10.1038/nature14236},
	doi = {10.1038/nature14236},
	pages = {529--533},
	number = {7540},
	journaltitle = {Nature},
	author = {Mnih, Volodymyr and Kavukcuoglu, Koray and Silver, David and Rusu, Andrei A. and Veness, Joel and Bellemare, Marc G. and Graves, Alex and Riedmiller, Martin and Fidjeland, Andreas K. and Ostrovski, Georg and Petersen, Stig and Beattie, Charles and Sadik, Amir and Antonoglou, Ioannis and King, Helen and Kumaran, Dharshan and Wierstra, Daan and Legg, Shane and Hassabis, Demis},
	urldate = {2016-05-12},
	date = {2015-02-25},
	file = {Mnih et al. - 2015 - Human-level control through deep reinforcement lea.pdf:/home/user/Zotero/storage/QKDB7DAZ/Mnih et al. - 2015 - Human-level control through deep reinforcement lea.pdf:application/pdf}
}

With BibTool, I can reorder fields, remove braces from numeric fields, rename fields (like urldate to urlaccessdate) and remove fields (like file).

@Article{mnih_human-level_2015,
  title         = {Human-level control through deep reinforcement learning},
  author        = {Mnih, Volodymyr and Kavukcuoglu, Koray and Silver, David and Rusu, Andrei A. and Veness, Joel and Bellemare, Marc G. and Graves, Alex and Riedmiller, Martin and Fidjeland, Andreas
                  K. and Ostrovski, Georg and Petersen, Stig and Beattie, Charles and Sadik, Amir and Antonoglou, Ioannis and King, Helen and Kumaran, Dharshan and Wierstra, Daan and Legg, Shane and
                  Hassabis, Demis},
  volume        = 518,
  pages         = {529--533},
  url           = {https://www.nature.com/doifinder/10.1038/nature14236},
  urlaccessdate = {2016-05-12},
  issn          = {0028-0836, 1476-4687},
  doi           = {10.1038/nature14236},
  number        = 7540,
  journaltitle  = {Nature},
  date          = {2015-02-25}
}

@Glavin001
Copy link
Owner

Pull Requests welcome! See https://github.com/Glavin001/atom-beautify/blob/master/docs/add-languages-and-beautifiers.md#how-to-add-a-beautifier-for-a-language for details. Please feel free to ask questions. The core team is unlikely to implement new beautifiers like this, as we are working on other features, however we are always open to questions! 😃

@thorade
Copy link
Author

thorade commented Oct 9, 2017

@douglasrizzo The only problem I see with bibtool is that the author does not ship Windows binaries:

No com­piled ver­sions are avail­able from the au­thor (Use­less to ask!).

biber does ship binaries for Windows, and they are available in most TeX distributions.

@Glavin001 Glavin001 modified the milestones: v0.31.0, v0.33.0 (Next) Mar 2, 2018
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