Skip to content

Commit

Permalink
Reorganize folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisSung committed Apr 25, 2019
1 parent 9796902 commit 5c1c595
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 26 deletions.
8 changes: 7 additions & 1 deletion 0_init.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# These scripts have been run via bash on both Ubuntu 18.04 LTS and Raspbian 9.8
# Copyright © 2019 LouisSung.
# All rights reserved.

# These scripts have been run on Ubuntu 18.04 LTS via bash
# Require sudo privileges in order to install packages
# Update Python version if needed, e.g., Python >=3.6

echo -e "\e[1;36mSet Up Environment\e[0m"

# === Parameters ===
Expand Down
16 changes: 12 additions & 4 deletions 1_gen_paper.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# Copyright © 2019 LouisSung.
# All rights reserved.

echo -e "\e[1;36mGenerate Paper PDF\e[0m"

# export tex, bib, and bst path to env
export TEXINPUTS=.//:
export BIBINPUTS=.//:
export BSTINPUTS=.//:

BUILD_DIR='build/'
PAPER='Paper'

if [ ! -f "$BUILD_DIR$PAPER.aux" ]; then # make sure to ref citation for the first build
pdflatex -output-directory=$BUILD_DIR $PAPER.tex > /dev/null; fi
if [[ -n $(find ./ -name "*.bib") ]]; then # build BibTex if exist
if [[ -n $(find ./ -name '*.bib') ]]; then # build BibTex if exist
pdflatex -output-directory=$BUILD_DIR $PAPER.tex > /dev/null
bibtex $BUILD_DIR$PAPER.aux > /dev/null
pdflatex -output-directory=$BUILD_DIR $PAPER.tex > /dev/null
fi

pdflatex -output-directory=$BUILD_DIR $PAPER.tex > /dev/null

# print important msg only
echo "\
log
Expand Down
3 changes: 3 additions & 0 deletions 2_gen_diff.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright © 2019 LouisSung.
# All rights reserved.

echo -e "\e[1;36mGenerate Diff PDFs\e[0m"

cd diff/
Expand Down
10 changes: 10 additions & 0 deletions 3_run_texmaker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright © 2019 LouisSung.
# All rights reserved.

# export tex, bib, and bst path to env
export TEXINPUTS=.//:
export BIBINPUTS=.//:
export BSTINPUTS=.//:

# run texmaker in the background
texmaker &
35 changes: 23 additions & 12 deletions diff/gen_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
This script requires 'git', 'latexdiff', 'bibtex', and 'pdflatex' package.
"""
import binascii, git, os, shutil, subprocess
try:
import binascii, git, os, pathlib, shutil, subprocess
except ModuleNotFoundError:
import subprocess
subprocess.run(["pipenv", "install"])
import binascii, git, os, pathlib, shutil

__author__ = "Louis Sung"
__copyright__ = "Copyright © 2019 LouisSung. All rights reserved."
Expand All @@ -17,6 +22,7 @@
MAX_AUTHORS = 2
dir_diff = "diff/"
tex_paper = "Paper.tex"
set_env = "export TEXINPUTS=.//:;export BIBINPUTS=.//:;export BSTINPUTS=.//:"

# Preprocess target folders and file names
_tmp = binascii.b2a_hex(os.urandom(4)).decode() # tmp name for folders
Expand Down Expand Up @@ -66,21 +72,26 @@
# execute latexdiff and pdflatex
with open(os.devnull, "w") as null:
# generate old & new bbl files
subprocess.run("cd {0}; pdflatex {1}".format(
dir_new, tex_paper), shell=True, stdout=null)
subprocess.run("cd {0}; bibtex {1}".format(
dir_new, tex_paper[:-3] + "aux"), shell=True, stdout=null)
subprocess.run("cd {0}; pdflatex {1}".format(
dir_old, tex_paper), shell=True, stdout=null)
subprocess.run("cd {0}; bibtex {1}".format(
dir_old, tex_paper[:-3] + "aux"), shell=True, stdout=null)
subprocess.run("cd {0}; {1}; pdflatex {2}".format(
dir_new, set_env, tex_paper), shell=True, stdout=null)
subprocess.run("cd {0}; {1}; bibtex {2}".format(
dir_new, set_env, tex_paper[:-3] + "aux"), shell=True, stdout=null)
subprocess.run("cd {0}; {1}; pdflatex {2}".format(
dir_old, set_env, tex_paper), shell=True, stdout=null)
subprocess.run("cd {0}; {1}; bibtex {2}".format(
dir_old, set_env, tex_paper[:-3] + "aux"), shell=True, stdout=null)

# generate diff tex
with open(dir_new + file_diff + ".tex", "w") as w_diff:
# move all files to root directory
for d in (dir_new, dir_old):
for file in pathlib.Path(d).rglob("*.*"):
if str(file.parent) != d[:-1]:
shutil.move(os.path.join(str(file)),
os.path.join(d, file.name))
subprocess.run("latexdiff --flatten -p {0} {1} {2}".format(
"{0}._p{1}.tex".format(
dir_diff, min(_authors[author], MAX_AUTHORS)),
tex_old, tex_new), shell=True, stdout=w_diff, stderr=null)
preamble, tex_old, tex_new),
shell=True, stdout=w_diff, stderr=null)

# generate diff pdf
subprocess.run("cd {0}; pdflatex -interaction=nonstopmode {1}".format(
Expand Down
9 changes: 0 additions & 9 deletions references.tex

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 5c1c595

Please sign in to comment.