From 12460e60d45349504691070127ab68e1d2f712d7 Mon Sep 17 00:00:00 2001 From: Stefanie Falk Date: Tue, 2 Mar 2021 15:28:10 +0100 Subject: [PATCH 1/5] Add handy bash script to automate compiling latex on comand line. Includes conversion of vectorgraphics svg/eps into pdf, cleaning up the directory from latex compilation files, compressing the document for publication in pdf-a format. Potential to make the script cleaner. --- {figures => figures_src}/ship_tracks.jpg | Bin make | 296 +++++++++++++++++++++++ 2 files changed, 296 insertions(+) rename {figures => figures_src}/ship_tracks.jpg (100%) create mode 100755 make diff --git a/figures/ship_tracks.jpg b/figures_src/ship_tracks.jpg similarity index 100% rename from figures/ship_tracks.jpg rename to figures_src/ship_tracks.jpg diff --git a/make b/make new file mode 100755 index 0000000..2be18cc --- /dev/null +++ b/make @@ -0,0 +1,296 @@ +#!/bin/bash +# Script to compile latex documents which has to be seperated in one main document and dependend sections in different files. +# Figures are expected in a directory figures_src. +# Original graphics in vector formates will be converted into pdf and moved to figures directory. +# Graphics in pdf or bitmap formats will be linked into a directory figures. +# The compiled document will automatically opened with okular if installed. +# There is also an option to compress the file. +# Function declarations +function findMain { + if([ ! $file ]); then + if([ ! ${1} ]); then + echo "Provide base file name or press ENTER." + read file + echo $file + if [[ -z ${file} ]]; then + echo "Assuming file:" + file=`grep -lr --include="*.tex" "begin{document}" .` + fi + fi + fi + if([ ! -e $file ]); then + echo "$File does not exist!" + exit 1 + fi + echo "==> $file" + file=`basename $file .tex ` + bib_file=`find . -name *.bib` +} + +function findUpToDate { +# if there are no changes to any .tex file or to .bib +# script will exit + changes=$1; + if [[ $changes -gt 0 ]]; then + rm $file.${clear_suff[0]} + fi + + for i in `find . -name \*.${suffix[0]} | xargs`; + do + if [[ ${i} -ot $file.${suffix[4]} ]]; then + echo "No changes to `basename ${i}`" + else + changes=$(($changes + 1)) + fi + done + + if [[ $file.${suffix[2]} -ot $file.${suffix[4]} ]]; then + echo "No changes to $file.${suffix[2]}." + else + changes=$(($changes + 1)) + rm ${file}.${suffix}[4] + fi + if [[ $changes -eq 0 ]]; then + echo "Nothing to do." + if [[ ${1} -eq ${options[0]} ]]; then + echo "Will open $file.${suffix[3]}." + openPdf + fi + exit + fi +} + +function makeBib { + if ([ `grep -c --exclude=*.sh "LaTeX Warning: There were undefined references." $file.${suffix[1]}` -gt 0 ] || [ -e $file.${suffix[2]} ]) ; then + bibtex $file.${suffix[4]} + pdflatex $directory/$file.${suffix[0]} + #pdflatex $directory/$file.${suffix[0]} + fi + if ([ `grep -c --exclude=*.sh "LaTeX Warning: Label(s) may have changed." $file.${suffix[1]}` -gt 0 ]); then + pdflatex $directory/$file.${suffix[0]} + fi +} + +function makeLineno { + if ([ `grep -c --exclude=*.sh "Package lineno Warning: Linenumber reference failed" $file.${suffix[1]}` -gt 0 ] || [ -e $file.${suffix[2]} ]) ; then + pdflatex $directory/$file.${suffix[0]} + fi +} + +function makePic { + targetPath=figures + path=figures_src + if([ -d $path ]); then + if([ ! -d $targetPath ]); then + mkdir $targetPath + echo "Created directory $targetPath." + fi + fi + updatedPics=0; + for i in `ls $path | xargs`; do + srcFile=${i} + if ([ "$srcFile" != "${srcFile/%eps}" ]); then + # Deal with eps + targetFile=$targetPath/`basename $srcFile .eps`.pdf + if [[ -e $targetFile ]]; then + if [ $(stat -c '%Z' $path/$srcFile) -gt $(stat -c '%Z' $targetFile) ]; then + rm $targetFile + fi + fi + if [[ ! -e $targetFile ]]; then + #echo $targetFile + `epstopdf $path/$srcFile` + echo "Converted $srcFile to eps." + mv $path/`basename $targetFile` $targetPath + echo "Moved `basename $targetFile` to $targetPath." + updatedPics=$(($updatedPics + 1)) + fi + fi + if ([ "$srcFile" != "${srcFile/%svg}" ]); then + # Deal with svg + targetFile=$targetPath/`basename $srcFile .svg`.pdf + if [[ -e $targetFile ]]; then + if [ $(stat -c '%Z' $path/$srcFile) -gt $(stat -c '%Z' $targetFile) ]; then + rm $targetFile + fi + fi + if [[ ! -e $targetFile ]]; then + `inkscape -z --file=$path/$srcFile --export-pdf=$targetFile` + echo "Created `basename $targetFile`" + updatedPics=$(($updatedPics + 1)) + fi + else + # Deal with pdf and png... + targetFile=$targetPath/$srcFile + if( [ ! -e $targetFile ] || [ $(stat -c '%Z' $path/$srcFile) -gt $(stat -c '%Z' $targetFile) ]); then + # Don't know why, but link needs to be realative. + cd $targetPath + ln -s "../$path/$srcFile" $srcFile + echo "Created symbolic link for $srcFile in $targetPath." + cd .. + updatedPics=$(($updatedPics + 1)) + fi + fi + done + + echo "Figures updated: $updatedPics" +} + +function makeClean { + echo "Clean directory." + + for i in ${clear_suff[@]}; do + echo "Remove ${file}.${i}." + rm *.${i} + done + if([ -d figures ]); then + rm -r figures + fi + exit +} + +function openPdf { + if [ `grep -c "Output written on." $file.${suffix[1]}` -eq 0 ]; then + echo "Exit." + #exit + #not nice but seems to do the job + elif ([ ! `ps -f | grep -c $file.${suffix[3]}` -gt 1 ]); then + if [ -z `which okular` ]; then + evince $file.${suffix[3]} + else + okular $file.${suffix[3]} + fi + else + echo "$file.${suffix[3]} is already running." + fi +} + +function spellCheck { + for i in `find . -name \*.${suffix[0]} | xargs`; + do + if [[ ${1} = "de" ]]; then + aspell -t -x -c --lang de_DE-neu ${i} + else + aspell -t -x -c ${i} + fi + done + exit +} + +function compress { + compressedFile="$file-compressed.${suffix[3]}" + if ([ -f $file.${suffix[3]} ]); then + `gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$compressedFile $file.${suffix[3]}` + fi +} + +function getWarnings { + WARNINGS=`grep -c "[W/w]arning" $file.${suffix[1]}` + echo "++++" + echo "There occurred $WARNINGS warning(s):" + if ([ $WARNINGS -le 10 ]); then + grep -s -n --color "[W/w]arning" $file.${suffix[1]} + fi + echo "++++" +} + +function getErrors { + echo "++++" + echo "There occurred `grep -c "[E/e]rror" $file.${suffix[1]}` error(s):" + grep -s -n --color "[E/e]rror" $file.${suffix[1]} + echo "++++" +} + +function getOverFlow { + OVERWARNINGS=`grep -c "[o,O]verfull" $file.${suffix[1]}` + echo "++++" + echo "There occurred $OVERWARNINGS box overflow(s)." + if ([ $OVERWARNINGS -le 10 ]); then + grep -s -n --color "[o,O]verfull" $file.${suffix[1]} + fi + echo "++++" +} + +function getUnderFlow { + UNDERWARNINGS=`grep -c "[u,U]nderfull" $file.${suffix[1]}` + echo "++++" + echo "There occurred $UNDERWARNINGS box underflow(s)." + if ([ $UNDERWARNINGS -le 10 ]); then + grep -s -n --color "[u,U]nderfull" $file.${suffix[1]} + fi + echo "++++" +} + +function makeCopy { + target=${1} + echo "++++" + echo "Copying ${file}.${suffix[3]} to given destination:" + echo "${target}" + echo "++++" + cp ${file}.${suffix[3]} ${target} +} + +function makeReview { + echo "++++" + echo "Preparing abstract." + echo "Zipping figures." + echo "++++" + pdfseparate -f 1 -l 1 ${file}.${suffix[3]} ${file}_abstract.${suffix[3]} + zip figures -xi fig* +} + +### MAIN ### + +suffix=( tex log bib pdf aux ) +pic_suff=( pdf jpg jpeg png bmp tiff pnm ) +clear_suff=( aux bbl blg out log pdf toc ) +directory=`pwd` +options=( "open" "clean" "check" "pic" "compress" "copy" "review") + +case ${1} in + "") + findMain + makePic + findUpToDate $updatedPics + pdflatex -halt-on-error $directory/$file.${suffix[0]} + makeBib + makeLineno + getWarnings + getOverFlow + getUnderFlow + getErrors + openPdf + ;; + ${options[1]}) + makeClean ${2} + exit + ;; + ${options[2]}) + spellCheck ${2} + exit + ;; + ${options[0]}) + openPdf + exit + ;; + ${options[3]}) + makePic + exit + ;; + ${options[4]}) + compress + exit + ;; + ${options[5]}) + makeCopy ${2} + exit + ;; + ${options[6]}) + makeReview + exit + ;; + *) + echo "Options" + echo ${options[@]} + exit +esac From 2082fb1b5d51bef1e2a74055685c2ffd5311400b Mon Sep 17 00:00:00 2001 From: Stefanie Falk Date: Wed, 3 Mar 2021 15:03:43 +0100 Subject: [PATCH 2/5] Update the README and add some explanation on how to use the script. bash usage function should be implemented in the future. --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 96ffae4..a275459 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Thanks to Inger Helene Karset for sharing and as far as I am aware, it was Andr ## Usage and compilation of template This template can be used with overleaf or your favorite LateX editor. Note that overleaf has an integration with GitHub, so it can be synced to GitHub (a premium version of Overleaf is needed for this). -If you wish to compile with the terminal locally you must run the following commands in the given order +If you wish to compile directly with the terminal locally you must run the following commands in the given order ```shell $ pdflatex main.tex $ bibtex main @@ -15,5 +15,20 @@ $ pdflatex main.tex $ pdflatex main.tex ``` +You can also use the bash script called 'make'. Execute it by typing +```shell +./make + +``` +in your shell. Follow the instructions on screen. + +- The script compiles the latex document which can be seperated into a main document and dependend sections located in different files. +- All figures are expected to be located in a directory called figures_src. +- Original graphics in vector formates will be converted into pdf and moved to figures directory. +- Graphics in pdf or bitmap formats will be linked into a directory figures. +- The compiled document will automatically open in okular if installed else evince will be called. +- A short summary taken from the tex log files is shown on screen, counting the occurance of box under and overflows and missing references. +- There is also an option to compress the file for pdf-a usage. + ## Contribution Suggestions for any improvements and pull requests are highly welcomed! From 46712d0d1007e2f88c3ec50a114ffb1a7725b410 Mon Sep 17 00:00:00 2001 From: Stefanie Falk Date: Wed, 3 Mar 2021 15:06:19 +0100 Subject: [PATCH 3/5] More explanation --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index a275459..0205ed0 100644 --- a/README.md +++ b/README.md @@ -30,5 +30,18 @@ in your shell. Follow the instructions on screen. - A short summary taken from the tex log files is shown on screen, counting the occurance of box under and overflows and missing references. - There is also an option to compress the file for pdf-a usage. +``` shell +./make compress +``` + +- You can clean up the directory for latex compilation files +``` shell +./make clean +``` + +Possible comandline options: + "open" "clean" "check" "pic" "compress" "copy" "review" + + ## Contribution Suggestions for any improvements and pull requests are highly welcomed! From a6b9360209dc5c65dd994396eaba5c7e0bba1d46 Mon Sep 17 00:00:00 2001 From: Stefanie Falk Date: Thu, 11 Mar 2021 15:15:11 +0100 Subject: [PATCH 4/5] Fix bug in makebib. Add compatability with pdflatex and biber --- make | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/make b/make index 2be18cc..5d7dce9 100755 --- a/make +++ b/make @@ -1,8 +1,8 @@ #!/bin/bash # Script to compile latex documents which has to be seperated in one main document and dependend sections in different files. -# Figures are expected in a directory figures_src. -# Original graphics in vector formates will be converted into pdf and moved to figures directory. -# Graphics in pdf or bitmap formats will be linked into a directory figures. +# Figures are expected in a directory pictures_src. +# Original graphics in vector formates will be converted into pdf and moved to pictures directory. +# Graphics in pdf or bitmap formats will be linked into a directory pictures. # The compiled document will automatically opened with okular if installed. # There is also an option to compress the file. # Function declarations @@ -61,13 +61,19 @@ function findUpToDate { } function makeBib { - if ([ `grep -c --exclude=*.sh "LaTeX Warning: There were undefined references." $file.${suffix[1]}` -gt 0 ] || [ -e $file.${suffix[2]} ]) ; then - bibtex $file.${suffix[4]} + if ([ `grep -c --exclude=*.sh "LaTeX Warning: There were undefined references." $file.${suffix[1]}` > 0 ] || [ -e $file.${suffix[2]} ]) ; then + if [[ `grep -c --exclude=*.sh "biber" $file.${suffix[0]}`> 0 ]]; then + biber $file + pdflatex $directory/$file.${suffix[0]} + else + bibtex $file.${suffix[4]} + fi pdflatex $directory/$file.${suffix[0]} - #pdflatex $directory/$file.${suffix[0]} fi if ([ `grep -c --exclude=*.sh "LaTeX Warning: Label(s) may have changed." $file.${suffix[1]}` -gt 0 ]); then + pdflatex $directory/$file.${suffix[0]} + fi } @@ -78,8 +84,8 @@ function makeLineno { } function makePic { - targetPath=figures - path=figures_src + targetPath=pictures + path=pictures_src if([ -d $path ]); then if([ ! -d $targetPath ]); then mkdir $targetPath @@ -133,7 +139,7 @@ function makePic { fi done - echo "Figures updated: $updatedPics" + echo "Pictures updated: $updatedPics" } function makeClean { @@ -143,8 +149,8 @@ function makeClean { echo "Remove ${file}.${i}." rm *.${i} done - if([ -d figures ]); then - rm -r figures + if([ -d pictures ]); then + rm -r pictures fi exit } From cb9d150ee6d00acc027c37d31858f44551f2aa3c Mon Sep 17 00:00:00 2001 From: Stefanie Falk Date: Sun, 18 Apr 2021 10:12:35 +0200 Subject: [PATCH 5/5] Fix bug related to finding the right bibliography file and making a link to it in the main directory if necessary --- make | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/make b/make index 5d7dce9..539024a 100755 --- a/make +++ b/make @@ -24,7 +24,12 @@ function findMain { fi echo "==> $file" file=`basename $file .tex ` - bib_file=`find . -name *.bib` + # Find name of bib file used in main document + bib_file="`grep -oP '.*\K(?<={)\w+(?=.bib})' $file.${suffix[0]}`.bib" + bib_dir=`find . -name ${bib_file} | head -1` + if [[ ! -e $bib_file ]]; then + ln -s $bib_dir $bib_file + fi } function findUpToDate { @@ -44,8 +49,8 @@ function findUpToDate { fi done - if [[ $file.${suffix[2]} -ot $file.${suffix[4]} ]]; then - echo "No changes to $file.${suffix[2]}." + if [[ ${bib_file} -ot $file.${suffix[4]} ]]; then + echo "No changes to ${bib_file}." else changes=$(($changes + 1)) rm ${file}.${suffix}[4] @@ -61,14 +66,15 @@ function findUpToDate { } function makeBib { + if ([ `grep -c --exclude=*.sh "LaTeX Warning: There were undefined references." $file.${suffix[1]}` > 0 ] || [ -e $file.${suffix[2]} ]) ; then if [[ `grep -c --exclude=*.sh "biber" $file.${suffix[0]}`> 0 ]]; then biber $file - pdflatex $directory/$file.${suffix[0]} else bibtex $file.${suffix[4]} fi pdflatex $directory/$file.${suffix[0]} + pdflatex $directory/$file.${suffix[0]} fi if ([ `grep -c --exclude=*.sh "LaTeX Warning: Label(s) may have changed." $file.${suffix[1]}` -gt 0 ]); then @@ -77,6 +83,13 @@ function makeBib { fi } +function makeGlossaries { + if [[ `grep -c --exclude=*.sh "glossaries" $file.${suffix[0]}`> 0 ]]; then + makeglossaries $file + pdflatex $directory/$file.${suffix[0]} + fi +} + function makeLineno { if ([ `grep -c --exclude=*.sh "Package lineno Warning: Linenumber reference failed" $file.${suffix[1]}` -gt 0 ] || [ -e $file.${suffix[2]} ]) ; then pdflatex $directory/$file.${suffix[0]} @@ -249,16 +262,19 @@ function makeReview { suffix=( tex log bib pdf aux ) pic_suff=( pdf jpg jpeg png bmp tiff pnm ) -clear_suff=( aux bbl blg out log pdf toc ) +clear_suff=( acn acr alg aux bbl bcf blg glg glo gls glsdefs ist run.xml out log toc ) directory=`pwd` options=( "open" "clean" "check" "pic" "compress" "copy" "review") +# in any case +findMain + case ${1} in "") - findMain makePic findUpToDate $updatedPics pdflatex -halt-on-error $directory/$file.${suffix[0]} + makeGlossaries makeBib makeLineno getWarnings