Class: Macaw

Inherits:
Object
  • Object
show all
Defined in:
lib/macaw/rules/tex.rb,
lib/macaw/version.rb,
lib/macaw/rules/make.rb,
lib/macaw/rules/biber.rb,
lib/macaw/rules/clean.rb,
lib/macaw/rules/dvips.rb,
lib/macaw/rules/latex.rb,
lib/macaw/rules/xetex.rb,
lib/macaw/rules/bibtex.rb,
lib/macaw/rules/indent.rb,
lib/macaw/rules/luatex.rb,
lib/macaw/rules/pdftex.rb,
lib/macaw/rules/ps2pdf.rb,
lib/macaw/rules/sketch.rb,
lib/macaw/rules/animate.rb,
lib/macaw/rules/dvipdfm.rb,
lib/macaw/rules/nomencl.rb,
lib/macaw/rules/songidx.rb,
lib/macaw/rules/xelatex.rb,
lib/macaw/rules/dvipdfmx.rb,
lib/macaw/rules/lmkclean.rb,
lib/macaw/rules/lualatex.rb,
lib/macaw/rules/pdflatex.rb,
lib/macaw/rules/texcount.rb,
lib/macaw/rules/makeindex.rb,
lib/macaw/rules/xdvipdfmx.rb,
lib/macaw/rules/xelatexmk.rb,
lib/macaw/rules/lualatexmk.rb,
lib/macaw/rules/pdflatexmk.rb,
lib/macaw/rules/sumatrapdf.rb,
lib/macaw/rules/dvipsps2pdf.rb,
lib/macaw/rules/frontespizio.rb,
lib/macaw/rules/makeglossaries.rb

Overview

MakeGlossaries rule for arara author: Marco Daniel requres arara 3.0+

Constant Summary collapse

VERSION =
"0.0.41"

Instance Method Summary collapse

Instance Method Details

#animate(delay = nil, loop = nil, density = nil) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/macaw/rules/animate.rb', line 19

def animate(delay=nil, loop=nil, density=nil)
  delay ||= 10
  loop ||= 0
  density ||= 300

  Macaw.system "convert -delay #{delay} -loop #{loop} -density #{density} #{~"#{@base}.pdf"} #{~"#{@base}.gif"}"
end

#biber(options = nil) ⇒ Object



5
6
7
# File 'lib/macaw/rules/biber.rb', line 5

def biber(options=nil)
  Macaw.system "biber #{options} #{~@base}"
end

#bibtex(options = nil) ⇒ Object



5
6
7
# File 'lib/macaw/rules/bibtex.rb', line 5

def bibtex(options=nil)
  Macaw.system "bibtex #{options} #{~"#{@base}.aux"}"
end

#clean(files) ⇒ Object



5
6
7
8
9
# File 'lib/macaw/rules/clean.rb', line 5

def clean(files)
  files.reject{|f| f.downcase == @file.downcase}.each{|f|
    File.unlink(f)
  }
end

#dvipdfm(options = nil, output = nil) ⇒ Object



5
6
7
8
# File 'lib/macaw/rules/dvipdfm.rb', line 5

def dvipdfm(options=nil, output=nil)
  output ||= @base
  Macaw.system "dvipdfm #{~"#{@base}.dvi"} -o #{~"#{output}.ps"} #{options}"
end

#dvipdfmx(output = nil, options = nil) ⇒ Object



5
6
7
8
# File 'lib/macaw/rules/dvipdfmx.rb', line 5

def dvipdfmx(options=nil, output=nil)
  output ||= @base
  Macaw.system "dvipdfmx #{~"#{@base}.dvi"} -o #{~"#{output}.ps"} #{options}"
end

#dvips(options = nil, output = nil) ⇒ Object



5
6
7
8
# File 'lib/macaw/rules/dvips.rb', line 5

def dvips(options=nil, output=nil)
  output ||= @base
  Macaw.system "dvips #{~"#{@base}.dvi"} -o #{~"#{output}.ps"} #{options}"
