Skip to content

Commit

Permalink
restructured build process
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-bachner committed Nov 24, 2020
1 parent a5fcd44 commit 0fba364
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 143 deletions.
8 changes: 5 additions & 3 deletions src/md-paper.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

version="0.1.2"
version="0.1.3"

if brew ls --versions md-paper >/dev/null
then
Expand Down Expand Up @@ -79,7 +79,8 @@ case $1 in
# convert latex to pdf
if [ -e *.tex ]
then
ksh ${resources}/pdf.ksh
ksh ${resources}/pdf.sh
open *.pdf
else
echo "No (La)TeX file found"
exit 1
Expand All @@ -90,7 +91,8 @@ case $1 in
then
# convert md to pdf
sh ${resources}/tex.sh
ksh ${resources}/pdf.ksh
ksh ${resources}/pdf.sh
open *.pdf
else
echo "No Markdown file found"
exit 1
Expand Down
138 changes: 0 additions & 138 deletions src/pdf.ksh

This file was deleted.

151 changes: 151 additions & 0 deletions src/pdf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# pick first markdown the file finds
TEX=$(find *.tex)
# remove .md file name
FILE=${TEX%.tex}

function ERROR {
echo -e "\033[38;5;1mERROR: ${1}"
exit 1
}

function LOADING {
echo "$1"

STEP_SIZE=5
TOTAL_STEPS=$((100 / STEP_SIZE))
FILE_SIZE=$(wc -l ${FILE}.tex | cut -c 6-8)

for ((k = 0; k < $TOTAL_STEPS ; k++))
do
echo -ne "\033[K"
echo -n "[ "

for ((i = 0 ; i < k; i++))
do
echo -n "#"
done

for (( j = i ; j < $TOTAL_STEPS ; j++ ))
do
echo -n " "
done

echo -n " ]"

STEP=$((k * STEP_SIZE))
echo -ne " ${STEP} %\r"

DELAY=$(( ( ( RANDOM % 5 ) * FILE_SIZE ) / 2000 ))
sleep ${DELAY}s
done
}

function delete {
if [ -e *.${1} ]
then
rm *.${1}
fi
}

# Remove old files
delete pdf
delete log
delete aux
delete toc
delete lof
delete lot
delete bbl
delete blg
delete out

# check if bibliography exists
# if yes, process it
if [ -e *.bib ] || [ -e *.bibtex ]
then
LOADING "(1/3) Processing bibliography" &
pdflatex ${FILE}.tex >pdf.log && \
bibtex ${FILE}.aux >bib.log &
wait
if [ -e *.pdf ]
then
echo "[ #################### ] 100 %"
echo
rm *.pdf
else
ERROR "Could not process bibliography"
fi

# convert latex to pdf using pdflatex
LOADING "(2/3) Preparing conversion from LaTeX to PDF" &
pdflatex ${FILE}.tex >pdf.log &
wait
if [ -e *.pdf ]
then
echo "[ #################### ] 100 %"
echo
rm *.pdf
else
ERROR "PDF build failed"
fi

# pdflatex needs to repeat the process to account for the processing of table of contents and similar environments
LOADING "(3/3) Converting LaTeX to PDF" &
pdflatex ${FILE}.tex >pdf.log &
wait
if [ -e *.pdf ]
then
echo "[ #################### ] 100 %"
echo
else
ERROR "PDF build failed"
fi
else
# convert latex to pdf using pdflatex
LOADING "(1/2) Preparing conversion from LaTeX to PDF" &
pdflatex ${FILE}.tex >pdf.log &
wait
if [ -e *.pdf ]
then
echo "[ #################### ] 100 %"
echo
rm *.pdf
else
ERROR "PDF build failed"
fi

# pdflatex needs to repeat the process to account for the processing of table of contents and similar environments
LOADING "(2/2) Converting LaTeX to PDF" &
pdflatex ${FILE}.tex >pdf.log &
wait
if [ -e *.pdf ]
then
echo "[ #################### ] 100 %"
echo
else
ERROR "PDF build failed"
fi
fi

# Delete build files generated by pdflatex if they exist
if [ "$1" == "--log" ] || [ "$2" == "--log" ]
then
mkdir logs
mv *.log logs/
"log files are in logs folder"
else
delete log
fi
if [ "$1" == "--aux" ] || [ "$2" == "--aux" ]
then
mkdir aux
mv *.log aux/
"aux files are in logs folder"
else
delete aux
delete out
delete toc
delete lof
delete lot
delete bbl
delete blg
fi
2 changes: 0 additions & 2 deletions src/tex.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/bin/sh

# remove old file
if [ -e *.tex ]
then
Expand Down

1 comment on commit 0fba364

@vercel
Copy link

@vercel vercel bot commented on 0fba364 Nov 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.