bibtex-ruby 6.0.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -4
- data/History.txt +40 -0
- data/README.md +313 -256
- data/bibtex-ruby.gemspec +2 -1
- data/features/support/env.rb +2 -2
- data/lib/bibtex/name_parser.rb +66 -64
- data/lib/bibtex/names.rb +1 -1
- data/lib/bibtex/parser.rb +25 -23
- data/lib/bibtex/version.rb +1 -1
- data/test/bibtex/test_utilities.rb +1 -1
- data/test/helper.rb +1 -6
- data/test/test_bibtex.rb +1 -1
- data/test/test_export.rb +1 -1
- metadata +21 -7
data/README.md
CHANGED
@@ -24,50 +24,62 @@ Install and load BibTeX-Ruby in an IRB session:
|
|
24
24
|
|
25
25
|
Open a BibTeX bibliography:
|
26
26
|
|
27
|
-
|
27
|
+
```ruby
|
28
|
+
b = BibTeX.open('./ruby.bib')
|
29
|
+
```
|
28
30
|
|
29
31
|
Select a BibTeX entry and access individual fields:
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
```ruby
|
34
|
+
b['pickaxe'].title
|
35
|
+
#=> "Programming Ruby 1.9: The Pragmatic Programmer's Guide"
|
36
|
+
b[:pickaxe].author.length
|
37
|
+
#=> 3
|
38
|
+
b[:pickaxe].author.to_s
|
39
|
+
#=> "Thomas, D. and Fowler, Chad and Hunt, Andy"
|
40
|
+
b[:pickaxe].author[2].first
|
41
|
+
#=> "Andy"
|
42
|
+
```
|
39
43
|
|
40
44
|
Query a bibliography:
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
```ruby
|
47
|
+
b['@book'].length
|
48
|
+
#=> 3 - the number books in the bibliography
|
49
|
+
b['@article'].length
|
50
|
+
#=> 0 - the number of articles in the bibliography
|
51
|
+
b['@book[year=2009]'].length
|
52
|
+
#=> 1 - the number of books published in 2009
|
53
|
+
```
|
48
54
|
|
49
55
|
Extend first name initials throughout your bibliography:
|
50
56
|
|
51
|
-
|
52
|
-
|
53
|
-
|
57
|
+
```ruby
|
58
|
+
b.extend_initials ['Dave', 'Thomas']
|
59
|
+
b[:pickaxe].author.to_s
|
60
|
+
#=> "Thomas, Dave and Fowler, Chad and Hunt, Andy"
|
61
|
+
```
|
54
62
|
|
55
63
|
You can also extend all names in the bibliography to their prototypical
|
56
64
|
(i.e., the longest available) form:
|
57
65
|
|
58
|
-
|
66
|
+
```ruby
|
67
|
+
b.extend_initials! #=> extends all names in the bibliography
|
68
|
+
```
|
59
69
|
|
60
70
|
Use with caution as this method will treat two names as identical if they
|
61
71
|
look the same in their `#sort_order(:initials => true)` form.
|
62
72
|
|
63
73
|
Unify certain fields across the bibliography:
|
64
74
|
|
65
|
-
|
75
|
+
```ruby
|
76
|
+
b.unify :publisher, /o'?reilly/i, "O'Reilly"
|
66
77
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
78
|
+
b.unify :publisher, /^penguin/i do |entry|
|
79
|
+
entry.publisher = 'Penguin Books'
|
80
|
+
entry.address = 'London'
|
81
|
+
end
|
82
|
+
```
|
71
83
|
|
72
84
|
This will unify various spellings of entries published by O'Reilly and Penguin.
|
73
85
|
|
@@ -75,24 +87,24 @@ Render your bibliography in one of
|
|
75
87
|
[many different citation styles](https://github.com/citation-style-language/styles)
|
76
88
|
(requires the **citeproc-ruby** gem):
|
77
89
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
Guide. Raleigh, North Carolina: The Pragmatic Bookshelf, 2009."
|
90
|
+
```ruby
|
91
|
+
require 'citeproc'
|
92
|
+
CiteProc.process b[:pickaxe].to_citeproc, :style => :apa
|
93
|
+
#=> "Thomas, D., Fowler, C., & Hunt, A. (2009). Programming Ruby 1.9: The Pragmatic Programmer's Guide. The Facets of Ruby. Raleigh, North Carolina: The Pragmatic Bookshelf."
|
94
|
+
CiteProc.process b[:pickaxe].to_citeproc, :style => 'chicago-author-date'
|
95
|
+
#=> "Thomas, Dave, Chad Fowler, and Andy Hunt. 2009. Programming Ruby 1.9: The Pragmatic Programmer's Guide. The Facets of Ruby.Raleigh, North Carolina: The Pragmatic Bookshelf."
|
96
|
+
CiteProc.process b[:pickaxe].to_citeproc, :style => :mla
|
97
|
+
#=> "Thomas, Dave, Chad Fowler, and Andy Hunt. Programming Ruby 1.9: The Pragmatic Programmer's Guide. Raleigh, North Carolina: The Pragmatic Bookshelf, 2009."
|
98
|
+
```
|
88
99
|
|
89
100
|
Save a bibliography to a file:
|
90
101
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
102
|
+
```ruby
|
103
|
+
b.save
|
104
|
+
#=> saves the original file
|
105
|
+
b.save_to(file)
|
106
|
+
#=> saves the bibliography in a new file
|
107
|
+
```
|
96
108
|
|
97
109
|
Compatibility
|
98
110
|
-------------
|
@@ -106,6 +118,8 @@ Starting with BibTeX-Ruby version 3.0, support for Ruby versions 1.9.2 and
|
|
106
118
|
earlier has been dropped; most features will likely continue to work, but
|
107
119
|
compliance with old Rubies is not a priority going forward.
|
108
120
|
|
121
|
+
Starting with BibTex-Ruby version 7.0, only ruby versions still in "security maintenance phase" will be supported.
|
122
|
+
This is, as of writing Ruby 2.7 and up.
|
109
123
|
|
110
124
|
Documentation
|
111
125
|
-------------
|
@@ -119,16 +133,18 @@ everything, simply add `:include => [:meta_content]` to your invocation of
|
|
119
133
|
Once BibTeX-Ruby has parsed your '.bib' file, you can easily access individual
|
120
134
|
entries. For example, if you set up your bibliography as follows:
|
121
135
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
136
|
+
```ruby
|
137
|
+
b = BibTeX.parse <<-END
|
138
|
+
@book{pickaxe,
|
139
|
+
address = {Raleigh, North Carolina},
|
140
|
+
author = {Thomas, Dave and Fowler, Chad and Hunt, Andy},
|
141
|
+
publisher = {The Pragmatic Bookshelf},
|
142
|
+
series = {The Facets of Ruby},
|
143
|
+
title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
|
144
|
+
year = {2009}
|
145
|
+
}
|
146
|
+
END
|
147
|
+
```
|
132
148
|
|
133
149
|
You could easily access it, using the entry's key, 'pickaxe', like so:
|
134
150
|
`b[:pickaxe]`; you also have easy access to individual fields, for example:
|
@@ -147,31 +163,36 @@ problem with a field's value, simply convert it to a string by calling the
|
|
147
163
|
Instead of parsing strings you can also create BibTeX elements directly in
|
148
164
|
Ruby:
|
149
165
|
|
150
|
-
|
166
|
+
```ruby
|
167
|
+
bib = BibTeX::Bibliography.new
|
168
|
+
```
|
151
169
|
|
152
170
|
Using a Hash:
|
153
171
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
172
|
+
```ruby
|
173
|
+
bib << BibTeX::Entry.new({
|
174
|
+
:bibtex_type => :book,
|
175
|
+
:key => :rails,
|
176
|
+
:address => 'Raleigh, North Carolina',
|
177
|
+
:author => 'Ruby, Sam and Thomas, Dave, and Hansson, David Heinemeier',
|
178
|
+
:booktitle => 'Agile Web Development with Rails',
|
179
|
+
:edition => 'third',
|
180
|
+
:keywords => 'ruby, rails',
|
181
|
+
:publisher => 'The Pragmatic Bookshelf',
|
182
|
+
:series => 'The Facets of Ruby',
|
183
|
+
:title => 'Agile Web Development with Rails',
|
184
|
+
:year => '2009'
|
185
|
+
})
|
186
|
+
```
|
167
187
|
|
168
188
|
Or programmatically:
|
169
189
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
190
|
+
```ruby
|
191
|
+
book = BibTeX::Entry.new
|
192
|
+
book.type = :book
|
193
|
+
book.key = :mybook
|
194
|
+
bib << book
|
195
|
+
```
|
175
196
|
|
176
197
|
### Cross References
|
177
198
|
|
@@ -181,24 +202,25 @@ and `inproceedings`. When an entry has a valid citation key in the field
|
|
181
202
|
`crossref`, BibTeX-Ruby will return any fields inherited from the parent
|
182
203
|
entry:
|
183
204
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
205
|
+
```ruby
|
206
|
+
b = BibTeX.parse <<-END
|
207
|
+
@inbook{fraassen_1989b,
|
208
|
+
Crossref = {fraassen_1989},
|
209
|
+
Pages = {40-64},
|
210
|
+
Title = {Ideal Science: David Lewis's Account of Laws},
|
211
|
+
}
|
212
|
+
|
213
|
+
@book{fraassen_1989,
|
214
|
+
Address = {Oxford},
|
215
|
+
Author = {Bas C. van Fraassen},
|
216
|
+
Publisher = {Oxford University Press},
|
217
|
+
Title = {Laws and Symmetry},
|
218
|
+
Year = 1989
|
219
|
+
}
|
220
|
+
END
|
221
|
+
> b['fraassen_1989b'].booktitle
|
222
|
+
#=> <"Laws and Symmetry">
|
223
|
+
```
|
202
224
|
|
203
225
|
### Queries
|
204
226
|
|
@@ -208,70 +230,75 @@ Additionally, you can access individual elements or groups of elements via
|
|
208
230
|
their index using `Bibliography#[]`; this accessor also exposes some of the
|
209
231
|
query functionality with the exception of yielding to a block. For instance:
|
210
232
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
233
|
+
```ruby
|
234
|
+
bib[-1]
|
235
|
+
#=> Returns the last element of the Bibliography or nil
|
236
|
+
bib[1,2]
|
237
|
+
#=> Returns the second and third elements or nil
|
238
|
+
bib[1..2]
|
239
|
+
#=> Same as above
|
240
|
+
|
241
|
+
bib[:key]
|
242
|
+
#=> Returns the first entry with key 'key' or nil
|
243
|
+
bib['key']
|
244
|
+
#=> Returns all entries with key 'key' or []
|
245
|
+
|
246
|
+
bib['@article']
|
247
|
+
#=> Returns all entries of type 'article' or []
|
248
|
+
bib['!@book']
|
249
|
+
#=> Returns all entries of any type other than 'book' or []
|
250
|
+
bib['@preamble']
|
251
|
+
#=> Returns all preamble objects (this is the same as Bibliography#preambles) or []
|
252
|
+
bib[/ruby/]
|
253
|
+
#=> Returns all objects that match 'ruby' anywhere or []
|
254
|
+
|
255
|
+
bib['@incollection[booktitle]']
|
256
|
+
#=> Returns all in-collection entries with a booktitle or []
|
257
|
+
|
258
|
+
# note that the above includes entries inheriting the book title
|
259
|
+
# from a cross-referenced entry!
|
260
|
+
|
261
|
+
bib['@book[keywords=ruby]']
|
262
|
+
#=> Returns all books whose keywords attribute equals 'ruby' or []
|
263
|
+
bib['@book[keywords!=ruby]']
|
264
|
+
#=> Returns all books whose keywords attribute does not equal 'ruby'
|
265
|
+
bib['@book[keywords/=ruby]']
|
266
|
+
#=> Same as above
|
267
|
+
|
268
|
+
bib.q('@book[keywords ^= ruby]')
|
269
|
+
#=> Returns all books whose keywords attribute matches /^ruby/
|
270
|
+
bib.q('@book[keywords ~= ruby]')
|
271
|
+
#=> Returns all books whose keywords attribute matches /ruby/
|
272
|
+
bib['@book[keywords!~ruby]']
|
273
|
+
#=> Returns all books whose keywords attribute does not match /ruby/ or don't have keywords attribute
|
274
|
+
|
275
|
+
bib.q('@article[year<=2007]')
|
276
|
+
#=> Returns all articles published in 2007 or earlier
|
277
|
+
bib.query('@book') { |e| e.keywords.split(/,/).length > 1 }
|
278
|
+
#=> Returns all book entries with two or more keywords or []
|
279
|
+
```
|
256
280
|
|
257
281
|
Queries offer syntactic sugar for common enumerator invocations:
|
258
282
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
283
|
+
```ruby
|
284
|
+
bib.query(:all, '@book')
|
285
|
+
#=> same as bib.select { |b| b.has_type?(:book) }
|
286
|
+
bib.query('@book')
|
287
|
+
#=> same as above
|
288
|
+
bib.query(:first, '@book')
|
289
|
+
#=> same as bib.detect { |b| b.has_type?(:book) }
|
290
|
+
bib.query(:none, '@book')
|
291
|
+
#=> same as bib.reject { |b| b.has_type?(:book) }
|
292
|
+
```
|
267
293
|
|
268
294
|
You can also use queries to delete entries in your bibliography:
|
269
295
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
296
|
+
```ruby
|
297
|
+
bib.delete(/ruby/)
|
298
|
+
#=> deletes all object that match 'ruby' in their string representation
|
299
|
+
bib.delete('@comment')
|
300
|
+
#=> strips all BibTeX comments from the bibliography
|
301
|
+
```
|
275
302
|
|
276
303
|
### String Replacement
|
277
304
|
|
@@ -282,39 +309,43 @@ You can replace the string symbols of an object by calling the object's
|
|
282
309
|
the **replace** method. Thus, to replace all strings defined in bibliography
|
283
310
|
b you could use the following code:
|
284
311
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
312
|
+
```ruby
|
313
|
+
b.each do |obj|
|
314
|
+
obj.replace(b.q('@string'))
|
315
|
+
end
|
316
|
+
```
|
317
|
+
|
289
318
|
A shorthand version for replacing all strings in a given bibliography is the
|
290
319
|
`Bibliography#replace` method. Similarly, you can use the
|
291
320
|
`Bibliography#join` method to join individual strings together. For instance:
|
292
321
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
}
|
322
|
+
```ruby
|
323
|
+
bib = BibTeX::Bibliography.new
|
324
|
+
bib.add BibTeX::Element.parse '@string{ foo = "foo" }'
|
325
|
+
bib << BibTeX::Element.parse '@string{ bar = "bar" }'
|
326
|
+
bib.add BibTeX::Element.parse <<-END
|
327
|
+
@book{abook,
|
328
|
+
author = foo # "Author",
|
329
|
+
title = foo # bar
|
330
|
+
}
|
331
|
+
END
|
332
|
+
puts bib[:abook].to_s
|
333
|
+
#@book{abook,
|
334
|
+
# author = foo # "Author",
|
335
|
+
# title = foo # bar
|
336
|
+
#}
|
337
|
+
bib.replace
|
338
|
+
puts bib[:abook].to_s
|
339
|
+
#@book{abook,
|
340
|
+
# author = "foo" # "Author",
|
341
|
+
# title = "foo" # "bar"
|
342
|
+
#}
|
343
|
+
bib.join
|
344
|
+
#@book{abook,
|
345
|
+
# author = {fooAuthor},
|
346
|
+
# title = {foobar}
|
347
|
+
#}
|
348
|
+
```
|
318
349
|
|
319
350
|
### Names
|
320
351
|
|
@@ -333,34 +364,42 @@ symbols that cannot be replaced will not be parsed.
|
|
333
364
|
In the following example, string replacement can take place, thus all names
|
334
365
|
are parsed and can easily be mapped to their last names:
|
335
366
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
367
|
+
```ruby
|
368
|
+
BibTeX.parse(<<-END)[1].author.map(&:last)
|
369
|
+
@string{ ht = "Nathaniel Hawthorne" }
|
370
|
+
@book{key,
|
371
|
+
author = ht # " and Melville, Herman"
|
372
|
+
}
|
373
|
+
END
|
374
|
+
#=> ["Hawthorne", "Melville"]
|
375
|
+
```
|
343
376
|
|
344
377
|
Another useful method is `Bibliography#names` which returns all names in
|
345
378
|
your bibliography (authors, editors, translators). For example, to quickly
|
346
379
|
expand the initials of a name across your entire bibliography, you could
|
347
380
|
use the following snippet:
|
348
381
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
382
|
+
```ruby
|
383
|
+
b.names.each do |name|
|
384
|
+
if name.sort_order =~ /^Poe, E/
|
385
|
+
name.first = 'Edgar Allen'
|
386
|
+
end
|
387
|
+
end
|
388
|
+
```
|
354
389
|
|
355
390
|
There is also a short-hand for this use case:
|
356
391
|
|
357
|
-
|
392
|
+
```ruby
|
393
|
+
b.extend_initials ['Edgar Allen', 'Poe']
|
394
|
+
```
|
358
395
|
|
359
396
|
Alternatively, if your bibliography contains the same names in various
|
360
397
|
forms (e.g., 'Poe, Edgar A.', 'Poe, E.A.', 'Poe, E. Allen') you can also
|
361
398
|
set all names to their longest available form:
|
362
399
|
|
363
|
-
|
400
|
+
```ruby
|
401
|
+
b.extend_initials!
|
402
|
+
```
|
364
403
|
|
365
404
|
Use with caution, though, as this method will treat names as identical
|
366
405
|
as long as their initials are the same. That is to say, 'Poe, Eric A.' would
|
@@ -374,11 +413,13 @@ names or initials, titles using different casing, different keywords etc.).
|
|
374
413
|
BibTex-Ruby allows you to group your bibliography by any number of fields
|
375
414
|
in order to detect such duplicate entries.
|
376
415
|
|
377
|
-
|
378
|
-
|
416
|
+
```ruby
|
417
|
+
b.select_duplicates_by :year, :title
|
418
|
+
#=> groups the bibliography by using the year and title field as key
|
379
419
|
|
380
|
-
|
381
|
-
|
420
|
+
b.duplicates?
|
421
|
+
#=> whether or not the bibliography contains any duplicates
|
422
|
+
```
|
382
423
|
|
383
424
|
For more complex requirements you can use the `#group_by` method directly.
|
384
425
|
This methods accepts a list of arguments whose value will be used for grouping
|
@@ -388,25 +429,29 @@ digest.
|
|
388
429
|
|
389
430
|
The duplicate methods above, for example, do something like this:
|
390
431
|
|
391
|
-
|
392
|
-
|
393
|
-
|
432
|
+
```ruby
|
433
|
+
group_by(:year, :title) do |digest, entry|
|
434
|
+
digest.gsub(/\s+/, '').downcase
|
435
|
+
end
|
436
|
+
```
|
394
437
|
|
395
438
|
You can use this method, for example, to match entries only by their author's
|
396
439
|
last name and so on and so forth.
|
397
440
|
|
398
441
|
Since version 4.1.0, BibTeX-ruby supports parsing of names spelled in the East Asian order (last name, then first name). Names contain a Chinese, Japanese or Korean letter are currently assumed to be such names. If the name is written in comma-separated manner, it is parsed in the normal way.
|
399
442
|
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
443
|
+
```ruby
|
444
|
+
b = BibTeX.parse(<<-END)
|
445
|
+
@book{key,
|
446
|
+
title = "プログラミング言語 Ruby",
|
447
|
+
author = "David Flanagan and まつもと ゆきひろ",
|
448
|
+
translator = "卜部, 昌平 and 長尾, 高弘",
|
449
|
+
year = "2009",
|
450
|
+
publisher = "O'Reilly Japan"
|
451
|
+
}
|
452
|
+
END
|
453
|
+
[*b[0].author, *b[0].translator].map(&:last) #=> [Flanagan, まつもと, 卜部, 長尾]
|
454
|
+
```
|
410
455
|
|
411
456
|
### Filters
|
412
457
|
|
@@ -417,24 +462,30 @@ to a given filter. Starting with version 1.3.9 BibTeX-Ruby includes a
|
|
417
462
|
LaTeX filter that depends on the
|
418
463
|
[latex-decode gem](http://rubygems.org/gems/latex-decode). Example:
|
419
464
|
|
420
|
-
|
421
|
-
|
422
|
-
|
465
|
+
```ruby
|
466
|
+
faust = '@book{faust, title = {Faust: Der Trag\"odie Erster Teil}}'
|
467
|
+
BibTeX.parse(faust).convert(:latex)[:faust].title
|
468
|
+
#=> "Faust: Der Tragödie Erster Teil"
|
469
|
+
```
|
423
470
|
|
424
471
|
Conditional conversions are also supported:
|
425
472
|
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
473
|
+
```ruby
|
474
|
+
faust1 = '@book{faust1, title = {Faust: Der Trag\"odie Erster Teil}}'
|
475
|
+
faust2 = '@book{faust2, title = {Faust: Der Trag\"odie Zweiter Teil}}'
|
476
|
+
p BibTeX.parse(faust1 + faust2).convert(:latex) { |e| e.key == :faust2 }.to_s
|
477
|
+
```
|
478
|
+
|
430
479
|
Returns:
|
431
480
|
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
481
|
+
```bibtex
|
482
|
+
@book{faust1,
|
483
|
+
title = {Faust: Der Trag\"odie Erster Teil}
|
484
|
+
}
|
485
|
+
@book{faust2,
|
486
|
+
title = {Faust: Der Tragödie Zweiter Teil}
|
487
|
+
}
|
488
|
+
```
|
438
489
|
|
439
490
|
If you need to express a condition on the basis of individual fields, use the
|
440
491
|
conversion methods of BibTeX::Entry with a block instead (the block will be
|
@@ -444,8 +495,9 @@ When working with Bibliographies that contain LaTeX it is often best to
|
|
444
495
|
apply the filter upon opening or parsing the Bibliography. You can do this,
|
445
496
|
by passing the `:filter` option:
|
446
497
|
|
447
|
-
|
448
|
-
|
498
|
+
```ruby
|
499
|
+
BibTeX.open 'references.bib', :filter => :latex
|
500
|
+
```
|
449
501
|
|
450
502
|
### Exports
|
451
503
|
|
@@ -461,7 +513,9 @@ In order to export your bibliography use **#to\_s**, **#to\_yaml**,
|
|
461
513
|
**#to\_json**, or **#to\_xml**, respectively. For example, the following line
|
462
514
|
constitutes a simple BibTeX to YAML converter:
|
463
515
|
|
464
|
-
|
516
|
+
```ruby
|
517
|
+
BibTeX.open('example.bib').to_yaml
|
518
|
+
```
|
465
519
|
|
466
520
|
Starting with version 2.0, BibTeX-Ruby's `#to_xml` exports your bibliography
|
467
521
|
to the [BibTeXML](http://bibtexml.sf.net/) format via `rexml`. By passing the option
|
@@ -469,15 +523,17 @@ to the [BibTeXML](http://bibtexml.sf.net/) format via `rexml`. By passing the op
|
|
469
523
|
will return individual person elements and name tokens (provided you have
|
470
524
|
successfully parsed the names of your bibliography).
|
471
525
|
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
526
|
+
```ruby
|
527
|
+
BibTeX.parse(<<-END).to_xml(:extended => true).write($stdout, 2)
|
528
|
+
@book{pickaxe,
|
529
|
+
Address = {Raleigh, North Carolina},
|
530
|
+
Author = {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
|
531
|
+
Publisher = {The Pragmatic Bookshelf},
|
532
|
+
Title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
|
533
|
+
Year = {2009}
|
534
|
+
}
|
535
|
+
END
|
536
|
+
```
|
481
537
|
|
482
538
|
This example parse a BibTeX entry, formats it as extended BibTeXML,
|
483
539
|
and writes the following XML to standard out:
|
@@ -527,35 +583,38 @@ hash which lets you define what quotes to use (note that BibTeX-Ruby will
|
|
527
583
|
always use regular double quotes if a value consists of more than one token,
|
528
584
|
because these tokens will be concatenated using BibTeX's '#' operator).
|
529
585
|
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
586
|
+
```ruby
|
587
|
+
BibTeX.parse(<<-END).to_a # implies: :quotes => ['{','}']
|
588
|
+
@book{pickaxe,
|
589
|
+
Address = {Raleigh, North Carolina},
|
590
|
+
Author = {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
|
591
|
+
Publisher = {The Pragmatic Bookshelf},
|
592
|
+
Title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
|
593
|
+
Year = {2009}
|
594
|
+
}
|
595
|
+
END
|
596
|
+
#=> [{:bibtex_key=>:pickaxe, :bibtex_type=>:book,
|
597
|
+
# :address=>"{Raleigh, North Carolina}",
|
598
|
+
# :author=>"{Thomas, Dave, and Fowler, Chad, and Hunt, Andy}",
|
599
|
+
# :publisher=>"{The Pragmatic Bookshelf}",
|
600
|
+
# :title=>"{Programming Ruby 1.9: The Pragmatic Programmer's Guide}",
|
601
|
+
# :year=>"{2009}"}]
|
602
|
+
```
|
545
603
|
|
546
604
|
For post-processing in Ruby most of the time you do not need any explicit
|
547
605
|
quotes; therefore you can simply add the :quotes option with an empty string:
|
548
606
|
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
607
|
+
```ruby
|
608
|
+
>> BibTeX.parse(<<-END).to_a(:quotes => '')
|
609
|
+
...
|
610
|
+
END
|
611
|
+
#=> [{:bibtex_key=>:pickaxe, :bibtex_type=>:book,
|
612
|
+
# :address=>"Raleigh, North Carolina",
|
613
|
+
# :author=>"Thomas, Dave, and Fowler, Chad, and Hunt, Andy",
|
614
|
+
# :publisher=>"The Pragmatic Bookshelf",
|
615
|
+
# :title=>"Programming Ruby 1.9: The Pragmatic Programmer's Guide",
|
616
|
+
# :year=>"2009"}]
|
617
|
+
```
|
559
618
|
|
560
619
|
The Parser
|
561
620
|
----------
|
@@ -599,8 +658,6 @@ To execute the test suite continuously while you're working run:
|
|
599
658
|
|
600
659
|
$ bundle exec guard
|
601
660
|
|
602
|
-
|
603
|
-
|
604
661
|
Credits
|
605
662
|
-------
|
606
663
|
|