end

#dvipsps2pdf(options = nil, output = nil) ⇒ Object



5
6
7
8
9
# File 'lib/macaw/rules/dvipsps2pdf.rb', line 5

def dvipsps2pdf(options=nil, output=nil)
  output ||= @base
  Macaw.system "dvips #{~"#{@base}.dvi"} -o #{~"#{@base}.ps"} #{options}"
  Macaw.system "ps2pdf #{options} #{~"#{@base}.ps"} #{~"#{output}.pdf"}"
end

#frontespizio(engine) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/macaw/rules/frontespizio.rb', line 6

def frontespizio(engine)
  engine ||= 'pdflatex'

  Macaw.system "#{engine} #{~@base}"
  Macaw.system "#{engine} #{~"#{@base}-frn"}"
  Macaw.system "dvips -o #{~"#{@base}-frn.eps"} #{~"#{@base}-frn"}" if engine == 'latex'
  Macaw.system "#{engine} #{~@base}"
end

#indent(overwrite = nil, silent = nil, trace = nil, localSettings = nil, output = nil, onlyDefault = nil, cruft = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/macaw/rules/indent.rb', line 22

def indent(overwrite=nil, silent=nil, trace=nil, localSettings=nil, output=nil, onlyDefault=nil, cruft=nil)
  cmd = ["latexindent.#{OS.windows? ? 'exe' : 'pl'}"]
  cmd << '-s' if silent
  cmd << '-t' if trace
  cmd << '-l' if localSettings
  cmd << "-c=#{~cruft}" if cruft
  cmd << '-w' if overwrite
  cmd << '-d' if onlyDefault
  cmd << "-o #{~output}" if output
  cmd << ~@file
  cmd << ~output if output

  Macaw.system cmd
end

#latex(action = nil, shell = nil, synctex = nil, draft = nil, options = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/macaw/rules/latex.rb', line 6

def latex(action=nil, shell=nil, synctex=nil, draft=nil, options=nil)
  cmd = ['latex']
  cmd << "--interaction=#{action}" if action
  cmd << '--draftmode' if draft
  cmd << shell ? '--shell-escape' : '--no-shell-escape'
  cmd << "--synctex=#{synctex ? 1 : 0}"
  cmd << options
  cmd << ~@file

  Macaw.system cmd
end

#lmkclean(include = nil) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/macaw/rules/lmkclean.rb', line 5

def lmkclean(include=nil)
  include ||= '-c'

  cmd = ['latexmk']
  cmd << include.downcase if include && %w{all -c}.include(include.downcase)
  cmd << ~@file
  Macaw.system cmd
end

#lualatex(action = nil, shell = nil, synctex = nil, draft = nil, options = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/macaw/rules/lualatex.rb', line 6

def lualatex(action=nil, shell=nil, synctex=nil, draft=nil, options=nil)
  cmd = ['lualatex']
  cmd << "--interaction=#{action}" if action
  cmd << '--draftmode' if draft
  cmd << "--#{shell ? '' : 'no-'}shell-escape"
  cmd << "--synctex=#{synctex ? 1 : 0}"
  cmd << options
  cmd << ~@file

  Macaw.system cmd
end

#lualatexmk(action = nil, shell = nil, synctex = nil, options = nil, style = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/macaw/rules/lualatexmk.rb', line 5

def lualatexmk(action=nil, shell=nil, synctex=nil, options=nil, style=nil)
  cmd = []
  cmd << "latexmk -e '$pdflatex=q/lualatex%O%S/'"
  cmd << "--interaction=#{action}" if action
  cmd << "--synctex=#{synctex ? 1 : 0}"
  cmd << shell ? '--shell-escape' : '--no-shell-escape'
  cmd << options
  cmd << "$makeindex=q/makeindex %O -s #{style}.ist -o %D %S/" if style
  cmd << "-pdf #{~@file}"

  Macaw.system cmd
end

#luatex(action = nil, shell = nil, synctex = nil, draft = nil, options = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/macaw/rules/luatex.rb', line 6

def luatex(action=nil, shell=nil, synctex=nil, draft=nil, options=nil)
  cmd = ['luatex']
  cmd << "--interaction=#{action}" if action
  cmd << '--draftmode' if draft
  cmd << "--#{shell ? '' : 'no-'}shell-escape"
  cmd << "--synctex=#{synctex ? 1 : 0}"
  cmd << options
  cmd << ~@file

  Macaw.system cmd
end

#make(task = nil) ⇒ Object



6
7
8
# File 'lib/macaw/rules/make.rb', line 6

def make(task=nil)
  Macaw.system ['make', task]
end

#makeglossaries(options = nil) ⇒ Object



5
6
7
8
# File 'lib/macaw/rules/makeglossaries.rb', line 5

def makeglossaries(options=nil)

  Macaw.system ['makeglossaries', options, ~@base]
end

#makeindex(style = nil, german = nil, options = nil, extension = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/macaw/rules/makeindex.rb', line 6

def makeindex(style=nil, german=nil, options=nil, extension=nil)
  extension ||= 'idx'

  cmd = ['makeindex']
  cmd << '-g' if german
  cmd << "-s #{style}" if style
  cmd << ~"#{@base}.#{extension}"

  Macaw.system cmd
end

#nomencl(style = nil, options = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/macaw/rules/nomencl.rb', line 6

def nomencl(style=nil, options=nil)
  style ||= nomencl

  cmd = ['makeindex']
  cmd << options
  cmd << ~"#{@base}.nlo"
  cmd << '-s ' + ~"#{style}.ist" if style
  cmd << '-o ' + ~"#{@base}.nls"

  Macaw.system cmd
end

#pdflatex(action = nil, shell = nil, synctex = nil, draft = nil, options = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/macaw/rules/pdflatex.rb', line 6

def pdflatex(action=nil, shell=nil, synctex=nil, draft=nil, options=nil)
  cmd = ['pdflatex']
  cmd << "--interaction=#{action}" if action
  cmd << '--draftmode' if draft
  cmd << shell ? '--shell-escape' : '--no-shell-escape'
  cmd << "--synctex=#{synctex ? 1 : 0}"
  cmd << options
  cmd << ~@file

  Macaw.system cmd
end

#pdflatexmk(action = nil, shell = nil, synctex = nil, options = nil, style = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/macaw/rules/pdflatexmk.rb', line 5

def pdflatexmk(action=nil, shell=nil, synctex=nil, options=nil, style=nil)
  cmd = ["latexmk -e '$pdflatex=q/pdflatex%O%S/'"]
  cmd << "--interaction=#{action}" if action
  cmd << "--synctex=#{synctex ? 1 : 0}"
  cmd << "--#{shell ? '' : 'no-'}shell-escape"
  cmd << options
  cmd << "-e '$makeindex=q/makeindex %O -s #{~"#{style}.ist"} -o %D %S/'" if style
  cmd << '-pdf'
  cmd << ~@file

  Macaw.system cmd
end

#pdftex(action = nil, shell = nil, synctex = nil, draft = nil, options = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/macaw/rules/pdftex.rb', line 5

def pdftex(action=nil, shell=nil, synctex=nil, draft=nil, options=nil)
  cmd = ['pdftex']
  cmd << "--interaction=#{action}" if action
  cmd << '--draftmode' if draft
  cmd << "--#{shell ? '' : 'no-'}shell-escape"
  cmd << "--synctex=#{synctex ? 1 : 0}"
  cmd << options
  cmd << ~@file

  Macaw.system cmd
end

#ps2pdf(options = nil, output = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/macaw/rules/ps2pdf.rb', line 6

def ps2pdf(options=nil, output=nil)
  output ||= @base

  cmd = ['ps2pdf']
  cmd << options
  cmd << ~"#{@base}.ps"
  cmd << ~"#{output}.pdf"

  Macaw.system cmd
end

