Skip to content

Commit

Permalink
Added parameter support for tab file directory
Browse files Browse the repository at this point in the history
  • Loading branch information
remcorakers committed Jan 14, 2017
1 parent e898438 commit cb1b33b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ Create a PDF file from all your tabs, lyrics, or chord files that you have store

This is a first rudimentary version, but sufficient for now. The PDF has an index with clickable links and each song starts on a new page.

## Prerequisites

- `xelatex` should be installed (see [XeTeX's Wikipedia page](https://en.wikipedia.org/wiki/XeTeX) for more info)
- Script needs read/write permission in the current folder
- Files in the target directory are stored as `.txt` files
- Tested and developed on OSX, but should be possible to make it work on other platforms without much effort.

## How to generate your PDF?
- Configure the path to your txt files in generate.sh
- Run songbook.tex from terminal with write18 enabled, to be able to execute shell scripts: `$ xelatex -enable-write18 songbook.tex`

Run the following command from the directory containing this repo code:

```Shell
$ bash ./songbook.sh /path/to/tab/directory
```

This will create a file named `songbook.pdf` containing all the `.txt` files from the provided directory.
14 changes: 10 additions & 4 deletions generate.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#!/bin/bash

# Change path to your the directory where you store your tabs.
for f in /users/remco/dropbox/tabs/*.txt
if [ "$1" == "" ]; then
echo "Please provide an path where your tab files are located."
exit 4
fi

files="$1/*.txt"

for f in $files
do
filename=$(basename "$f")
extension="${filename##*.}"
filename="${filename%.*}"

echo "\clearpage"
echo "\section*{$filename}"
echo "\markboth{$filename}{$filename}"
echo "\addcontentsline{toc}{section}{$filename}"
echo "\VerbatimInput{\"$f\"}"
done
done
27 changes: 27 additions & 0 deletions songbook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

if [ "$1" == "" ]; then
echo "Please provide an path where your tab files are located."
exit 4
fi

tabDir=${1%/} # remove last slash, if existing

escapedDir="${tabDir//\//\/}"
expression="%s/TABDIR/$escapedDir/g"

# use a temp file, based on songbook.tex
cp ./songbook.tex ./songbook.temp.tex

# replace TABDIR placeholder with actual value of the directory with tab files
ex -sc $expression -cx ./songbook.temp.tex

# run twice: first run for the table of contenst, second one for complete PDF
xelatex -enable-write18 "./songbook.temp.tex"
xelatex -enable-write18 "./songbook.temp.tex"

# rename generated songbook pdf
mv ./songbook.temp.pdf songbook.pdf

# clean up temp files
rm ./*temp*
10 changes: 5 additions & 5 deletions songbook.tex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
top=20mm,
bottom=20mm,
}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
Expand All @@ -34,7 +34,7 @@
\usepackage[titles]{tocloft}
\setlength{\cftbeforesecskip}{-.1ex}

\immediate\write18{./generate.sh > temptabs.tex}
\immediate\write18{./generate.sh TABDIR > tabs.temp.tex}

\begin{document}

Expand All @@ -43,8 +43,8 @@
\tableofcontents
\clearpage

\input{temptabs.tex}
\input{tabs.temp.tex}

\immediate\write18{rm ./temptabs.tex}
\immediate\write18{rm ./tabs.temp.tex}

\end{document}
\end{document}

0 comments on commit cb1b33b

Please sign in to comment.