forked from apuntes-uam-infomat/apuntes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_subject
executable file
·69 lines (49 loc) · 1.29 KB
/
create_subject
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
name=$1
abbr=$2
[ -z "$name" ] && (echo "usage: create_subject name [abbreviature for tex file]"; exit)
[ -z "$abbr" ] && abbr=$(echo "$name" | tr -d ' ')
echo "Creating folder structure for subject $name. Filename: $abbr"
mkdir "$name"
cd "$name"
extra_folders="img pdf tex tikzgen"
extra_tex_files_suffixes="Ejs"
extra_tex_files_input=""
for folder in $extra_folders; do
mkdir $folder
touch $folder/.keep
echo "Created directory $name/$folder with .keep file."
done
touch "$abbr.tex"
for suffix in $extra_tex_files_suffixes; do
texfile="tex/${abbr}_${suffix}.tex"
printf -v extra_tex_files_input "$extra_tex_files_input\n\chapter{---}\n\\input{$texfile}"
echo "% -*- root: ../${abbr}.tex -*-" > $texfile
echo "Created extra file $texfile"
done
current_year=$(date +%y)
if [ $(date +%m ) -ge 08 ] ; then # ¿Primer o segundo cuatrimestre?
docdate="$current_year/$((current_year + 1)) C1"
else
docdate="$((current_year - 1))/$current_year C2"
fi
cat << EOF > "$abbr.tex"
\documentclass{apuntes}
\title{$name}
\author{}
\date{$docdate}
% Paquetes adicionales
% --------------------
\begin{document}
\pagestyle{plain}
\maketitle
\tableofcontents
\newpage
% Contenido.
%% Apéndices (ejercicios, exámenes)
\appendix
$extra_tex_files_input
\printindex
\end{document}
EOF
echo "Done."