Skip to content

Instantly share code, notes, and snippets.

@WangNianyi2001
Last active May 15, 2023 19:13
Show Gist options
  • Save WangNianyi2001/f462a9f376f254c49e4e49d29da483e7 to your computer and use it in GitHub Desktop.
Save WangNianyi2001/f462a9f376f254c49e4e49d29da483e7 to your computer and use it in GitHub Desktop.
Useful bash scripts
#! /usr/bin/bash
bn="$(basename $*)";
fn=${bn%.*};
echo $fn;
cd $1;
echo $(pwd);
#! /usr/bin/bash
# Process a XeLaTeX source directory and output the result PDF to certain directory.
# Usage: ./xelatex.sh [source-file] [out-dir]
# It is assumed that all necessary auxiliary files are present along with the source TeX file in the same directory.
home=$(pwd);
bin=$(dirname $0);
srcDir=$($bin/realpath.sh $(dirname $1));
srcName=$(basename $1);
srcFileName=$($bin/filename.sh $srcName);
outDir=$($bin/realpath.sh $2);
tmpDir=/tmp/xelatex;
mkdir $tmpDir;
extList=tex,toc;
cd $srcDir;
for ext in ${extList//,/ }; do
cp $srcFileName.$ext $tmpDir;
done;
cd $tmpDir;
xelatex -interaction=nonstopmode $srcName;
for ext in ${extList//,/ }; do
cp $srcFileName.$ext $srcDir;
done;
cp $srcFileName.pdf $outDir;
cd $home;
rm -rf $tmpDir;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment