Download the repository. Add your qems output csv and update the settings.txt file to reflect your qems output filename and the name of your set. Install pandas and pdflatex. Run the Python script.
The program will generate pdf packet files but also the .tex files, which can be used to correct imperfections.
The script will generate p = q / 20 packets, where q is the number of tossups/bonuses.
The tossups are divided into categories based on the listed subcategories (e.g. "History - European") and into major categories (e.g. "History") based on the first word of their category. Any category with more than p tossups has 1 randomly selected tossup placed into each packet. This is repeated until all categories have fewer the p tossups, at which point the remaining tossups are pooled into major categories and shuffled. With this new list of "excess tossups," one tossup at a time is placed into each packet until all of the packets are full. This process is then repeated for bonuses.
Based on common principles of packetization, the tossups and bonuses within each packet are shuffled randomly until they fulfill the following criteria:
- No tossup has the same major category as the bonus at the same position.
- No major category should appear in two consecutive tossups or in two consecutive bonuses.
- The last tossup should not be geography, current events, or trash.
Thanks to Harris Bunker for letting me use a complete qems output file of his for testing (that's the sample file that appears in the repository).
Note that while the algorithm works, there will very likely be imperfections in the resulting packet pdfs and if you decide to try using this tool I would recommend closely checking over the result and having a rudimentary knowledge of LaTeX in order to make small adjustments as needed.
Github repo link: https://github.com/ArjunPanickssery/PacketBuilder