#!/bin/bash # This script aims to help with kyomato usage, boiling it to a single command # You can try running it as # > KYOMATO_IMAGES=$(realpath ./image_folder) ./kyomato-helper.bash test_input/input.md # From the directory it's located in # It's functions are as follows: # - Create a hidden directory near specified input file # - Clear it, so that build is always clean # - Run kyomato to transform input file into `.tex` # - Run pdflatex twice on resulting `.tex`, to generate all tables correctly # - Move resulting `.pdf` right near input file. Temporary hidden folder can be deleted manually, or used for debug # check if kyomato exists: ( kyomato -V > /dev/null ) || { echo "can't reach kyomato"; exit -1; } # check if pdflatex exists: ( pdflatex -v > /dev/null ) || { echo "can't reach pdflatex"; exit -1; } # input file path is expected at first argument input_file=$1 if [[ -z $input_file ]] then echo "input file must be supplied"; exit -1; fi if [[ ! -f $input_file ]] then echo "File is expected as input"; exit -1; fi echo "input file is ${input_file}" # Determine working directory source_directory=$( dirname $input_file ) if [[ -z source_directory ]] then echo "dirname had failed. please contact me"; exit -1; fi input_name=$( basename $input_file | cut -f 1 -d '.') working_directory=$source_directory/.kyomato_tmp echo "working directory is ${working_directory}" # Ensure working directory exists mkdir -p -v $working_directory if [[ ! -z "$(dir $working_directory)" ]] then # Clean up the working directory from previous runs rm -v -r --preserve-root=all $working_directory/*; fi # Actually run kyomato execution_dir=$(pwd) cd $working_directory echo "running kyomato..." ( kyomato --in ../$( basename $input_file ) --debug-paths --exec $execution_dir > source.tex 2> kyomato_err.log ) || { echo "kyomato had failed, please contact me"; exit -1; } # run pdflatex echo "running pdflatex(1/2) ..." ( pdflatex -halt-on-error -file-line-error -interaction=nonstopmode -output-format=pdf -output-directory=. -shell-escape source.tex &> pdflatex1.log ) || { echo "pdflatex had failed, please contact me"; exit -1; } echo "running pdflatex(2/2) ..." ( pdflatex -halt-on-error -file-line-error -interaction=nonstopmode -output-format=pdf -output-directory=. -shell-escape source.tex &> pdflatex2.log ) || { echo "pdflatex had failed, on the second run! please contact me"; exit -1; } # yep, latex must be run twice # because latex is weird # at the end, move out generated pdf mv -v -u source.pdf ../$input_name.pdf