@ -1,5 +1,6 @@
#!/usr/bin/env bash
#!/usr/bin/env bash
# GPL3 2023 solarchemist
# solarchemist
# GPL3 2023
set -euo pipefail
set -euo pipefail
@ -7,8 +8,9 @@ usage() {
cat <<EOF
cat <<EOF
Usage: $( basename " ${ BASH_SOURCE [0] } " ) <flags>
Usage: $( basename " ${ BASH_SOURCE [0] } " ) <flags>
Compiles Markdown manuscript and SI to PDF, and optionally converts to HTML,
Compiles Markdown manuscript and SI to PDF, and optionally converts it to HTML,
ODT, or DOCX.
ODT, and/or DOCX.
Requires .mdtemplates file to exist in the current working directory.
Available flags:
Available flags:
+ --help --> display this usage guide
+ --help --> display this usage guide
@ -43,6 +45,8 @@ parse_params() {
-v | --verbose) set -x ; ;
-v | --verbose) set -x ; ;
--convert-all) convert_formats = true ; ;
--convert-all) convert_formats = true ; ;
--convert-html) convert_html = true ; ;
--convert-html) convert_html = true ; ;
--paper) only_paper = true; ;
--si) only_si = true; ;
-?*) die " Unknown option: $1 " ; ;
-?*) die " Unknown option: $1 " ; ;
*) break ; ;
*) break ; ;
esac
esac
@ -53,16 +57,76 @@ parse_params() {
convert_formats = false
convert_formats = false
convert_html = false
convert_html = false
only_paper = false
only_si = false
parse_params " $@ "
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
# note the colons (same function as in $PATH), they are important
export TEXINPUTS = .:${ PWD } /templates/:
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
# these are just strings
BIBLIOGRAPHIES = "--bibliography ./refmngr/zotero.bib --bibliography ./references.bib"
BIBLIOGRAPHIES = "--bibliography ./refmngr/zotero.bib --bibliography ./references.bib"
PANDOC = pandoc
PANDOC = pandoc
@ -76,16 +140,16 @@ fi
# for some reason, *.aux file is messing up the subsequent run (but not the first run):
# 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}
# /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
# note the exclamation mark in the for loop variable, makes it the loop index
# https://stackoverflow.com/a/51794732/1198249
# https://stackoverflow.com/a/51794732/1198249
for M in " ${ !MANUSCRIPT _SOURCES [@]} " ; do
for M in " ${ !MANUSCRIPT [@]} " ; do
# manuscript value in current loop
# array key (manuscript name)
manuscript = " ${ M ANUSCRIPT_SOURCES[M] } "
manuscript = " ${ M } "
# template value in current loop
# array value (template path)
template = " ${ MANUSCRIPT _TEMPLATES [ M]} "
template = " ${ MANUSCRIPT [ ${ M} ]} "
# The --biblatex option is not for use with the --citeproc option or with PDF output
# The --biblatex option is not for use with the --citeproc option or with PDF output
# https://pandoc.org/MANUAL.html#citation-rendering
# https://pandoc.org/MANUAL.html#citation-rendering