inukshuk / bibtex-ruby

A BibTeX library, parser, and converter for Ruby.
http://inukshuk.github.com/bibtex-ruby
GNU General Public License v3.0
156 stars 31 forks source link

Braces not removed #41

Closed tnhh closed 12 years ago

tnhh commented 12 years ago

I have only just come across this project so excuse me if I have missed something obvious. How do I remove braces from BibTeX entries? e.g., given a file nasa.bib containing

@Article{nasa,
    author = {Neil Armstrong},
    title = {I was a {NASA} astronaut},
    journal = {Journal of {CAPITALISATION}},
    year = 2011
}

the code

require 'bibtex'
require 'citeproc'
bib = BibTeX.open('nasa.bib')
CiteProc.process bib.to_citeproc, :style => 'apa'

gives

"Armstrong, N. (2011). I was a {NASA} astronaut. Journal of {CAPITALISATION}."

whereas I would have expected to see

"Armstrong, N. (2011). I was a NASA astronaut. Journal of CAPITALISATION."

which is what BibTeX gives me. I am not familiar with citeproc so I don't know if the problem is in bibtex-ruby or citeproc-ruby. Any help would be appreciated.

inukshuk commented 12 years ago

The braces in BibTeX entries are typically part of LaTeX directives (just as in your example). We're not processing LaTeX in bibtex-ruby by default because many users do not require it, but there's a filter you can use.

require 'bibtex'

BibTeX.parse(DATA) do |bib|
  puts bib[:nasa].title

  bib.convert :latex

  puts bib[:nasa].title
end

__END__
@Article{nasa,
   author = {Neil Armstrong},
   title = {I was a {NASA} astronaut},
   journal = {Journal of {CAPITALISATION}},
   year = 2011
}

This should give you the following output:

I was a {NASA} astronaut
I was a NASA astronaut

As you can see, braces are automatically stripped when using the LaTeX converter. Additionally, the filter will convert many LaTeX directives to unicode. You should also be able to apply the filter when parsing by using the :filter option. For example:

BibTeX.open 'nasa.bib', :filter => :latex

Hope that helps!

tnhh commented 12 years ago

Thanks for the quick reply! How curious that LaTeX output is not the default - I would have assumed that most BibTeX users would also want their LaTeX directives processed. I now have some HTML output issues but I think that those are citeproc-ruby issues, not bibtex-ruby.

inukshuk commented 12 years ago

Since we moved the latex filter to a separate gem, the rationale was to not make it the default, in order to not force the additional dependency. Other than that, you're right, of course, it would make a sensible default option.

citeproc-ruby probably produces HTML output, but you can turn that off and use plain text instead (you will not have italics and similar style features in that case though).