code: def booklet_nup_pdf(input_filename: str, output_filename: str,
                      latex_paper_size: str = LATEX_PAPER_SIZE_A4) -> str:
      
      log.info("Creating booklet")
      log.debug("... {!r} -> {!r}", input_filename, output_filename)
      require(PDFJAM, HELP_MISSING_PDFJAM)
      n_pages = get_page_count(input_filename)
      n_sheets = calc_n_sheets(n_pages)
      log.debug("{} pages => {} sheets", n_pages, n_sheets)
      pagenums = page_sequence(n_sheets, one_based=True)
      pagespeclist = [str(p) if p <= n_pages else "{}"
                      for p in pagenums]
      # ... switches empty pages to "{}", which is pdfjam notation for
      # an empty page.
      pagespec = ",".join(pagespeclist)
      pdfjam_tidy = True  # clean up after yourself?
      args = [
          PDFJAM,
          "--paper", latex_paper_size,
          "--landscape",
          "--nup", "2x1",
          "--keepinfo",  # e.g. author information
          "--outfile", output_filename,
          "--tidy" if pdfjam_tidy else "--no-tidy",
          "--",  # "no more options"
          input_filename, pagespec
      ]
      run(args)
      return output_filename
docs: Takes a PDF (e.g. A4) and makes a 2x1 booklet (e.g. 2xA5 per A4).
      The booklet can be folded like a book and the final pages will be in order.
      Returns the output filename.