Module: Texas::Template::Helper::TeX

Included in:
Runner::TeX
Defined in:
lib/texas/template/helper/tex.rb

Instance Method Summary collapse

Instance Method Details

Converts all URLs in a text in url TeX commands


9
10
11
# File 'lib/texas/template/helper/tex.rb', line 9

def auto_link(text)
  text.to_s.gsub(/(https*\:\/\/\S+)/, '\url{\1}')
end

#bold(text) ⇒ Object Also known as: b


13
14
15
# File 'lib/texas/template/helper/tex.rb', line 13

def bold(text)
  tex :textbf, text
end

#h1(*args) ⇒ Object


18
# File 'lib/texas/template/helper/tex.rb', line 18

def h1(*args); tex(:section, *args); end

#h2(*args) ⇒ Object


19
# File 'lib/texas/template/helper/tex.rb', line 19

def h2(*args); tex(:subsection, *args); end

#h3(*args) ⇒ Object


20
# File 'lib/texas/template/helper/tex.rb', line 20

def h3(*args); tex(:subsubsection, *args); end

#h4(text) ⇒ Object


21
# File 'lib/texas/template/helper/tex.rb', line 21

def h4(text); '\paragraph{'+text+'} ~\\'; end

#input(*path) ⇒ Object


28
29
30
31
# File 'lib/texas/template/helper/tex.rb', line 28

def input(*path)
  write_template_for_input(path)
  tex :input, relative_template_basename(path)
end

#input!(*path) ⇒ Object


33
34
35
36
# File 'lib/texas/template/helper/tex.rb', line 33

def input!(*path)
  write_template_for_input(path)
  tex :include, relative_template_basename(path)
end

#italic(text) ⇒ Object Also known as: i


23
24
25
# File 'lib/texas/template/helper/tex.rb', line 23

def italic(text)
  tex :emph, text
end

#linebreakObject Also known as: br


38
39
40
# File 'lib/texas/template/helper/tex.rb', line 38

def linebreak
  "\\\\"
end

#quote(string) ⇒ Object


43
44
45
# File 'lib/texas/template/helper/tex.rb', line 43

def quote(string)
  "\"`#{string}\"'"
end

#relative_template_basename(path) ⇒ Object

Returns a path relative to the build_path and strips the template extension

Example:

relative_template_basename("/home/rene/github/sample_project/tmp/build/contents.tex.erb")
# => "contents"

70
71
72
# File 'lib/texas/template/helper/tex.rb', line 70

def relative_template_basename(path)
  Template.basename relative_template_filename(path)
end

#relative_template_filename(path, possible_exts = Template.known_extensions) ⇒ Object

Returns a path relative to the build_path

Example:

relative_template_filename("/home/rene/github/sample_project/tmp/build/contents.tex.erb")
# => "contents.tex.erb"

59
60
61
62
# File 'lib/texas/template/helper/tex.rb', line 59

def relative_template_filename(path, possible_exts = Template.known_extensions)
  filename = find_template_file!(path, possible_exts)
  filename.gsub(build_path+'/', '')
end

#tex(command, text) ⇒ Object


74
75
76
# File 'lib/texas/template/helper/tex.rb', line 74

def tex(command, text)
  "\\#{command}{#{text}}"
end

#write_template_for_input(path) ⇒ Object


47
48
49
50
51
# File 'lib/texas/template/helper/tex.rb', line 47

def write_template_for_input(path)
  filename = find_template_file!(path, template_extensions)
  template = Template.create(filename, build)
  template.write
end