From 687379932faf302b289b10def2db82871311d602 Mon Sep 17 00:00:00 2001 From: "taha@asks2" Date: Wed, 6 Sep 2023 23:03:50 +0200 Subject: [PATCH] Compile only paper or only SI with dynamically set manuscript filenames and corresponding LaTeX template files for Markdown. To avoid having to set overly long command I have opted to read these values from file. --- chemdtex.sh | 90 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 77 insertions(+), 13 deletions(-) mode change 100644 => 100755 chemdtex.sh diff --git a/chemdtex.sh b/chemdtex.sh old mode 100644 new mode 100755 index de06555..b35b17c --- a/chemdtex.sh +++ b/chemdtex.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -# GPL3 2023 solarchemist +# solarchemist +# GPL3 2023 set -euo pipefail @@ -7,8 +8,9 @@ usage() { cat < -Compiles Markdown manuscript and SI to PDF, and optionally converts to HTML, -ODT, or DOCX. +Compiles Markdown manuscript and SI to PDF, and optionally converts it to HTML, +ODT, and/or DOCX. +Requires .mdtemplates file to exist in the current working directory. Available flags: + --help --> display this usage guide @@ -43,6 +45,8 @@ parse_params() { -v | --verbose) set -x ;; --convert-all) convert_formats=true ;; --convert-html) convert_html=true ;; + --paper) only_paper=true;; + --si) only_si=true;; -?*) die "Unknown option: $1" ;; *) break ;; esac @@ -53,16 +57,76 @@ parse_params() { convert_formats=false convert_html=false +only_paper=false +only_si=false parse_params "$@" +# https://ostechnix.com/bash-associative-array +# https://phoenixnap.com/kb/bash-associative-array +# I expect .mdtemplates to look like this: +# (note the use of "keys" named "paper" and "si", these key names should always be paper/si) +# ``` +# $ cat .mdtemplates +# declare -A MANUSCRIPT=( ["paper"]="templates/pmichaillat.latex", ["si"]="templates/pmichaillat-si.latex" ) +# ``` +# so if your main manuscript is named something other than "paper", just adjust accordingly in your .mdtemplates +# and ditto for the relative path to your latex template file markdown should use. + +msg "--- Looking for .mdtemplates" +if [ -e .mdtemplates ]; then + msg "--- Found in .mdtemplates:" + # https://stackoverflow.com/a/4685432/1198249 + source ./.mdtemplates + for M in "${!MANUSCRIPT[@]}"; do + echo " ${M}: ${MANUSCRIPT[${M}]}" + done +else + die "Found no .mdtemplates file. Quitting..." 0 + # for later, add the ability define the array as arg to the --paper and --si flags +fi + + +if [[ $only_paper == "true" ]]; then + # msg "Detected --paper flag" + declare -A MANUSCRIPT_PAPER + MANUSCRIPT_PAPER["paper"]=${MANUSCRIPT["paper"]} + unset MANUSCRIPT + declare -A MANUSCRIPT + MANUSCRIPT["paper"]=${MANUSCRIPT_PAPER["paper"]} + # declare -a MANUSCRIPT_TEMPLATES=( "templates/pmichaillat.latex" ) +fi + + +if [[ $only_si == "true" ]]; then + # msg "Detected --si flag" + declare -A MANUSCRIPT_SI + # in this assignment we lose the "si" key, gets replaced by integer + # declare -a MANUSCRIPT_SI=${MANUSCRIPT["si"]} + # we effectively need to build a new array from the old + # https://unix.stackexchange.com/a/464627/411416 + MANUSCRIPT_SI["si"]=${MANUSCRIPT["si"]} + # echo "${MANUSCRIPT_SI[@]}" + # echo "${!MANUSCRIPT_SI[@]}" + # echo "${#MANUSCRIPT_SI[@]}" + # simpledelay.sh 10 + unset MANUSCRIPT + declare -A MANUSCRIPT + MANUSCRIPT["si"]=${MANUSCRIPT_SI["si"]} +# declare -a MANUSCRIPT_TEMPLATES=( "templates/pmichaillat-si.latex" ) +fi + + +# echo "${MANUSCRIPT[@]}" +# echo "${!MANUSCRIPT[@]}" +# echo "${#MANUSCRIPT[@]}" +# simpledelay.sh 15 + + +# NOTE "templates/" is hard-coded here! # note the colons (same function as in $PATH), they are important export TEXINPUTS=.:${PWD}/templates/: -# these are indexed bash arrays -# https://www.cyberciti.biz/faq/bash-for-loop-array/ -declare -a MANUSCRIPT_SOURCES=("paper" "si") -declare -a MANUSCRIPT_TEMPLATES=("templates/wiley.latex" "templates/wiley-si.latex") # these are just strings BIBLIOGRAPHIES="--bibliography ./refmngr/zotero.bib --bibliography ./references.bib" PANDOC=pandoc @@ -76,16 +140,16 @@ fi # for some reason, *.aux file is messing up the subsequent run (but not the first run): # /paper.aux:224: Undefined control sequence. l.224 \BibFileName[0]{paper.html} -rm -f *.aux +# rm -f *.aux # note the exclamation mark in the for loop variable, makes it the loop index # https://stackoverflow.com/a/51794732/1198249 -for M in "${!MANUSCRIPT_SOURCES[@]}"; do - # manuscript value in current loop - manuscript="${MANUSCRIPT_SOURCES[M]}" - # template value in current loop - template="${MANUSCRIPT_TEMPLATES[M]}" +for M in "${!MANUSCRIPT[@]}"; do + # array key (manuscript name) + manuscript="${M}" + # array value (template path) + template="${MANUSCRIPT[${M}]}" # The --biblatex option is not for use with the --citeproc option or with PDF output # https://pandoc.org/MANUAL.html#citation-rendering