Skip to content

Commit

Permalink
Add script for automatic solution building with latexmk.
Browse files Browse the repository at this point in the history
  • Loading branch information
lschmelzeisen committed Feb 23, 2021
1 parent 7c141e6 commit 0d4940e
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 9 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.aux
*.bbl
*.bcf
*.blg
*.fdb_latexmk
*.fls
*.log
*.out
*.pdf
*.run.xml
*.toc
*-solution.tex
4 changes: 4 additions & 0 deletions .latexmkrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$pdf_mode = 1;
$pdflatex = 'pdflatex -synctex=1 -file-line-error -interaction=nonstopmode -halt-on-error %O %S';
$bibtex_use = 2;
@generated_exts = (@generated_exts, 'bbl', 'run.xml', 'synctex.gz');
2 changes: 1 addition & 1 deletion acAssignment.cls
Original file line number Diff line number Diff line change
Expand Up @@ -782,4 +782,4 @@
\clearpage%
\addtocounter{page}{-1}%
\thispagestyle{acBlankPage}%
\textit{\@acLocBlankPages}}}}
\textit{\@acLocBlankPages}}}}
4 changes: 2 additions & 2 deletions example-assignment-english.tex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
% Enable warnings about problematic code
\RequirePackage[l2tabu, orthodox]{nag}

\documentclass[solution]{acAssignment}
\documentclass{acAssignment}

% Parse this file as UTF-8 (included in LaTeX by default since 2018 but included
% here for backwards-compatibility). If you use something else, change this.
Expand Down Expand Up @@ -371,4 +371,4 @@ \section{First-order Basics}
\end{acSolution}
\end{enumerate}

\end{document}
\end{document}
4 changes: 2 additions & 2 deletions example-assignment-german.tex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
% Enable warnings about problematic code
\RequirePackage[l2tabu, orthodox]{nag}

\documentclass[german, solution]{acAssignment}
\documentclass[german]{acAssignment}

\acCourse[https://west.uni-koblenz.de/studying/ws1920/algorithmen-und-datenstrukturen]
{Algorithmen und Datenstrukturen}
Expand Down Expand Up @@ -448,4 +448,4 @@ \section{Hinweise zur Abgabe}
Um nun eine Testklasse auszuführen, Rechtsklick auf die entprechende \texttt{.java}-Datei und erst \texttt{Run As} und dann \texttt{JUnit Test} auswählen.
\end{itemize}

\end{document}
\end{document}
2 changes: 1 addition & 1 deletion example-bibliography.bib
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ @book{DBLP:books/lib/MittelbachGB04
publisher = {Addison-Wesley},
year = {2004},
url = {https://www.worldcat.org/oclc/53972111},
}
}
4 changes: 2 additions & 2 deletions example-exam-english.tex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
% Enable warnings about problematic code
\RequirePackage[l2tabu, orthodox]{nag}

\documentclass[exam, sectionseven, solution]{acAssignment}
\documentclass[exam, sectionseven]{acAssignment}

% Parse this file as UTF-8 (included in LaTeX by default since 2018 but included
% here for backwards-compatibility). If you use something else, change this.
Expand Down Expand Up @@ -393,4 +393,4 @@ \section{PageRank}

\acBlankPages{3}

\end{document}
\end{document}
2 changes: 1 addition & 1 deletion example-exam-german.tex
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,4 @@ \subsection{Einfügen}

\acBlankPages{3}

\end{document}
\end{document}
39 changes: 39 additions & 0 deletions latexmk-solutions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3

from pathlib import Path
import re
import subprocess

PATTERN = re.compile(
r"^\\documentclass\[?([^\]]*)\]?\{acAssignment\}", re.MULTILINE)

for tex_file in Path(".").iterdir():
if (
not tex_file.name.endswith(".tex") or
tex_file.name == "acAssignment.tex"
):
continue

tex_file_solution = (
tex_file.parent / (tex_file.name.replace(".tex", "-solution.tex"))
)

contents = tex_file.read_text(encoding="UTF-8")
match = PATTERN.search(contents)
if not match:
continue

options = [
option.strip()
for option in match.group(1).split(",")
if option.strip()
]
options.append("solution")
options_str = ", ".join(options)

contents_solution = PATTERN.sub(
rf"\\documentclass[{options_str}]{{acAssignment}}", contents
)
tex_file_solution.write_text(contents_solution, encoding="UTF-8")

subprocess.call(["latexmk"])

0 comments on commit 0d4940e

Please sign in to comment.