#!/bin/bash # converts akoaba markdown into tex # TODO # - formatting scripture https://tex.stackexchange.com/a/652451/264579 # - do I even need mutliple verse environments? USAGE="""USAGE: $(basename $0) markdown-file""" if [ $# -ne 1 ] ; then echo "$USAGE" && exit 1; fi INFILE=$1 # remove any suffix https://stackoverflow.com/a/36341390 BASENAME=$(basename "${INFILE%.*}") KEEP_TMP_FILES=0 ############### # OLD VERSION # ############### ## translate from pandoc md to latex #pandoc \ # -f markdown \ # ${bname}.md \ # -t latex \ # -o ${bname}.tmp1 ## repurpose headings and verbatim #sed \ # -e "s/subsection/attrib/" \ # -e "s/section/poemtitle/" \ # -e "s/verbatim/verse/" \ # ${bname}.tmp1 \ # > ${bname}.tex ## insert verse into empty lines ################### # SECOND VERSION # ################### sed \ 's/^$/\\end{verse}\ \ \\begin{verse}/' \ ${INFILE} \ > ${BASENAME}.tmp1 # remove first end{verse} https://unix.stackexchange.com/a/335450 cat \ ${BASENAME}.tmp1 \ | awk -v c=1 '/end{verse}/ && i++ < c {next};1' \ > ${BASENAME}.tmp2 # remove last begin{verse} https://unix.stackexchange.com/a/335450 tac \ ${BASENAME}.tmp2 \ | awk -v c=1 '/begin{verse}/ && i++ < c {next};1' \ | tac \ > ${BASENAME}.tmp3 # translate from ako.aba.md to latex pandoc \ -f markdown \ ${BASENAME}.tmp3 \ -t latex \ -o ${BASENAME}.tmp4 # --wrap=preserve \ sed \ -e "s/subsection/attrib/" \ -e "s/section/poemtitle/" \ ${BASENAME}.tmp4 \ > ${BASENAME}.tex if ! [[ $KEEP_TMP_FILES -gt 0 ]] then rm *tmp* fi