Skip to content

Commit

Permalink
Merge pull request #6 from IAS-Uni-Siegen/deployment
Browse files Browse the repository at this point in the history
add refactored build.py for exercise and update readme.md
  • Loading branch information
wallscheid authored Oct 22, 2024
2 parents bb70c5a + 5f978b9 commit f27adc5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 41 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This work is licensed under a
[cc-by-shield]: https://img.shields.io/badge/License-CC%20BY%204.0-lightgrey.svg

## Lecture slides (click on preview picture)
<a href="https://ias-uni-siegen.github.io/EMD_course/lecture.pdf" target="_blank" class="image fit"><img src="misc/Slide_preview.png" alt=""></a>
<a href="https://ias-uni-siegen.github.io/EMD_course/lecture.pdf" target="_blank" class="image fit"><img src="misc/Lecture_preview.png" alt=""></a>

The covered topics are:
- An initial overview of electrical machines and drives
Expand All @@ -31,3 +31,10 @@ The covered topics are:

## Exercise tasks including solutions (click on preview picture)
<a href="https://ias-uni-siegen.github.io/EMD_course/exercise_with_solution.pdf" target="_blank" class="image fit"><img src="misc/Exercise_with_solution_preview.png" alt=""></a>

## Exam history

| Exam | Only Tasks | Tasks with Solutions |
|------------|---------------------------------------------|-------------------------------------------------|
| Summer 2024 | [Only Tasks](https://ias-uni-siegen.github.io/EMD_course/summer2024.pdf) | [Tasks with Solutions](https://ias-uni-siegen.github.io/EMD_course/summer2024_with_solution.pdf) |
| Summer 2024 (mock-up)| [Only Tasks](https://ias-uni-siegen.github.io/EMD_course/summer2024_mock-up.pdf) | [Tasks with Solutions](https://ias-uni-siegen.github.io/EMD_course/summer2024_mock-up_with_solution.pdf) |
87 changes: 47 additions & 40 deletions exercise/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,63 @@ def clear_tex_binaries():
if not file.endswith(('.tex', '.pdf')):
os.remove(file)

def build_pdf(with_solution):
# Modify and build the main.tex file
clear_tex_binaries()

# build main pdf (with solutions)
clear_tex_binaries()
with fileinput.input('main.tex', inplace=True) as f:
for line in f:
if 'includeonly{' in line:
# comment out includeonly flag
print(f'%{line}', end='')
#check if the line including '\documentclass' has the parameter 'solution' - if not add it
elif '{exerciseClass}' in line:
if 'solution' not in line:
print(line.replace('{exerciseClass}', ', [solution]{exerciseClass}'), end='')
# Flag to ensure documentclass line is modified correctly
docclass_modified = False

with fileinput.input('main.tex', inplace=True) as f:
for line in f:
if 'includeonly{' in line:
# Comment out the includeonly flag
print(f'%{line}', end='')
# Look for the documentclass line
elif '\\documentclass' in line and 'exerciseClass' in line:
docclass_modified = True # Set the flag that we have modified the line

# Split documentclass into its components
preamble, class_info = line.split('{', 1)
class_name = class_info.rstrip('}\n') # Remove the trailing }

if with_solution:
# Add the [solution] option if not present
if '[' not in preamble:
preamble = preamble.replace('\\documentclass', '\\documentclass[solution]')
else:
preamble = preamble.replace('[', '[solution, ')
else:
# Remove the [solution] option if present
preamble = preamble.replace('[solution, ', '[').replace('[solution]', '')

# Reassemble the documentclass line
print(f'{preamble}{{{class_name}}}', end='\n')
else:
print(line, end='')
else:
print(line, end='')

call(call_pdflatex_l)
call(call_pdflatex_l)
print(line, end='')

# If we didn't modify the documentclass, raise an exception for debugging
if not docclass_modified:
raise ValueError("documentclass line with 'exerciseClass' not found or not modified.")

# Run pdflatex twice for proper compilation
call(call_pdflatex_l)
call(call_pdflatex_l)


# go into the parent directory
os.chdir('..')
os.makedirs('built', exist_ok=True)
#take main.pdf from the exercise folder and move it to the parent folder
os.replace('exercise/main.pdf', os.path.join('built', 'exercise_with_solution.pdf'))


# build main pdf (without solutions)
os.chdir('exercise')
clear_tex_binaries()
with fileinput.input('main.tex', inplace=True) as f:
for line in f:
if 'includeonly{' in line:
# comment out includeonly flag
print(f'%{line}', end='')
#check if the line including '\documentclass' has the parameter 'solution' - if yes remove it
elif '{exerciseClass}' in line:
if 'solution' in line:
print(line.replace('solution]{exerciseClass}', ']{exerciseClass}'), end='')
else:
print(line, end='')
else:
print(line, end='')

call(call_pdflatex_l)
call(call_pdflatex_l)

build_pdf(with_solution=True)
#os.makedirs('../built', exist_ok=True)
os.replace('main.pdf', os.path.join('../built', 'exercise_with_solution.pdf'))

# Build without solutions
build_pdf(with_solution=False)
os.replace('main.pdf', os.path.join('../built', 'exercise.pdf'))

# go into the parent directory
os.chdir('..')
#take main.pdf from the exercise folder and move it to the parent folder
os.replace('exercise/main.pdf', os.path.join('built', 'exercise.pdf'))
Binary file added misc/Lecture_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f27adc5

Please sign in to comment.