-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit.sh
More file actions
executable file
·267 lines (232 loc) · 7.14 KB
/
submit.sh
File metadata and controls
executable file
·267 lines (232 loc) · 7.14 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOURCE_DIR="$REPO_ROOT/sub_1"
BUILD_DIR="$REPO_ROOT/build"
PDF_DIR="$REPO_ROOT/dist/pdf"
EXPORT_DIR="$REPO_ROOT/dist/export"
TARGET="${1:-all}"
die() {
printf 'Error: %s\n' "$1" >&2
exit 1
}
require_command() {
command -v "$1" >/dev/null 2>&1 || die "Required command not found: $1"
}
sanitize_pdf_metadata() {
local pdf_file="$1"
local sanitized_file="${pdf_file%.pdf}.sanitized.pdf"
if ! command -v gs >/dev/null 2>&1; then
printf 'Warning: ghostscript not found; blind PDF metadata was not sanitized.\n' >&2
return 0
fi
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
-sOutputFile="$sanitized_file" \
-c "[ /Title (A reusable Elsevier submission workflow for SustainLab manuscripts) /Author (Anonymous) /Subject () /Keywords () /Creator (SustainLab Elsevier submission workflow) /Producer (SustainLab Elsevier submission workflow) /DOCINFO pdfmark" \
-f "$pdf_file"
mv "$sanitized_file" "$pdf_file"
}
strip_latex_text() {
perl -0pe '
s/%.*$//mg;
s/\\[a-zA-Z@]+(?:\[[^][]*\])?(?:\{[^{}]*\})?/ /g;
s/[{}]/ /g;
s/\s+/ /g;
' "$1"
}
graphical_abstract_asset() {
local extension
for extension in pdf png jpg jpeg; do
if [[ -f "$SOURCE_DIR/graphical_abstract.$extension" ]]; then
printf '%s\n' "graphical_abstract.$extension"
return 0
fi
done
return 1
}
validate_placeholders() {
if rg -n '\b(TITLE|HIGHLIGHT|KEYWORD|Author2)\b|example-image' "$SOURCE_DIR"/*.tex "$SOURCE_DIR"/*.bib >/dev/null; then
die "Submission source still contains placeholder tokens."
fi
}
validate_todos() {
if rg -n '\\todo|\\todoo|\\rewrite' "$SOURCE_DIR"/*.tex >/dev/null; then
die "Submission source still contains draft todo commands."
fi
}
validate_abstract() {
local abstract_words
abstract_words="$(strip_latex_text "$SOURCE_DIR/abstract.tex" | wc -w | tr -d ' ')"
if (( abstract_words > 250 )); then
die "Abstract exceeds the 250 word limit ($abstract_words words)."
fi
}
validate_keywords() {
local keyword_count
keyword_count="$(
perl -0ne '
s/%.*$//mg;
s/\n/ /g;
@items = grep { /\S/ } map { s/^\s+|\s+$//gr } split(/\\sep/, $_);
print scalar(@items);
' "$SOURCE_DIR/keywords.tex"
)"
if (( keyword_count < 1 || keyword_count > 7 )); then
die "Keyword count must be between 1 and 7 (found $keyword_count)."
fi
}
validate_highlights() {
local count=0
local line
while IFS= read -r line; do
[[ "$line" =~ ^[[:space:]]*\\item[[:space:]]+(.+)$ ]] || continue
local text="${BASH_REMATCH[1]}"
text="$(printf '%s\n' "$text" | perl -0pe 's/\\[a-zA-Z@]+(?:\[[^][]*\])?(?:\{[^{}]*\})?/ /g; s/[{}]/ /g; s/\s+/ /g; s/^ //; s/ $//;')"
local length=${#text}
((count += 1))
if (( length > 85 )); then
die "Highlight $count exceeds 85 characters ($length characters)."
fi
done < "$SOURCE_DIR/highlights_content.tex"
if (( count < 3 || count > 5 )); then
die "Highlight count must be between 3 and 5 (found $count)."
fi
}
validate_bibliography() {
rg -q '^@' "$SOURCE_DIR/bib.bib" || die "Bibliography database is empty."
}
validate_citations() {
if ! rg -q '\\cite[a-zA-Z]*\{' "$SOURCE_DIR/paper.tex" "$SOURCE_DIR/content.tex" "$SOURCE_DIR/abstract.tex"; then
die "Manuscript source must contain at least one citation command."
fi
}
validate_source() {
require_command latexmk
require_command pdflatex
require_command bibtex
require_command rg
require_command perl
validate_placeholders
validate_todos
validate_abstract
validate_keywords
validate_highlights
validate_bibliography
validate_citations
}
compile_latex() {
local tex_file="$1"
local build_name="$2"
local output_name="$3"
local build_path="$BUILD_DIR/$build_name"
mkdir -p "$build_path" "$PDF_DIR"
(
cd "$SOURCE_DIR"
latexmk -norc -pdf -interaction=nonstopmode -file-line-error -halt-on-error \
-outdir="$build_path" "$tex_file"
)
cp "$build_path/${tex_file%.tex}.pdf" "$PDF_DIR/$output_name"
}
build_full() {
validate_source
compile_latex "paper.tex" "paper_full" "paper_full.pdf"
}
build_blind() {
validate_source
compile_latex "paper_blind.tex" "paper_blind" "paper_blind.pdf"
sanitize_pdf_metadata "$PDF_DIR/paper_blind.pdf"
}
build_titlepage() {
validate_source
compile_latex "titlepage.tex" "titlepage" "titlepage.pdf"
}
build_highlights() {
validate_source
compile_latex "highlights.tex" "highlights" "highlights.pdf"
}
build_graphical_abstract() {
validate_source
if ! graphical_abstract_asset >/dev/null; then
printf 'Skipping graphical abstract: no graphical_abstract asset found in sub_1/.\n'
return 0
fi
compile_latex "graphical_abstract.tex" "graphical_abstract" "graphical_abstract.pdf"
}
build_all() {
build_full
build_blind
build_titlepage
build_highlights
build_graphical_abstract
}
export_bundle() {
local asset=""
validate_source
build_blind
build_titlepage
build_highlights
if asset="$(graphical_abstract_asset 2>/dev/null)"; then
build_graphical_abstract
fi
rm -rf "$EXPORT_DIR"
mkdir -p "$EXPORT_DIR"
cp "$SOURCE_DIR"/paper.tex "$EXPORT_DIR"/paper.tex
cp "$SOURCE_DIR"/paper_blind.tex "$EXPORT_DIR"/paper_blind.tex
cp "$SOURCE_DIR"/titlepage.tex "$EXPORT_DIR"/titlepage.tex
cp "$SOURCE_DIR"/highlights.tex "$EXPORT_DIR"/highlights.tex
cp "$SOURCE_DIR"/highlights_content.tex "$EXPORT_DIR"/highlights_content.tex
cp "$SOURCE_DIR"/settings.tex "$EXPORT_DIR"/settings.tex
cp "$SOURCE_DIR"/metadata.tex "$EXPORT_DIR"/metadata.tex
cp "$SOURCE_DIR"/abstract.tex "$EXPORT_DIR"/abstract.tex
cp "$SOURCE_DIR"/keywords.tex "$EXPORT_DIR"/keywords.tex
cp "$SOURCE_DIR"/authors.tex "$EXPORT_DIR"/authors.tex
cp "$SOURCE_DIR"/content.tex "$EXPORT_DIR"/content.tex
cp "$SOURCE_DIR"/bib.bib "$EXPORT_DIR"/bib.bib
cp "$PDF_DIR"/paper_blind.pdf "$EXPORT_DIR"/paper_blind.pdf
cp "$PDF_DIR"/titlepage.pdf "$EXPORT_DIR"/titlepage.pdf
cp "$PDF_DIR"/highlights.pdf "$EXPORT_DIR"/highlights.pdf
if [[ -n "$asset" ]]; then
cp "$SOURCE_DIR"/graphical_abstract.tex "$EXPORT_DIR"/graphical_abstract.tex
cp "$SOURCE_DIR/$asset" "$EXPORT_DIR/$asset"
cp "$PDF_DIR"/graphical_abstract.pdf "$EXPORT_DIR"/graphical_abstract.pdf
fi
}
clean_outputs() {
rm -rf "$BUILD_DIR" "$REPO_ROOT/dist"
find "$SOURCE_DIR" -maxdepth 1 -type f \
\( -name '*.aux' -o -name '*.bbl' -o -name '*.blg' -o -name '*.fdb_latexmk' \
-o -name '*.fls' -o -name '*.log' -o -name '*.out' -o -name '*.spl' \
-o -name '*.acn' -o -name '*.acr' -o -name '*.alg' -o -name '*.ist' \
-o -name '*.abs' \) \
-delete
rm -f "$SOURCE_DIR/paper.pdf" "$SOURCE_DIR/paper_blind.pdf" "$SOURCE_DIR/highlights.pdf" "$SOURCE_DIR/titlepage.pdf"
}
case "$TARGET" in
full)
build_full
;;
blind)
build_blind
;;
titlepage)
build_titlepage
;;
highlights)
build_highlights
;;
graphicalabstract)
build_graphical_abstract
;;
all)
build_all
;;
export)
export_bundle
;;
clean)
clean_outputs
;;
*)
die "Unknown target '$TARGET'. Use: full, blind, titlepage, highlights, graphicalabstract, all, export, clean."
;;
esac