From 5c1c595bfa7f6120d6bb45c4122ddae5b744397c Mon Sep 17 00:00:00 2001 From: LouisSung Date: Thu, 25 Apr 2019 17:03:40 +0800 Subject: [PATCH] Reorganize folder structure --- 0_init.sh | 8 +++- 1_gen_paper.sh | 16 ++++++-- 2_gen_diff.sh | 3 ++ 3_run_texmaker.sh | 10 +++++ diff/gen_diff.py | 35 ++++++++++++------ references.tex | 9 ----- IEEEtran.bst => source/IEEEtran.bst | 0 IEEEtran.cls => source/IEEEtran.cls | 0 abstract.tex => source/abstract.tex | 0 author.tex => source/author.tex | 0 citation.bib => source/citation.bib | 0 conclusion.tex => source/conclusion.tex | 0 evaluation.tex => source/evaluation.tex | 0 {fig => source/fig}/fig1.png | Bin introduction.tex => source/introduction.tex | 0 related_work.tex => source/related_work.tex | 0 .../technical_approach.tex | 0 17 files changed, 55 insertions(+), 26 deletions(-) create mode 100755 3_run_texmaker.sh delete mode 100644 references.tex rename IEEEtran.bst => source/IEEEtran.bst (100%) rename IEEEtran.cls => source/IEEEtran.cls (100%) rename abstract.tex => source/abstract.tex (100%) rename author.tex => source/author.tex (100%) rename citation.bib => source/citation.bib (100%) rename conclusion.tex => source/conclusion.tex (100%) rename evaluation.tex => source/evaluation.tex (100%) rename {fig => source/fig}/fig1.png (100%) rename introduction.tex => source/introduction.tex (100%) rename related_work.tex => source/related_work.tex (100%) rename technical_approach.tex => source/technical_approach.tex (100%) diff --git a/0_init.sh b/0_init.sh index 4c27c0f..09135b7 100755 --- a/0_init.sh +++ b/0_init.sh @@ -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 === diff --git a/1_gen_paper.sh b/1_gen_paper.sh index 1ef31d1..2386cfc 100755 --- a/1_gen_paper.sh +++ b/1_gen_paper.sh @@ -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 diff --git a/2_gen_diff.sh b/2_gen_diff.sh index 938d1aa..8fa8626 100755 --- a/2_gen_diff.sh +++ b/2_gen_diff.sh @@ -1,3 +1,6 @@ +# Copyright © 2019 LouisSung. +# All rights reserved. + echo -e "\e[1;36mGenerate Diff PDFs\e[0m" cd diff/ diff --git a/3_run_texmaker.sh b/3_run_texmaker.sh new file mode 100755 index 0000000..12460f0 --- /dev/null +++ b/3_run_texmaker.sh @@ -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 & diff --git a/diff/gen_diff.py b/diff/gen_diff.py index 45ab216..534af20 100644 --- a/diff/gen_diff.py +++ b/diff/gen_diff.py @@ -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." @@ -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 @@ -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( diff --git a/references.tex b/references.tex deleted file mode 100644 index a1cd4db..0000000 --- a/references.tex +++ /dev/null @@ -1,9 +0,0 @@ -\begin{thebibliography}{00} -\bibitem{b1} G. Eason, B. Noble, and I. N. Sneddon, ``On certain integrals of Lipschitz-Hankel type involving products of Bessel functions,'' Phil. Trans. Roy. Soc. London, vol. A247, pp. 529--551, April 1955. -\bibitem{b2} J. Clerk Maxwell, A Treatise on Electricity and Magnetism, 3rd ed., vol. 2. Oxford: Clarendon, 1892, pp.68--73. -\bibitem{b3} I. S. Jacobs and C. P. Bean, ``Fine particles, thin films and exchange anisotropy,'' in Magnetism, vol. III, G. T. Rado and H. Suhl, Eds. New York: Academic, 1963, pp. 271--350. -\bibitem{b4} K. Elissa, ``Title of paper if known,'' unpublished. -\bibitem{b5} R. Nicole, ``Title of paper with only first word capitalized,'' J. Name Stand. Abbrev., in press. -\bibitem{b6} Y. Yorozu, M. Hirano, K. Oka, and Y. Tagawa, ``Electron spectroscopy studies on magneto-optical media and plastic substrate interface,'' IEEE Transl. J. Magn. Japan, vol. 2, pp. 740--741, August 1987 [Digests 9th Annual Conf. Magnetics Japan, p. 301, 1982]. -\bibitem{b7} M. Young, The Technical Writer's Handbook. Mill Valley, CA: University Science, 1989. -\end{thebibliography} \ No newline at end of file diff --git a/IEEEtran.bst b/source/IEEEtran.bst similarity index 100% rename from IEEEtran.bst rename to source/IEEEtran.bst diff --git a/IEEEtran.cls b/source/IEEEtran.cls similarity index 100% rename from IEEEtran.cls rename to source/IEEEtran.cls diff --git a/abstract.tex b/source/abstract.tex similarity index 100% rename from abstract.tex rename to source/abstract.tex diff --git a/author.tex b/source/author.tex similarity index 100% rename from author.tex rename to source/author.tex diff --git a/citation.bib b/source/citation.bib similarity index 100% rename from citation.bib rename to source/citation.bib diff --git a/conclusion.tex b/source/conclusion.tex similarity index 100% rename from conclusion.tex rename to source/conclusion.tex diff --git a/evaluation.tex b/source/evaluation.tex similarity index 100% rename from evaluation.tex rename to source/evaluation.tex diff --git a/fig/fig1.png b/source/fig/fig1.png similarity index 100% rename from fig/fig1.png rename to source/fig/fig1.png diff --git a/introduction.tex b/source/introduction.tex similarity index 100% rename from introduction.tex rename to source/introduction.tex diff --git a/related_work.tex b/source/related_work.tex similarity index 100% rename from related_work.tex rename to source/related_work.tex diff --git a/technical_approach.tex b/source/technical_approach.tex similarity index 100% rename from technical_approach.tex rename to source/technical_approach.tex