bibtex-ruby 5.1.6 → 6.1.0

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