Just for reference, below is the shell script I'm currently using for compile files with extension .piece.tex
, where .piece
is a mark to tell that this is not a complete LaTeX code file.
DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $DIR
mkdir -p .aux
filename=$(ls -t *.piece.tex | head -n1)
echo "\\documentclass[use boldface, theorem in new line, simple name, theorem numbering = *]{einfart}" > .aux/${filename%.piece.tex}.temp.tex
echo "\\usepackage{ProjLib}" >> .aux/${filename%.piece.tex}.temp.tex
echo "\\usepackage{tikz-cd}" >> .aux/${filename%.piece.tex}.temp.tex
echo "\\\\begin{document}" >> .aux/${filename%.piece.tex}.temp.tex
echo "\\input{$filename}" >> .aux/${filename%.piece.tex}.temp.tex
echo "\\end{document}" >> .aux/${filename%.piece.tex}.temp.tex
latexmk -xelatex -silent -output-directory=.aux -jobname=${filename%.piece.tex} .aux/${filename%.piece.tex}.temp.tex
mv .aux/${filename%.piece.tex}.pdf ${filename%.piece.tex}.pdf
For example, if you have a Document.piece.tex
with the content:
This is a test document.
\begin{theorem}\label{thm1}
\blindtext
\end{theorem}
\begin{theorem}\label{thm2}
\blindtext
\end{theorem}
\begin{definition}\label{def1}
\blindtext
\end{definition}
\cref{thm1,def1,thm2}
\dnf
Then after running the script, you shall get a Document.pdf
looks like:

Some explanations:
The first two lines change the directory to the current one containing the shell script:
DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $DIR
Then make a .aux
folder for storing auxiliary files.
mkdir -p .aux
The script shall now find the latest .piece.tex
file for compilation.
filename=$(ls -t *.piece.tex | head -n1)
It will produce a same named .temp.tex
file in the .aux
folder for latexmk
to work on.
echo "\\documentclass[use boldface, theorem in new line, simple name, theorem numbering = *]{einfart}" > .aux/${filename%.piece.tex}.temp.tex
echo "\\usepackage{ProjLib}" >> .aux/${filename%.piece.tex}.temp.tex
echo "\\usepackage{tikz-cd}" >> .aux/${filename%.piece.tex}.temp.tex
echo "\\\\begin{document}" >> .aux/${filename%.piece.tex}.temp.tex
echo "\\input{$filename}" >> .aux/${filename%.piece.tex}.temp.tex
echo "\\end{document}" >> .aux/${filename%.piece.tex}.temp.tex
And finally, compile with latexmk
and move the .pdf
file to the current folder.
latexmk -xelatex -silent -output-directory=.aux -jobname=${filename%.piece.tex} .aux/${filename%.piece.tex}.temp.tex
mv .aux/${filename%.piece.tex}.pdf ${filename%.piece.tex}.pdf