#sketch(options = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/macaw/rules/sketch.rb', line 5

def sketch(options=nil)
  cmd = ['sketch']
  cmd << options
  cmd << ~@file
  cmd << '-o'
  cmd << ~"#{@base}.tex"

  Macaw.system cmd
end

#songidx(input) ⇒ Object



5
6
7
# File 'lib/macaw/rules/songidx.rb', line 5

def songidx(input)
  Macaw.system "songidx " + ~"#{input}.sxd"
end

#sumatrapdf(pdf = nil) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/macaw/rules/sumatrapdf.rb', line 3

def sumatrapdf(pdf=nil)
  pdf ||= "#{@base}.pdf"

  Macaw.log('spawning sumatrapdf...')
  pdf = ~pdf
  Process.spawn "sumatrapdf -reuse-instance #{pdf}"
end

#tex(action, shell = nil, options = nil) ⇒ Object



6
7
8
# File 'lib/macaw/rules/tex.rb', line 6

def tex(action, shell=nil, options=nil)
  Macaw.system ['tex', action ? "--interaction=#{action}" : nil, "--#{shell ? '' : 'no-'}shell-escape", options, ~@file]
end

#texcount(includes = nil) ⇒ Object

this probably needs to be a lot fancier, but I can’t be arsed about it right now.



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
# File 'lib/macaw/rules/texcount.rb', line 8

def texcount(includes=nil)

  count = {}
  Macaw.system(['texcount', ~@file], return: :array).each{|line|
    Macaw.log(line)

    case line
      when /^Words in text:\s*([0-9]+)/
        count[:all] = Integer($1)
      when /\s([0-9]+)\+[0-9]+\+[0-9]\s+\([0-9]+\/[0-9]+\/[0-9]+\/[0-9]+\)\s+Section:\s*([^}]+)/
        count[$2.strip] = Integer($1)
    end
  }

  cleanfile = lambda{|f|
    dir = File.dirname(f)
    file = File.basename(f)

    file = I18n.transliterate(file) # fold diacritics where possible
    file.gsub!(/[^!-~]/, '') # remove non-ascii characters
    file.gsub!(/#<\$\+%>!`&\*'\|{\?"=}\/:\\@/, '') # remove problematic characters
    File.join(dir, file)
  }

  if includes
    Dir["#{@base}*.count.txt"].each{|f| File.unlink(f) }
    count.each_pair{|k, v|
      f = cleanfile.call(@base + (k == :all ? '' : ".#{k}") + ".count.txt")
      File.open(f, 'w') {|f| f.write(v)}
    }
  end
end

#xelatex(action, shell = nil, synctex = nil, options = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/macaw/rules/xelatex.rb', line 6

def xelatex(action, shell=nil, synctex=nil, options=nil)
  Macaw.system [
    'xelatex',
    "--interaction=#{action}",
    "--#{shell ? '' : 'no-'}shell-escape",
    "--synctex=#{syntex ? 1 : 0}",
    options,
    ~@file
  ]
end

#xelatexmk(action, shell = nil, synctex = nil, style = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/macaw/rules/xelatexmk.rb', line 5

def xelatexmk(action, shell=nil, synctex=nil, style=nil)
  Macaw.system [
    "latexmk -e '$pdflatex=q/xelatex%O%S/' --interaction=#{action} --synctex=#{synctex ? 1 : 0} --#{shell ?  '' : 'no-'}shell-escape",
    options, 
    style ? "-e '$makeindex=q/makeindex %O -s #{style}.ist -o %D %S/'" : nil,
    '-pdf',
    ~@file
  ]
end

#xetex(action, shell = nil, synctex = nil, options = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/macaw/rules/xetex.rb', line 5

def xetex(action, shell=nil, synctex=nil, options=nil)
  Macaw.system [
    'xetex',
    "--interaction=#{action}",
    "--#{shell ? '' : 'no-'}shell-escape",
    "--synctex=#{synctex ? 1 : 0}",
    options,
    ~@file
  ]
end