#!/usr/bin/env bash # Build a flat, self-contained submission folder for Computers & Geosciences in # paper_cg/submission/ (gitignored): editable LaTeX source with the CAS class files, # refs.bib and main.bbl, figures as separate files named Figure_1..Figure_N in order of # appearance, the highlights file, the supplement PDF, and a test compile of the flat copy. # Run from paper_cg/ after building supplement.pdf and main.pdf (see README.md). set -euo pipefail cd "$(dirname "$0")" OUT=submission rm -rf "$OUT"; mkdir -p "$OUT" for f in supplement.aux supplement.pdf main.pdf main.bbl; do [ -f "$f" ] || { echo "missing $f: build the supplement and main first" >&2; exit 1; } done cp els-cas-templates/cas-sc.cls els-cas-templates/cas-common.sty \ els-cas-templates/cas-model2-names.bst "$OUT"/ cp -r els-cas-templates/thumbnails "$OUT"/ # icons used by the class for e-mail/ORCID cp ../paper/refs.bib main.bbl supplement.aux supplement.pdf highlights.txt "$OUT"/ python3 - "$OUT" <<'PY' import re, shutil, sys out = sys.argv[1] s = open('main.tex').read() figs = re.findall(r'\\includegraphics(?:\[[^\]]*\])?\{([^}]+)\}', s) for n, f in enumerate(figs, 1): shutil.copy(f'../paper/figures/{f}', f'{out}/Figure_{n}.pdf') s = s.replace('{' + f + '}', '{' + f'Figure_{n}.pdf' + '}', 1) s = s.replace(r'\graphicspath{{../paper/figures/}}', '') s = s.replace(r'\bibliography{../paper/refs}', r'\bibliography{refs}') code = '\n'.join(l.split('%')[0] for l in s.splitlines()) assert '../paper' not in code, 'unresolved ../paper path' open(f'{out}/main.tex', 'w').write(s) print('\n'.join(f'Figure_{n}.pdf <- {f}' for n, f in enumerate(figs, 1))) PY mv "$OUT/main.bbl" "$OUT/main.bbl.orig" ( cd "$OUT" && pdflatex -interaction=nonstopmode main >/dev/null && { bibtex main >/dev/null || true; } \ && pdflatex -interaction=nonstopmode main >/dev/null && pdflatex -interaction=nonstopmode main >/dev/null ) cmp -s "$OUT/main.bbl" "$OUT/main.bbl.orig" && rm "$OUT/main.bbl.orig" || { echo "bbl differs from the main build" >&2; exit 1; } if grep -q "undefined" "$OUT/main.log"; then echo "undefined references in the flat copy" >&2; exit 1; fi rm -f "$OUT"/main.{aux,blg,log,out,abs} echo "flat copy compiles: $OUT/main.pdf"