提交 arXiv 文章的(LaTeX)预处理技巧

提交基于 tex 的文章时,可使用下列 shell 脚本进行处理,快速生成需要提交的文件:

环境依赖:

  • latexpand
  • pdflatex
  • bibtex
#!/bin/bash

PS01="\033[01;35m\$\033[00m"

echo -e "\n${PS01} mv \033[4mmain.tex\033[0m \033[4mmain.tex.bak\033[0m"
mv main.tex main.tex.bak
latexpand --empty-comments main.tex.bak > main.tex
if [[ $OSTYPE == darwin* ]]; then
    sed -i '' -e '/^\s*%/d' main.tex
else
    sed -i -e '/^\s*%/d' main.tex
fi

echo -e "\n${PS01} pdflatex \033[4mmain.tex\033[0m"
pdflatex main.tex
echo -e "\n${PS01} bibtex main"
if [ -f "main.bbl" ]; then
    rm main.bbl
fi
bibtex main
echo -e "\n${PS01} pdflatex \033[4mmain.tex\033[0m"
pdflatex main.tex

echo -e "\n${PS01} rm \033[4mmain{.aux,.log,.out}\033[0m"
for suffix in .aux .blg .log .out; do
    if [ -f "main${suffix}" ]; then
        rm main${suffix}
    fi
done
echo -e "#########################################################"
echo -e "\n(1) Please \033[33mcheck\033[0m and then \033[33mdelete\033[0m the generated \033[4mmain.pdf\033[0m."
echo -e "\n(2) You \033[33mmust include\033[0m the following files in the archive:"
echo -e "  + main.tex\n  + main.bbl (or main.ind)\n  + referenced figures in main.tex\n  + (if applicable) other related tex files\n  + (optional) style file"
echo -e "\n(3) After removing \033[4mmain.pdf\033[0m, you can run the following"
echo -e "     command to generate the archive file:\n"
# Below is an example. Must include all involved .tex files, figure files, style files, and main.bbl.
echo -e "  zip -r to_arxiv.zip ./{INTERSPEECH2020.sty,acronyms.tex,figs,figs/*,main.bbl,main.tex}"
echo -e "\n#########################################################"