Class: Asciidoctor::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor/latex/node_processors.rb

Overview

Proces block elements of varios kinds

Constant Summary

STANDARD_ENVIRONMENT_NAMES =

STANDARD_ENVIRONMENT_NAMES = %w(theorem proposition lemma definition example problem equation)

%w(equation)

Instance Method Summary (collapse)

Instance Method Details

- (Object) admonition_process



340
341
342
# File 'lib/asciidoctor/latex/node_processors.rb', line 340

def admonition_process
  $tex.macro 'admonition', self.style, self.content
end

- (Object) click_process



516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
# File 'lib/asciidoctor/latex/node_processors.rb', line 516

def click_process
  attr = self.attributes
  click = self.attributes["role"]
  # record any environ$ments encounted but not built=in
  if !STANDARD_ENVIRONMENT_NAMES.include? click
    $latex_environment_names << click
  end

  if title
    title = self.title.downcase
  end

  # original_title = title.split(' ')[0].downcase
  # FIXME: the above is  work-around: instead set
  # originaltitle in clickblock

  if attr['plain-option']
    content = $tex.region 'rm', self.content
  else
    content = $tex.region 'it', self.content
  end

  # FIXME! This is a temporary hack.
  # attr['original_title'] can be nil --
  # it shouldn't be
  if attr['original_title']
    if attr['options'] and attr['options'].include? 'numbered'
      env = attr['original_title'].downcase
    else
      env =  attr['original_title'].downcase+'*'
    end
  else
    env = 'click'
  end



  if self.id == nil # No label
    $tex.env env, content
  else
    label = $tex.macro 'label', self.id
    $tex.env env, "#{label}\n#{content}"
  end
end

- (Object) env_title



400
401
402
403
404
405
406
# File 'lib/asciidoctor/latex/node_processors.rb', line 400

def env_title
  if self.attributes['original_title']
    "\{\\rm (#{self.attributes['original_title']}) \}"
  else
    ''
  end
end

- (Object) environment_process



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/asciidoctor/latex/node_processors.rb', line 457

def environment_process

  env = self.attributes["role"]

  # record any environments encountered but not built=in
  if !STANDARD_ENVIRONMENT_NAMES.include? env and !$latex_environment_names.include? env
    $latex_environment_names << env
  end

  case env
    when 'listing'
      handle_listing
    when 'equationalign'
      handle_eqalign
    when 'equation'
      handle_equation
    when 'chem'
      handle_chem
    when 'box'
      handle_box
    when 'texmacro'
      handle_texmacro
    when 'include_latex'
      handle_include_latex
    else
      handle_plain(env)
  end
end

- (Object) example_process



622
623
624
625
626
627
628
629
630
631
632
633
634
635
# File 'lib/asciidoctor/latex/node_processors.rb', line 622

def example_process
  id = self.attributes['id']
  if self.title
    heading = $tex.region 'bf', self.title
    content  = "-- #{heading}.\n#{self.content}"
  else
    content = self.content
  end
  if id
    hypertarget = $tex.hypertarget id, self.content.split("\n")[0]
    content = "#{hypertarget}\n#{content}" if id
  end
  $tex.env 'example', content
end

- (Object) floating_title_process



638
639
640
641
642
643
644
645
646
647
# File 'lib/asciidoctor/latex/node_processors.rb', line 638

def floating_title_process
  doctype = self.document.doctype

  tags = { 'article' => [ 'part',  'section', 'subsection', 'subsubsection', 'paragraph' ],
           'book' => [ 'part', 'chapter', 'section', 'subsection', 'subsubsection', 'paragraph' ] }

  tagname = tags[doctype][self.level]

  "\\#{tagname}*\{#{self.title}\}\n\n#{self.content}\n\n"
end

- (Object) handle_box



508
509
510
511
512
513
514
# File 'lib/asciidoctor/latex/node_processors.rb', line 508

def handle_box
  if self.title.nil? or self.title == ''
    $tex.env 'asciidocbox', self.content
  else
    $tex.env 'titledasciidocbox',  self.title, self.content
  end
end

- (Object) handle_chem



434
435
436
# File 'lib/asciidoctor/latex/node_processors.rb', line 434

def handle_chem
  $tex.env 'equation', "#{label}\n\\ce\{#{self.content.strip}\}\n"
end

- (Object) handle_eqalign



415
416
417
418
419
420
421
422
423
# File 'lib/asciidoctor/latex/node_processors.rb', line 415

def handle_eqalign
  if options.include? 'numbered'
    content = $tex.env 'split', label + "\n" + self.content.strip
    $tex.env 'equation', content
  else
    content = $tex.env 'split', label + "\n" + self.content.strip
    $tex.env 'equation*', content
  end
end

- (Object) handle_equation



425
426
427
428
429
430
431
432
# File 'lib/asciidoctor/latex/node_processors.rb', line 425

def handle_equation
  if options.include? 'numbered'
    content = $tex.hypertarget self.id, self.content.strip
    $tex.env 'equation', "#{label}#{content}"
  else
    $tex.env 'equation*', "#{label}#{self.content.strip}"
  end
