Commit e40f8fdf authored by Olivier's avatar Olivier
Browse files

M3: first commit

A working script for module M3 (producing PDFs based on the tex files
output by module M2).
Some input and output "proof-of-concept" data is provided as well.
parent cd5d1576
Script: create_pdfs.sh
======================
## Description
This script takes a series of `tex` files containing each a series of LaTeX variables with custom values, and produces, for each of those, a pair of `pdf` files: one contaning the assignment, and the other containing the corresponding solution.
The input files should be placed in the `script_input` folder which is in the same path as the script. The output files will be saved in the `script_output` folder.
## Dependencies
The script is run in a bash shell on a Ubuntu system. It makes use of the `pdflatex` compiler. The example `tex` file uses stylesheets from the [sensible styles](https://git.framasoft.org/u/olivier/sensible-styles) library.
## Script input
1. One `sample_problem_assignment.tex` and one `sample_problem_solution.tex` file, containing the basic LaTeX templates for the assignment and solution of the problem.
1. Any number of `parameters_ID_xxxxxxxx.tex` files, with xxxxxxxx the custom ID for each student, containing declarations for LaTeX variables and their numerical values, for example:
\newcommand{\codenumber}{17688816}
\newcommand{\pipediameter}{1.9}
\newcommand{\pipelength}{349.0}
\newcommand{\viscosity}{1.2e-2}
## Script output
For each input file, a pair of files named `assignment_ID_xxxxxxxx.pdf` and `solution_ID_xxxxxxxx.pdf`.
#!/bin/bash
# Input parameters
inputfolder='script_input'
outputfolder='script_output'
assignmentsourcefile="$inputfolder/assignment.tex"
solutionsourcefile="$inputfolder/solution.tex"
# Cleanup output folder
mkdir -v $outputfolder/old
rm -rvf $outputfolder/old/*
mv -vf $outputfolder/* $outputfolder/old/
# Create links to the source tex files in the current folder
# syntax: ln -s destination linkname
ln -svf "$assignmentsourcefile" assignment.tex
ln -svf "$solutionsourcefile" solution.tex
# Pick up all the files in input folder one by one
for parameterfile in "$inputfolder"/parameters_ID_*.tex; do
# What is the code number?
# Pick up parameter file name, strip all but number, call it $codenumber
codenumber=$(echo $parameterfile | sed "s/$inputfolder\/parameters_ID_//" | sed 's/\.tex//')
echo "#"
echo "#"
echo "building PDFs with code number of $codenumber..."
# Define input and output file names for this problem ID
parameterfilepath=$(echo $inputfolder/parameters_ID_$codenumber.tex)
assignmentfilepath=$(echo $outputfolder/assignment_ID_$codenumber.pdf)
solutionfilepath=$(echo $outputfolder/solution_ID_$codenumber.pdf)
# Make a link called "parameters.tex" that points to the specific
# parameters file for this ID
ln -svf "$parameterfilepath" parameters.tex
# Add LaTeX variable at the end of parameters.tex, which is just
# the custom ID:
echo "\newcommand{\codenumber}{$codenumber}" >> parameters.tex
# Empty up the tmp subfolder
rm -rf tmp/*
# Compile the actual PDF files:
# compile them with pdflatex
# then move the result to the output folder
pdflatex assignment.tex
mv -vf assignment.pdf $assignmentfilepath
pdflatex solution.tex
mv -vf solution.pdf $solutionfilepath
# Cleanup after pdflatex: move temporary files to tmp subfolder
mv -vf *.aux *.bbl *.bcf *.blg *.ilg *.log *.nav *.nlo *.nls *.run.xml *.snm *.toc *.out *.fls *.fdb_latexmk *.spl *-blx.bib *-eps-converted-to.pdf *bib.bak tmp/
done
# Remove remaining symlinks in main folder
rm -v parameters.tex assignment.tex solution.tex
echo "end of script."
\documentclass[12pt,a4paper]{article}
\usepackage{magdeburg1} % from https://git.framasoft.org/u/olivier/sensible-styles
\renewcommand{\authorofthisdocument}{Olivier Cleynen}
\renewcommand{\titleofthisdocument}{Example problem: assignment}
\usepackage{magdeburg2}
\input{parameters.tex}
\begin{document}
\begin{center}
~\vspace{2cm}\par
{\LARGE \titleofthisdocument\par}
\vspace{1em}
{\footnotesize Last modified \today\\
Olivier Cleynen -- olivier.cleynen@ovgu.de\\}
\vspace{2em}
\end{center}
\vspace{3cm}
\section{Introduction}
This example document is generated automatically for the student with the code number \num{\codenumber}.
\section{Problem}
An object has property $A = \SI{\dummyone}{\metre\per\second}$.
What is the value of $B$?
\end{document}
\newcommand{\pipediameter}{1.9}
\newcommand{\pipelength}{349.0}
\newcommand{\density}{1251.0}
\newcommand{\viscosity}{0.0062097}
\newcommand{\reynolds}{6223100.0}
\newcommand{\dummytwo}{0.0566}
\newcommand{\dummyone}{8120.0}
\newcommand{\meanvelocity}{1.234}
\newcommand{\massflow}{12.34}
\newcommand{\pipediameter}{1.9}
\newcommand{\pipelength}{172.0}
\newcommand{\density}{1157.0}
\newcommand{\viscosity}{0.1824009}
\newcommand{\reynolds}{18620310.0}
\newcommand{\dummytwo}{0.0554}
\newcommand{\dummyone}{7930.0}
\newcommand{\meanvelocity}{1.234}
\newcommand{\massflow}{12.34}
\newcommand{\pipediameter}{2.8}
\newcommand{\pipelength}{346.0}
\newcommand{\density}{1030.0}
\newcommand{\viscosity}{0.1494025}
\newcommand{\reynolds}{12641656.0}
\newcommand{\dummytwo}{0.0929}
\newcommand{\dummyone}{5540.0}
\newcommand{\meanvelocity}{1.234}
\newcommand{\massflow}{12.34}
\documentclass[12pt,a4paper]{article}
\usepackage{magdeburg1} % from https://git.framasoft.org/u/olivier/sensible-styles
\renewcommand{\authorofthisdocument}{Olivier Cleynen}
\renewcommand{\titleofthisdocument}{Example problem: solution}
\usepackage{magdeburg2}
\input{parameters.tex}
\begin{document}
\begin{center}
~\vspace{2cm}\par
{\LARGE \titleofthisdocument\par}
\vspace{1em}
{\footnotesize Last modified \today\\
Olivier Cleynen -- olivier.cleynen@ovgu.de\\}
\vspace{2em}
\end{center}
\vspace{3cm}
\section{Introduction}
This example document is the solution for the problem with code number \num{\codenumber}.\\
Please grade this fairly and rigorously. Thank you!
\section{Problem solution}
Since $A$ has the value $A = \SI{\dummyone}{\metre\per\second}$, we calculate that $B = \SI{\dummytwo}{\kelvin}$.
\end{document}
......@@ -29,7 +29,7 @@ A total of nine modules (six of which being locally-run scripts) are needed to r
[x] [Module 2](M2_customize_assignments): Generate custom variables for assignments
(in Python)
[ ] Module 3: Generate assignments and solutions
[x] [Module 3](M3_generate_assignments): Generate assignments and solutions
(in bash + LaTeX)
[ ] Module 4: Send assignments to students
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment