m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/lib/latex.rb
blob: e0c0f9a939a5b06d8f06a85cb9ddab996340f547 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def render_partial_latex song
  template = tex_template 'song-partial'
  templated = template.result binding
  File.write(tmp(song_partial_tex song.id), templated)
end

def render_latex song
  template = tex_template 'song'
  templated = template.result binding
  File.write(tmp(song_tex song.id), templated)
end

def render_pdf song
  render_latex song
  system "lualatex --shell-escape -output-directory=#{TmpDir}/#{SongsDir} #{tmp (song_tex song.id)}"
  system "mv #{tmp (song_pdf song.id)} #{build (song_pdf song.id)}"
end

def render_songbook_latex songs
  template = tex_template 'songbook'
  templated = template.result binding
  File.write(tmp('songbook.tex'), templated)
end

def render_songbook songs
  render_songbook_latex songs
  system "lualatex --shell-escape -output-directory=#{TmpDir}/ #{tmp 'songbook.tex'}"
  # compile twice for table of contents to generate properly
  system "lualatex --shell-escape -output-directory=#{TmpDir}/ #{tmp 'songbook.tex'}"
  system "mv #{tmp 'songbook.pdf'} #{build 'śpiewnik-tuturutu.pdf'}"
end

def make_pdfs songs
  songs.each_value do |song|
    render_partial_latex song
    render_pdf song
  end

  render_songbook songs
end