Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handout Switch #45

Merged
merged 2 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions latex_main/main.tex
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
\pdfminorversion=4 % for acroread
%\documentclass[aspectratio=169,t,xcolor={usenames,dvipsnames}]{beamer}
\documentclass[aspectratio=169,t,handout,xcolor={usenames,dvipsnames}]{beamer}
\ifdefined\ishandout
\documentclass[aspectratio=169,t,handout,xcolor={usenames,dvipsnames}]{beamer}
\else
\documentclass[aspectratio=169,t,xcolor={usenames,dvipsnames}]{beamer}
\fi

\usepackage{../beamerstyle}
\usepackage{dsfont}
\usepackage{bm}
Expand Down
57 changes: 32 additions & 25 deletions slides.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import re
import sys
from functools import partial
from pathlib import Path
import subprocess
import multiprocessing


try:
subprocess.run("pdftk", capture_output=True)
PDFTK_INSTALLED = True
Expand All @@ -16,6 +16,7 @@

GIT_REPO = Path("./") # Overwritten in main
DST_FOLDER = Path("dst/") # Overwritten in main
HANDOUT_MODE = False # Overwritten in main

FULL_PDF_NAME = "autoML"
PDF_AUTHOR = "Marius Lindauer"
Expand All @@ -35,29 +36,30 @@ def copy():
with copy_destination.open("wb") as d:
d.write(content)

#sorts the values(paths) of the dict created in weekly and full slides

# sorts the values(paths) of the dict created in weekly and full slides
def sort_paths(plist):
for i in range(1, len(plist)):
j = i-1
j = i - 1
nxt_element = plist[i]
#get the slide numbers
# get the slide numbers
number1 = int(''.join(filter(str.isdigit, nxt_element.name)))
number2 = int(''.join(filter(str.isdigit, plist[j].name)))

if number1 >= 10:
number1 /= 10

if number2 >= 10:
number2 /= 10
while number2 > number1 and j >= 0:
plist[j+1] = plist[j]

while number2 > number1 and j >= 0:
plist[j + 1] = plist[j]
j = j - 1
number2 = int(''.join(filter(str.isdigit, plist[j].name)))

if number2 >= 10:
number2 /= 10
plist[j+1] = nxt_element
plist[j + 1] = nxt_element


def weekly_slides():
Expand All @@ -71,7 +73,7 @@ def weekly_slides():
sources[week_number][1].append(file)
for key in sources:
sort_paths(sources[key][1])

for week_name, sources in sources.values():
pdftk(sources, DST_FOLDER / f"{week_name}.pdf", Author=PDF_AUTHOR, Title=week_name.replace("_", " - ").title())

Expand All @@ -83,31 +85,30 @@ def full_slides():
sources = {}
for file, week_number, slide_number in iter_all():
if week_number not in sources:
sources[week_number]= (file.parent.name, [])
sources[week_number] = (file.parent.name, [])
sources[week_number][1].append(file)
for key in sources:
sort_paths(sources[key][1])


key_list= list(sources)

key_list = list(sources)
key_list.sort()
sources_list= list()
sources_list = list()
for i in key_list:
sources_list.extend(sources[i][1])

pdftk(sources_list, DST_FOLDER / f"{FULL_PDF_NAME}.pdf", Author=PDF_AUTHOR, Title=FULL_PDF_NAME)


def compile_all():
files = (file for file, _, _ in iter_all(ext="tex"))
with multiprocessing.Pool(multiprocessing.cpu_count()) as pool:
pool.map(pdflatex, files)
pool.map(partial(pdflatex, handout=HANDOUT_MODE), files)


def compile_git():
files = (file for file, _, _ in iter_all(ext="tex") if check_git(file.with_suffix(".tex")))
with multiprocessing.Pool(multiprocessing.cpu_count()) as pool:
pool.map(pdflatex, files)
pool.map(partial(pdflatex, handout=HANDOUT_MODE), files)


def compile_single(week_id, slide_id):
Expand All @@ -121,7 +122,7 @@ def fits_identifier(week, slide):

files = (file for file, week, slide in iter_all(ext="tex") if fits_identifier(week, slide))
with multiprocessing.Pool(multiprocessing.cpu_count()) as pool:
pool.map(pdflatex, files)
pool.map(partial(pdflatex, handout=HANDOUT_MODE), files)


def cleanup():
Expand All @@ -138,7 +139,7 @@ def iter_all(ext="pdf"):
week_number = folder_pattern.match(week_folder.name)
if week_number is None: # folder does not match mattern
continue

week_number = int(week_number.group(1))

for file in week_folder.iterdir():
Expand Down Expand Up @@ -191,8 +192,12 @@ def pdftk(source, out_file, **meta_data) -> int:
return proc.returncode


def pdflatex(source) -> int:
args = ["pdflatex", "-interaction=nonstopmode", "-output-format=pdf", source]
def pdflatex(source, handout=False) -> int:
args = ["pdflatex", "-interaction=nonstopmode", "-output-format=pdf"]
if handout:
args.append(f"\\PassOptionsToClass{{handout}}{{beamer}}\\input{{{Path(source).as_posix()}}}")
else:
args.append(source)
print(args, file=sys.stderr)
proc = subprocess.run(args, cwd=str(source.parent), stdout=subprocess.PIPE)
if proc.returncode != 0:
Expand Down Expand Up @@ -226,12 +231,14 @@ def main():
action='store_true')
parser.add_argument("--compile-all", help="Compile all slides", action='store_true')
parser.add_argument("--cleanup", help="Cleanup all temporary latex files (aux, log, ...)", action='store_true')
parser.add_argument("--handout", help="Compile slides in handout-mode (more compact, no animation slides)", action='store_true')

args = parser.parse_args()

global GIT_REPO, DST_FOLDER
global GIT_REPO, DST_FOLDER, HANDOUT_MODE
GIT_REPO = Path(args.source)
DST_FOLDER = Path(args.destination)
HANDOUT_MODE = args.handout

_did_smth = False
if args.compile_all:
Expand Down Expand Up @@ -261,4 +268,4 @@ def main():


if __name__ == '__main__':
main()
main()