Created
May 10, 2021 02:18
-
-
Save zlatko-minev/adc3e040e8927501adf23c6f7dbf0db8 to your computer and use it in GitHub Desktop.
Example shell script to prepare lyx file to upload to arxiv or to journal with zip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Tested on MacOS | |
# @license: APACHE 2.0 | |
# @author: Zlatko K. Minev (2020) | |
############################################################### | |
### User define! | |
alias lyx="/Applications/LyX.app/Contents/MacOS/lyx" # # https://wiki.lyx.org/LyX/ManPage | |
DEST="_SUBMIT_" | |
MAIN="epr-main" # "$MAIN.lyx" | |
############################################################### | |
### General initialization | |
# Colors | |
red=$'\e[1;31m' | |
grn=$'\e[1;32m' | |
yel=$'\e[1;33m' | |
blu=$'\e[1;34m' | |
mag=$'\e[1;35m' | |
cyn=$'\e[1;36m' | |
end=$'\e[0m' | |
# horizontal rule; http://wiki.bash-hackers.org/snipplets/print_horizontal_line | |
hr() { | |
local start=$'\e(0' end=$'\e(B' line='qqqqqqqqqqqqqqqq' | |
local cols=${COLUMNS:-$(tput cols)} | |
while ((${#line} < cols)); do line+="$line"; done | |
echo "" | |
printf '%s%s%s\n' "$start" "${line:0:cols}" "$end" | |
echo "" | |
} | |
BASEDIR=$(dirname "$0") # directory of file | |
cd "${BASEDIR}" | |
#cd ".." | |
############################################################### | |
### Main | |
clear | |
printf "\n\n$grn Lyx to latex.$end\n\n" | |
echo "pwd: $grn$(pwd)$end" | |
# FOLDERS: delete dir & make | |
rm -rf "$DEST" | |
mkdir "$DEST" | |
mkdir "$DEST/img-main" # USER-SPECIFY | |
mkdir "$DEST/img-app" | |
############################################################### | |
### Export lyx | |
echo "$grn\nExport LyX -> TeX: $end" | |
lyx --force-overwrite --export pdflatex "$MAIN.lyx" | |
mv -f "$MAIN.tex" "$DEST/$MAIN.tex" | |
mv -f "epr-macros.tex" "$DEST/epr-macros.tex" # EXTRA FILES created by conversion, since included as include files | |
cp -f "epr-preamble.tex" "$DEST/epr-preamble.tex" # This is a tex file include din the lyx, so dont move, copy only, we need it | |
python __copy_python_utils__.py -d "$DEST" -f "$MAIN" | |
# Encoding: of file # https://stackoverflow.com/questions/805418/how-to-find-encoding-of-a-file-via-script-on-linux | |
echo "$yel File encodings: $end" | |
file -I "$DEST/$MAIN.tex" | |
file -I "$DEST/epr-macros.tex" | |
file -I "$DEST/epr-preamble.tex" | |
# Encoding: Check for invalind encoding in file - remove these manuallly. Use https://tex.stackexchange.com/tags/accents/info | |
echo "$yel\n Invalid encoding (non UTF-8):$end\n (Assumming locale is UTF-8)\n" # https://stackoverflow.com/questions/29465612/how-to-detect-invalid-utf8-unicode-binary-in-a-text-file | |
grep -axv '.*' "$DEST/$MAIN.tex" | |
grep -axv '.*' "$DEST/epr-macros.tex" | |
grep -axv '.*' "$DEST/epr-preamble.tex" | |
# Library file | |
echo "$yel\n Change library.$end" | |
sed -i'.backup' 's|../../library|library|g' "$DEST/$MAIN.tex" | |
cp "../../library.bib" "$DEST/library.bib" | |
rm -f "$DEST/$MAIN.tex.backup" | |
echo "$yel File encoding (after 'sed'): $end" | |
file -I "$DEST/$MAIN.tex" | |
############################################################### | |
# Copy all pdf files for figures | |
echo "$grn\nCopy figures: $end" | |
cp img-main/**.pdf "$DEST/img-main" | |
cp img-app/**.pdf "$DEST/img-app" | |
############################################################### | |
echo "\n\n\n$grn"; hr | |
echo " C O M P I L E " | |
echo "$end"; hr | |
echo $(type -a pdflatex) # should be something like pdflatex is /Library/TeX/texbin/pdflatex | |
echo $(type -a bibtex) | |
printf "\n\n\n\n"; hr | |
cd "$DEST" | |
pdflatex "$MAIN.tex"; hr | |
bibtex "$MAIN"; hr | |
pdflatex "$MAIN.tex"; hr | |
pdflatex -synctex=1 -interaction=nonstopmode "$MAIN.tex"; hr # SyncTeX is a utility written by Jérôme Laurens which enables synchronization between your source document and the PDF output. If your editor/viewer supports it, then you can click in your source and jump to the equivalent place in the PDF or click in the PDF and it will jump to the appropriate place in your source document. | |
### Check for errors | |
echo "\n\n" | |
echo "$grn\CHECK FOR ERRORS:" | |
echo "$end$grn\nCheck for errors: Latex $end $yel" | |
grep -i "error" "$MAIN.log" | |
echo "$end$grn\nCheck for errors: BibTex $end $yel" | |
grep -i "error" "$MAIN.blg" # Bibtex | |
echo "$end\n"; hr | |
echo "$grn\CHECK FOR WARNINGS:" | |
echo "$end$grn\nCheck for warnings: Latex $end $yel" | |
grep -i "warning" "$MAIN.log" | |
echo "$end$grn\nCheck for warnings: BibTex $end $yel" | |
grep -i "warning" "$MAIN.blg" # Bibtex | |
echo "$end"; hr; | |
if true | |
then # final run for Arxiv, make zip | |
# worry about hyperindex,breaklinks | |
echo "$grnClear, format, and zip for arxiv.org:$end" | |
cd .. | |
rm -f "$DEST.zip" | |
sed -i'.backup' 's|\\usepackage{pdfsync}||' "$DEST/$MAIN.tex" # arxiv doesn't need synctex | |
sed -i'.backup' 's|\\synctex=-1||' "$DEST/$MAIN.tex" | |
rm -f "$DEST/$MAIN.tex.backup" | |
rm -f "$DEST/$MAIN.aux" | |
rm -f "$DEST/$MAIN.blg" | |
rm -f "$DEST/$MAIN.log" | |
rm -f "$DEST/$MAIN.out" | |
rm -f "$DEST/$MAIN.synctex" | |
rm -f "$DEST/$MAIN.pdfsync" | |
rm -f "$DEST/$MAIN.synctex.gz" | |
#rm -f "$DEST/$MAIN.pdf" | |
rm -f "$DEST/library.bib" | |
# remove SI figures | |
rm -f "$DEST/img-app/FE_JJsurf.pdf" | |
rm -f "$DEST/img-app/FE-junc.pdf" | |
rm -f "$DEST/img-app/frustrated-circuit-ex-simplify.pdf" | |
rm -f "$DEST/img-app/frustrated-circuit-ex.pdf" | |
rm -f "$DEST/img-app/mechanical-analogy.pdf" | |
rm -f "$DEST/img-app/pumped-process.pdf" | |
rm -f "$DEST/img-app/signs-matter-example.pdf" | |
rm -f "$DEST/img-app/transmon-cavity-spectrum.pdf" | |
zip -r "$DEST.zip" "$DEST" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment