Module: LaTeX

Defined in:
lib/ulmul.rb

Instance Method Summary collapse

Instance Method Details

#bodyObject



537
538
539
540
541
542
543
544
545
546
547
548
# File 'lib/ulmul.rb', line 537

def body
  b = @body.dup
  [@equations, @figures, @tables, @codes].each do |ary|
    ary.each_with_index do |r,i|
      s = r.sub(/:.*/,'')
      if /Eq|Fig/ =~ s then s << '.' end
      if /Eq/     =~ s then no = "(\\ref{#{r}})" else no = "\\ref{#{r}}" end
      b.gsub!(Regexp.new('(?![A-Za-z0-9_"\'#%\\\\{\=])(.)'+r+'(?![A-Za-z0-9_"\'#%}])(.)'), "\\1#{s}~#{no}\\2")
    end
  end
  return b
end

#cb_env_end2Object



479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
# File 'lib/ulmul.rb', line 479

def cb_env_end2()
  case @env_label
  when /^Fig:/
    width  = EXIFR::JPEG.new(@env_file).width
    height = EXIFR::JPEG.new(@env_file).height
    @body << "\\begin{figure}\n" << "  \\center\n  \\includegraphics[width=5cm,bb=0 0 #{width} #{height}]{#{@env_file}}\n"
    @body << '  \caption{' << @subs_rules.call(@env_caption).strip << "}\n"
    @body << "  \\label{#{@env_label}}\n" << "\\end{figure}\n"
  when /^Table:/
    @body << "\\begin{table}\n"
    @body << '  \caption{' << @subs_rules.call(@env_caption).strip << "}\n"
    @body << "  \\label{#{@env_label}}\n"
    @body << "  \\center\n"
    @body << "  {TABLE is not yet implemented.}\n"
    @body << "\\end{table}\n"
  when /^Code:/
    @body << "\\begin{lstlisting}[caption={#{@subs_rules.call(@env_caption).strip}},label=#{@env_label}]\n"
    f = open(@env_file)
    @body << f.read
    f.close
    @body << "\\end{lstlisting}\n"
  end
end

#cb_equation_end2Object



503
504
505
506
507
# File 'lib/ulmul.rb', line 503

def cb_equation_end2()
  @body << "\\begin{equation}\n" << "  \\label{#{@equation_label}}\n"
  @body << @equation_contents
  @body << "\\end{equation}\n"
end

#cb_heading(filename = nil, lnumber = nil, line = nil) ⇒ Object



458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/ulmul.rb', line 458

def cb_heading(filename=nil, lnumber=nil, line=nil)
  if /^(=+) (.*)$/ =~ line
    new_level=Regexp.last_match[1].length
    str=Regexp.last_match[2]
  elsif /^=end/ =~ line
    @level_of_heading=0
    @toc.cb_itemize_end()
    return
  end
  raise 'Illegal jump of heading level' if new_level>@level_of_heading+1
  @title=str                                 if new_level==1
  @body <<       '\section{' << str << "}\n" if new_level==2
  @body <<    '\subsection{' << str << "}\n" if new_level==3
  @body << '\subsubsection{' << str << "}\n" if new_level==4
  @body <<            '\bf{' << str << "}\n" if new_level==5
  if 2 <= new_level && new_level <= $MAX_TABLE_OF_CONTENTS
    @toc.cb_itemize_add_item('LaTeX Table of Contents', @i_th_heading, "  "*(new_level-2) + " * " + str)
  end
  @level_of_heading=new_level
end

#file(packages, name) ⇒ Object



509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/ulmul.rb', line 509

def file(packages,name)
  return "\\documentclass{article}
\\usepackage{graphicx}
\\usepackage{bm}
\\usepackage{listings}
\\renewcommand{\\lstlistingname}{Code}
\\lstset{language=c,
%  basicstyle=\\ttfamily\\scriptsize,
%  commentstyle=\\textit,
%  classoffset=1,
%  keywordstyle=\\bfseries,
 frame=shadowbox,
%  framesep=5pt,
%  showstringspaces=false,
%  numbers=left,
%  stepnumber=1,
%  numberstyle=\\tiny,
%  tabsize=2
}
\\title{#{@title}}
\\author{#{name}}
\\begin{document}
\\maketitle
#{body}
\\end{document}
"
end