#!/bin/sh
#] 
#] *********************
#] $ bash "$d_bin""txtDoc extract formulae.sh"  - 
# www.BillHowell.ca  ~05Oct2019 initial

# do NOT run this script directly - set up a calling file
# must define many variables before calling
# example - Lucas project, see "$d_bin""Lucas txtDoc header.sh"


#**********************************
# https://timmurphy.org/2010/05/19/checking-for-empty-string-in-bash/
#Checking for empty string in Bash
#Posted: 19th May 2010 by Tim in Bash
#Tags: Bash, coding, dash, empty, language, linux, null, programming, script, scripting, SET, shell, string, terminal
#In Bash you quite often need to check to see if a variable has been set or has a value other than an empty string. This can be done using the -n or -z string comparison operators.
#The -n operator checks whether the string is not null. Effectively, this will return true for every case except where the string contains no characters. ie:
#	VAR="hello"
#	if [ -n "$VAR" ]; then
#	    echo "VAR is not empty"
#	fi
#Similarly, the -z operator checks whether the string is null. ie:
#	VAR=""
#	if [ -z "$VAR" ]; then
#	    echo "VAR is empty"
#	fi
#Note the spaces around the square brackets. Bash will complain if the spaces are not there.


# simple line for one-line formulae :
# $ grep -n  "^(math" "$d_work""$f_work"  >"$d_work""mathH formulae list.txt"


#] extract_formulae()  - 

	extract_formulae()
{  
echo  ""  >"$p_out"
in_eqn=""
line_num=0

IFS=''
while read -u 9 line; do
	let "line_num = line_num + 1"
	if	 	[ -z "$in_eqn" ]; then
		start_eqn=$( echo "$line"  |  grep  "^(math" )
		if 	[ -n "$start_eqn" ]; then
			echo  "$line_num:$line" 	>>"$p_out"
			in_eqn="$start_eqn"
		fi
	else
		end_eqn=$( echo "$line"  |  grep  "^(endMath)" )
		if [ -n "$end_eqn" ]; then
			echo  " "		 	>>"$p_out"
			in_eqn=""
		else
			echo  "$line" 	>>"$p_out"
		fi
	fi
done 9< "$p_augmented" 
}  



# do NOT run this script directly - set up a calling file
# must define many variables before calling
# example - Lucas project, see "$d_bin""Lucas - formulae & augment.sh"


# enddoc