end

- (Object) handle_include_latex

Example:

env.include_latex

– nput abc.text usepackagedef – Nothing appears in the HTML, bu lines nput abc.text usepackagedef appear in the generated tex file.



501
502
503
504
505
506
# File 'lib/asciidoctor/latex/node_processors.rb', line 501

def handle_include_latex
  puts "Hi Boss, it's me again!"
  puts self.content
  puts "---------------"
  self.content
end

- (Object) handle_listing



410
411
412
413
# File 'lib/asciidoctor/latex/node_processors.rb', line 410

def handle_listing
  content = $tex.env 'verbatim', self.content
  $tex.env env, label, content
end

- (Object) handle_plain(env)



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/asciidoctor/latex/node_processors.rb', line 438

def handle_plain(env)

  if self.id and self.title
    _title = $tex.hypertarget self.id, self.env_title
  else
    _title = self.env_title
  end

  if self.attributes['plain-option']
    content = $tex.region 'rm', self.content
  else
    content = self.content
  end

  $tex.env env, "#{_title}#{label}#{content}\n"
end

- (Object) handle_texmacro



486
487
488
# File 'lib/asciidoctor/latex/node_processors.rb', line 486

def handle_texmacro
  "%% User tex macros:\n#{self.content}\n%% end of user macros\n"
end

- (Object) image_process



649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# File 'lib/asciidoctor/latex/node_processors.rb', line 649

def image_process
  if self.attributes['width']
    width = "#{self.attributes['width'].to_f/100.0}truein"
  else
    width = '2.5truein'
  end
  raw_image = self.attributes['target']
  if document.attributes['noteshare'] == 'yes'
    image_rx = /image.*original\/(.*)\?/
    match_data = raw_image.match image_rx
    if match_data
      image = match_data[1]
    else
      image = "undefined"
    end
  else
    image = raw_image
  end
  if self.title and self.title != ''
    caption =   "\\caption\{#{self.attributes['title']}\}"
  else
    caption = ''
  end
  refs = self.parent.document.references  # [:ids]
  if self.attributes['align'] == 'center'
    align = '\\centering'
  else
    align = ''
  end
  float = self.attributes['float']
  if float
    figure_type = 'wrapfigure'
    ftext_width = width # '0.45\\textwidth'
    caption=''
  else
    figure_type = 'figure'
    text_width = ''
  end
  case float
  when 'left'
    position = '{l}'
  when 'right'
    position = '{r}'
  else
    position = '[h]'
  end
  # pos_option = "#{figure_type}}#{position}"
  # incl_graphics = $tex.macro_opt, "width=#{width}", image
  # $tex.env figure_type, "#{pos_option}\{#{ftext_width}\}", incl_graphics,
  #\n\\includegraphics[width=#{width}]{#{image}}\n#{caption}\n#{align}"
  "\\begin{#{figure_type}}#{position}\{#{ftext_width}\}\n\\centering\\includegraphics[width=#{width}]{#{image}}\n#{caption}\n#{align}\n\\end{#{figure_type}}\n"
end

- (Object) label



386
387
388
389
390
391
392
393
394
# File 'lib/asciidoctor/latex/node_processors.rb', line 386

def label
  if self.id
    label = $tex.macro 'label', self.id
    # label = $tex.macro 'label', $tex.hypertarget(self.id, self.id)
  else
    label = ""
  end
  label
end

- (Object) listing_process



618
619
620
# File 'lib/asciidoctor/latex/node_processors.rb', line 618

def listing_process
  "\\begin\{verbatim\}\n#{self.content}\n\\end\{verbatim\}\n"
end

- (Object) literal_process



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/asciidoctor/latex/node_processors.rb', line 348

def literal_process
  heading = ''
  if id and self.title
    heading = $tex.hypertarget id, self.title
  elsif self.title
    heading = self.title
  end
  if heading == ''
    $tex.env 'verbatim', self.content
  else
    output = $tex.region 'bf', heading
    output << "\\vspace\{-1\\baselineskip\}\n"
    output << ($tex.env 'verbatim', self.content)
  end
end

- (Object) open_process

Process open blocks. Map a block of the form

.Foo

[hocus_pocus]

– La di dah –

to

beginFoo labelhocus_pocus La di dah endFoo

This scheme enables one to map Asciidoc blocks to LaTeX environments with essentally no knoweldge of either other than their form.



596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/asciidoctor/latex/node_processors.rb', line 596

def open_process

  attr = self.attributes

  # Get title !- nil or make a dummy one
  title = self.attributes["title"]
  if title == nil
    title = "Dummy"
  end

   # strip constructs like {counter:theorem} from the title
   title = title.gsub /\{.*?\}/, ""
   title = title.strip

  if attr['role'] == 'text-center'
    $tex.env 'center', self.content
  else
    self.content
  end

end

- (Object) options



396
397
398
# File 'lib/asciidoctor/latex/node_processors.rb', line 396

def options
  self.attributes['options']
end

- (Object) page_break_process



344
345
346
# File 'lib/asciidoctor/latex/node_processors.rb', line 344

def page_break_process
  "\n\\vfill\\eject\n"
end

- (Object) paragraph_process



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/asciidoctor/latex/node_processors.rb', line 311

def paragraph_process
  options = self.attributes['options']
  out = ""
  if self.attributes['title']
    title = "#{self.attributes['title']}\."
    out << $tex.region('bf', title) + ' '
  end
  content =  LaTeX::TeXPostProcess.make_substitutions(self.content)
  if role == "red"
    content = content.macro('rolered')
  elsif role == "blue"
    content = content.macro('roleblue')
  end
  if options and options.include? 'hardbreaks'
    # content =  content.macro('obeylines')
  end

  out << content << "\n\n"
end

- (Object) pass_process



364
365
366
# File 'lib/asciidoctor/latex/node_processors.rb', line 364

def pass_process
  self.content
end

- (Object) preamble_process



702
703
704
705
# File 'lib/asciidoctor/latex/node_processors.rb', line 702

def preamble_process
  # "\\begin\{preamble\}\n%% HO HO HO!\n#{self.content}\n\\end\{preamble\}\n"
  self.content
end

- (Object) quote_process



368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/asciidoctor/latex/node_processors.rb', line 368

def quote_process
  if self.attr? 'attribution'
    attribution = self.attr 'attribution'
    citetitle = (self.attr? 'citetitle') ? (self.attr 'citetitle') : nil
    # citetitle = citetitle ? ' - ' + citetitle : ''
    citetitle = citetitle ? $tex.region('bf', citetitle) + ' \\\\' : ''
    $tex.env 'aquote', attribution, citetitle, self.content
  elsif self.title
    $tex.env 'tquote', self.title, self.content
  else
    $tex.env 'quotation', self.content
  end
end

- (Object) report



565
566
567
568
569
570
571
572
573
574
# File 'lib/asciidoctor/latex/node_processors.rb', line 565

def report
  # Report on this node
  warn ["OPEN BLOCK:".magenta, "id: #{self.id}"].join(" ")
  warn ["Node:".magenta, "#{self.blockname}".cyan].join(" ")
  warn ["Attributes:".magenta, "#{self.attributes}".cyan].join(" ")
  warn ["Title: ".magenta, title.cyan, "style:", self.style].join(" ") if title
  warn ["Content:".magenta, "#{self.content}".yellow].join(" ")
  warn ["Style:".green, "#{self.style}".red].join(" ")
  # warn ["METHODS:".red, "#{self.methods}".yellow].join(" ")
end


708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
# File 'lib/asciidoctor/latex/node_processors.rb', line 708

def sidebar_process
  title = self.title
  attr = self.attributes
  id = attr['id']
  if id
    content = "\\hypertarget\{#{id}\}\{#{self.content.rstrip}\}"
  else
    content = self.content
  end
  if title
    title  = $tex.env 'bf', title
    $tex.env 'sidebar', "#{title}\\\\#{content}"
  else
    $tex.env 'sidebar', content
  end
end

- (Object) stem_process



331
332
333
334
335
336
337
338
# File 'lib/asciidoctor/latex/node_processors.rb', line 331

def stem_process
  environment = LaTeX::TeXBlock.environment_type self.content
  if LaTeX::TeXBlock::INNER_TYPES.include? environment
    "\\\[\n#{LaTeX::TeXPostProcess.stem_substitutions self.content}\n\\\]\n"
  else
    self.content
  end
end

- (Object) tex_process



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/asciidoctor/latex/node_processors.rb', line 264

def tex_process
  case self.blockname
  when :paragraph
    paragraph_process
  when :stem
    stem_process
  when :admonition
    admonition_process
  when :page_break
    page_break_process
  when :literal
    self.literal_process
  when :pass
    self.pass_process
  when :quote
    self.quote_process
  when :open
    self.open_process
  when :environment
    self.environment_process
  when :click
    self.click_process
  when :listing
    self.listing_process
  when :example
    self.example_process
  when :floating_title
    self.floating_title_process
  when :image
    self.image_process
  when :preamble
    self.preamble_process
  when :sidebar
    self.sidebar_process
  when :verse
    self.verse_process
  when :toc
    self.toc_process
  # when :table
    # self.table_process
  else
    # warn "This is Asciidoctor::Block, tex_process.  I don't know how to do that (#{self.blockname})" if $VERBOSE if $VERBOSE
    ""
  end
end

- (Object) toc_process



561
562
563
# File 'lib/asciidoctor/latex/node_processors.rb', line 561

def toc_process
  # warn "Please implement me! (toc_process)".red if $VERBOSE
end

- (Object) verse_process



725
726
727
728
# File 'lib/asciidoctor/latex/node_processors.rb', line 725

def verse_process
  # $tex.env 'alltt', self.content
  $tex.env 'verse', self.content
end