-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_separate.sh
executable file
·134 lines (112 loc) · 3.83 KB
/
render_separate.sh
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/zsh
updated_file=$(basename $1)
shift
OPEN_WITH="/Applications/Visual Studio Code.app"
# Directory of .tex files mentioned in the main.tex
TEX_FILE_DIR="sections"
# Auxiliary directory name
OUTPUT_DIR="aux"
OUTPUT_PREFIX=""
########## FLAGS ##########
OPEN_FILES=false # Open pdf files after compilation
RENDER_PHOTO="\let\ifrenderphoto\iffalse" # Render photo at top left corner
## TESTING ##
RENDER_LOCATION="\let\ifrenderloc\iffalse" # Render location under the Name
#############
VERBOSE=false #
PRINT_LOG="> /dev/null" # Dump lualatex standard input if verbose is false
# Reading input options
while [ $# -gt 0 ]; do
case $1 in
-v|--verbose) # Verboes
VERBOSE=true
PRINT_LOG=""
shift
;;
-O|--open-files) # Open files
OPEN_FILES=true
shift
;;
-R|--render-photo) # Render photo
if $VERBOSE; then
echo "Creating the resume with photo."
fi
RENDER_PHOTO="\let\ifrenderphoto\iftrue"
shift
;;
-L|--render-location) # Render location
if $VERBOSE; then
echo "Creating the resume with location."
fi
RENDER_LOCATION="\let\ifrenderloc\iftrue"
shift
;;
-o|--output-prefix)
OUTPUT_PREFIX=$2
shift 2
;;
*) # Bad argument
echo "Invalide option -$OPTARG.\n"
echo "Usage: $0 [-v] [-O] [-R]\n"
echo "\t-v\n\t\tUsed to get more verbose status."
echo "\t-O\n\t\tUsed to open pdf files after the latex compilation is done."
echo "\t-R\n\t\tUsed to instruct the latex to render the photo at the begining of the resume."
echo "\t-L\n\t\tUsed to instruct the latex to render the location (address) under the full name."
exit 1
;;
esac
done
current_time=$(date +%H:%M:%S)
echo -n -e "\e[36m$current_time\e[0m $updated_file \e[33mUPDATED\e[0m Rendering in progress"
# Checking if output directory exists
if [ -d "$OUTPUT_DIR" ]; then
if $VERBOSE; then
echo "output directory exists."
fi
else
if $VERBOSE; then
echo "output directory does not exist.\nCreating the $OUTPUT_DIR directory."
fi
mkdir "$OUTPUT_DIR" # Creating output dir for aux files
fi
# Looping through tex files mentioned in main.tex
for TEX_FILE in "$TEX_FILE_DIR"/*.tex; do
if [ -f "$TEX_FILE" ]; then # Check if the texfile exists
# assembling lualatex command
command="lualatex --output-directory=$OUTPUT_DIR \"$RENDER_PHOTO$RENDER_LOCATION\input{$TEX_FILE}\" $PRINT_LOG"
output=$(eval "$command")
if [[ -n "$output" ]]; then
echo -e "\e[97;41mERROR\e[0m"
echo "$output"
exit 1
fi
else
echo "No tex file was found in $TEX_FILE_DIR directory."
return 0
fi
done
##########
# Moving pdf files from output directory to the root
# directory for easier access
##########
for PDF_FILE in "$OUTPUT_DIR"/*.pdf; do
if [ -f "$PDF_FILE" ]; then
# Adding prefix to the name of pdf files in case it's specified
if [[ -n "$OUTPUT_PREFIX" ]]; then
# Extract the filename and extension
filename=$(basename -- "$PDF_FILE")
extension="${filename##*.}"
filename="${filename%.*}"
# Create the new filename with the prefix
new_filename="${OUTPUT_PREFIX}_${filename}.${extension}"
mv "$PDF_FILE" ./"$new_filename"
PDF_FILE=./"$new_filename"
fi
# Opening all pdf files in the root directory if -O flag is set
if $OPEN_FILES; then
sleep 1
open -a "$OPEN_WITH" $new_filename
fi
fi
done
echo " ==> \e[42mSUCCESS\e[0m"