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.
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
- b = BibTeX.open('./ruby.bib')
27
+ ```ruby
28
+ b = BibTeX.open('./ruby.bib')
29
+ ```
28
30
 
29
31
  Select a BibTeX entry and access individual fields:
30
32
 
31
- b['pickaxe'].title
32
- #=> "Programming Ruby 1.9: The Pragmatic Programmer's Guide"
33
- b[:pickaxe].author.length
34
- #=> 3
35
- b[:pickaxe].author.to_s
36
- #=> "Thomas, D. and Fowler, Chad and Hunt, Andy"
37
- b[:pickaxe].author[2].first
38
- #=> "Andy"
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
- b['@book'].length
43
- #=> 3 - the number books in the bibliography
44
- b['@article'].length
45
- #=> 0 - the number of articles in the bibliography
46
- b['@book[year=2009]'].length
47
- #=> 1 - the number of books published in 2009
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
- b.extend_initials ['Dave', 'Thomas']
52
- b[:pickaxe].author.to_s
53
- #=> "Thomas, Dave and Fowler, Chad and Hunt, Andy"
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
- b.extend_initials! #=> extends all names in the bibliography
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
- b.unify :publisher, /o'?reilly/i, "O'Reilly"
75
+ ```ruby
76
+ b.unify :publisher, /o'?reilly/i, "O'Reilly"
66
77
 
67
- b.unify :publisher, /^penguin/i do |entry|
68
- entry.publisher = 'Penguin Books'
69
- entry.address = 'London'
70
- end
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
- require 'citeproc'
79
- CiteProc.process b[:pickaxe].to_citeproc, :style => :apa
80
- #=> "Thomas, D., Fowler, C., & Hunt, A. (2009). Programming Ruby 1.9: The Pragmatic Programmer's
81
- Guide. The Facets of Ruby. Raleigh, North Carolina: The Pragmatic Bookshelf."
82
- CiteProc.process b[:pickaxe].to_citeproc, :style => 'chicago-author-date'
83
- #=> "Thomas, Dave, Chad Fowler, and Andy Hunt. 2009. Programming Ruby 1.9: The Pragmatic
84
- Programmer's Guide. The Facets of Ruby.Raleigh, North Carolina: The Pragmatic Bookshelf."
85
- CiteProc.process b[:pickaxe].to_citeproc, :style => :mla
86
- #=> "Thomas, Dave, Chad Fowler, and Andy Hunt. Programming Ruby 1.9: The Pragmatic Programmer's
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
- b.save
92
- #=> saves the original file
93
- b.save_to(file)
94
- #=> saves the bibliography in a new file
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
- b = BibTeX.parse <<-END
123
- @book{pickaxe,
124
- address = {Raleigh, North Carolina},
125
- author = {Thomas, Dave and Fowler, Chad and Hunt, Andy},
126
- publisher = {The Pragmatic Bookshelf},
127
- series = {The Facets of Ruby},
128
- title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
129
- year = {2009}
130
- }
131
- END
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
- > bib = BibTeX::Bibliography.new
166
+ ```ruby
167
+ bib = BibTeX::Bibliography.new
168
+ ```
151
169
 
152
170
  Using a Hash:
153
171
 
154
- > bib << BibTeX::Entry.new({
155
- :bibtex_type => :book,
156
- :key => :rails,
157
- :address => 'Raleigh, North Carolina',
158
- :author => 'Ruby, Sam and Thomas, Dave, and Hansson, David Heinemeier',
159
- :booktitle => 'Agile Web Development with Rails',
160
- :edition => 'third',
161
- :keywords => 'ruby, rails',
162
- :publisher => 'The Pragmatic Bookshelf',
163
- :series => 'The Facets of Ruby',
164
- :title => 'Agile Web Development with Rails',
165
- :year => '2009'
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
- > book = BibTeX::Entry.new
171
- > book.type = :book
172
- > book.key = :mybook
173
- > bib << book
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
- > b = BibTeX.parse <<-END
185
- @inbook{fraassen_1989b,
186
- Crossref = {fraassen_1989},
187
- Pages = {40-64},
188
- Title = {Ideal Science: David Lewis's Account of Laws},
189
- }
190
-
191
- @book{fraassen_1989,
192
- Address = {Oxford},
193
- Author = {Bas C. van Fraassen},
194
- Publisher = {Oxford University Press},
195
- Title = {Laws and Symmetry},
196
- Year = 1989
197
- }
198
- END
199
- > b['fraassen_1989b'].booktitle
200
- => <"Laws and Symmetry">
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
- bib[-1]
212
- => Returns the last element of the Bibliography or nil
213
- bib[1,2]
214
- => Returns the second and third elements or nil
215
- bib[1..2]
216
- => Same as above
217
-
218
- bib[:key]
219
- => Returns the first entry with key 'key' or nil
220
- bib['key']
221
- => Returns all entries with key 'key' or []
222
-
223
- bib['@article']
224
- => Returns all entries of type 'article' or []
225
- bib['!@book']
226
- => Returns all entries of any type other than 'book' or []
227
- bib['@preamble']
228
- => Returns all preamble objects (this is the same as Bibliography#preambles) or []
229
- bib[/ruby/]
230
- => Returns all objects that match 'ruby' anywhere or []
231
-
232
- bib['@incollection[booktitle]']
233
- => Returns all in-collection entries with a booktitle or []
234
-
235
- # note that the above includes entries inheriting the book title
236
- # from a cross-referenced entry!
237
-
238
- bib['@book[keywords=ruby]']
239
- => Returns all books whose keywords attribute equals 'ruby' or []
240
- bib['@book[keywords!=ruby]']
241
- => Returns all books whose keywords attribute does not equal 'ruby'
242
- bib['@book[keywords/=ruby]']
243
- => Same as above
244
-
245
- bib.q('@book[keywords ^= ruby]')
246
- => Returns all books whose keywords attribute matches /^ruby/
247
- bib.q('@book[keywords ~= ruby]')
248
- => Returns all books whose keywords attribute matches /ruby/
249
- bib['@book[keywords!~ruby]']
250
- => Returns all books whose keywords attribute does not match /ruby/ or don't have keywords attribute
251
-
252
- bib.q('@article[year<=2007]')
253
- => Returns all articles published in 2007 or earlier
254
- bib.query('@book') { |e| e.keywords.split(/,/).length > 1 }
255
- => Returns all book entries with two or more keywords or []
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
- bib.query(:all, '@book')
260
- => same as bib.select { |b| b.has_type?(:book) }
261
- bib.query('@book')
262
- => same as above
263
- bib.query(:first, '@book')
264
- => same as bib.detect { |b| b.has_type?(:book) }
265
- bib.query(:none, '@book')
266
- => same as bib.reject { |b| b.has_type?(:book) }
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
- bib.delete(/ruby/)
271
- => deletes all object that match 'ruby' in their string representation
272
- bib.delete('@comment')
273
- => strips all BibTeX comments from the bibliography
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
- b.each do |obj|
286
- obj.replace(b.q('@string'))
287
- end
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
- > bib = BibTeX::Bibliography.new
294
- > bib.add BibTeX::Element.parse '@string{ foo = "foo" }'
295
- > bib << BibTeX::Element.parse '@string{ bar = "bar" }'
296
- > bib.add BibTeX::Element.parse <<-END
297
- > @book{abook,
298
- > author = foo # "Author",
299
- > title = foo # bar
300
- > }
301
- > END
302
- > puts bib[:abook].to_s
303
- @book{abook,
304
- author = foo # "Author",
305
- title = foo # bar
306
- }
307
- > bib.replace
308
- > puts bib[:abook].to_s
309
- @book{abook,
310
- author = "foo" # "Author",
311
- title = "foo" # "bar"
312
- }
313
- > bib.join
314
- @book{abook,
315
- author = {fooAuthor},
316
- title = {foobar}
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
- BibTeX.parse(<<-END)[1].author.map(&:last)
337
- @string{ ht = "Nathaniel Hawthorne" }
338
- @book{key,
339
- author = ht # " and Melville, Herman"
340
- }
341
- END
342
- #=> ["Hawthorne", "Melville"]
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
- b.names.each do |name|
350
- if name.sort_order =~ /^Poe, E/
351
- name.first = 'Edgar Allen'
352
- end
353
- end
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
- b.extend_initials ['Edgar Allen', 'Poe']
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
- b.extend_initials!
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
- b.select_duplicates_by :year, :title
378
- #=> groups the bibliography by using the year and title field as key
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
- b.duplicates?
381
- #=> whether or not the bibliography contains any duplicates
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
- group_by(:year, :title) do |digest, entry|
392
- digest.gsub(/\s+/, '').downcase
393
- end
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
- b = BibTeX.parse(<<-END)
401
- @book{key,
402
- title = "プログラミング言語 Ruby",
403
- author = "David Flanagan and まつもと ゆきひろ",
404
- translator = "卜部, 昌平 and 長尾, 高弘",
405
- year = "2009",
406
- publisher = "O'Reilly Japan"
407
- }
408
- END
409
- [*b[0].author, *b[0].translator].map(&:last) #=> [Flanagan, まつもと, 卜部, 長尾]
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
- faust = '@book{faust, title = {Faust: Der Trag\"odie Erster Teil}}'
421
- BibTeX.parse(faust).convert(:latex)[:faust].title
422
- #=> "Faust: Der Tragödie Erster Teil"
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
- faust1 = '@book{faust1, title = {Faust: Der Trag\"odie Erster Teil}}'
427
- faust2 = '@book{faust2, title = {Faust: Der Trag\"odie Zweiter Teil}}'
428
- p BibTeX.parse(faust1 + faust2).convert(:latex) { |e| e.key == :faust2 }.to_s
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
- @book{faust1,
433
- title = {Faust: Der Trag\"odie Erster Teil}
434
- }
435
- @book{faust2,
436
- title = {Faust: Der Tragödie Zweiter Teil}
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
- BibTeX.open 'references.bib', :filter => :latex
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
- >> BibTeX.open('example.bib').to_yaml
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
- > BibTeX.parse(<<-END).to_xml(:extended => true).write($stdout, 2)
473
- " @book{pickaxe,
474
- " Address = {Raleigh, North Carolina},
475
- " Author = {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
476
- " Publisher = {The Pragmatic Bookshelf},
477
- " Title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
478
- " Year = {2009}
479
- " }
480
- " END
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
- >> BibTeX.parse(<<-END).to_a # implies: :quotes => ['{','}']
531
- @book{pickaxe,
532
- Address = {Raleigh, North Carolina},
533
- Author = {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
534
- Publisher = {The Pragmatic Bookshelf},
535
- Title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
536
- Year = {2009}
537
- }
538
- END
539
- => [{:bibtex_key=>:pickaxe, :bibtex_type=>:book,
540
- :address=>"{Raleigh, North Carolina}",
541
- :author=>"{Thomas, Dave, and Fowler, Chad, and Hunt, Andy}",
542
- :publisher=>"{The Pragmatic Bookshelf}",
543
- :title=>"{Programming Ruby 1.9: The Pragmatic Programmer's Guide}",
544
- :year=>"{2009}"}]
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
- >> BibTeX.parse(<<-END).to_a(:quotes => '')
550
- ...
551
- END
552
- => [{:bibtex_key=>:pickaxe, :bibtex_type=>:book,
553
- :address=>"Raleigh, North Carolina",
554
- :author=>"Thomas, Dave, and Fowler, Chad, and Hunt, Andy",
555
- :publisher=>"The Pragmatic Bookshelf",
556
- :title=>"Programming Ruby 1.9: The Pragmatic Programmer's Guide",
557
- :year=>"2009"}]
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