Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle cases when a script is called with relative or absolute paths #36

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/convert_to_tex.sh
Expand Up @@ -29,11 +29,22 @@ cat > $DIR/main.tex <<EOF
\clearpage
EOF

# One can call the script like /foo/bar/convert_to_tex.sh or
# bar/convert_to_tex.sh. If the variable $0 contains a slash the
# following parameter expansion will remove everything after the last
# slash. If not the variable $SC_PATH is a file name and the test will
# fail.
# So the list in the following loop will either contain $PWD/chapter* or
# some relative path.
SC_PATH=${0%/*}
if [ ! -d $SC_PATH ] ; then
SC_PATH=$(pwd)
fi

for d in chapter*; do
mkdir $DIR/$d
for d in $SC_PATH/chapter*; do
mkdir $DIR/${d##*/}
echo "\\graphicspath{{./$d/}}" >> $DIR/main.tex
title=`echo $d | sed 's/chapter_[0-9][0-9]_//; s/_/ /g; s/^./\U&/; s/ ./\U&/g'`
title=`echo ${d##*/} | sed 's/chapter_[0-9][0-9]_//; s/_/ /g; s/^./\U&/; s/ ./\U&/g'`
echo "\\chapter{$title}" >> $DIR/main.tex
for f in $d/*.md; do
pandoc -f markdown -t latex $f -o $DIR/$f.tex
Expand Down