# File vpp, line 476
def doselection(selection, booklet, evenodd, lpropt, output)
  includeopt = booklet ? ', booklet, landscape' : ''
  pagesel = evenodd ? "\\usepackage[#{evenodd}]{pagesel}" : ''
  outpdf = 'vpp.pdf'
  # if the whole document is selected, without booklet or twosided printing, 
  # we can simply print the original pdf or, if a copy is requested with the
  # o command, copy it to the new pdf, saving link information which is lost
  # otherwise:
  unless includeopt + pagesel + selection == '-' # unless just a copy needed
    begin
      open('vpp.tex','w') do |tex|
        tex.print "\\\\documentclass[pdftex]{article}\n\\\\usepackage[papersize={\#{@width}bp,\#{@height}bp}]{geometry}\n\#{pagesel} % require *before* pdfpages\n\\\\usepackage{pdfpages}[2004/03/27]\n\\\\begin{document}\n\\\\includepdf[pages={\#{selection}}\#{includeopt}]{\#{@filename}}\n\\\\end{document}\n"
      end
    rescue
      quit("Could not create vpp.tex in #{TMPDIR}: #{$!}",1)
    end
    h = sys("PDFLATEX='pdflatex -interaction=batchmode' texi2dvi -p #{@verbose ? '' : '-q'} vpp.tex")
    quit(h.error) unless h.success
  else
    outpdf = 'main.pdf'
  end
  if output
    output += '_' if evenodd
    to = (output+(evenodd||'')+'.pdf').sub(/\.pdf\.pdf/,'.pdf')
    warn "copying #{outpdf} to #{to}" if @verbose
    open(to,'w') { |p| p.write(open(outpdf).read) } or
      quit("Unexpected error: could not open #{to} for writing the pdf")
    puts "#{to} written"
  else
    h = sys("#{PRINTER} #{@printer} #{lpropt} #{outpdf}") 
    quit(h.error) unless h.success
  end
end