forked from ueokande/src2tex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
src2tex.sh
executable file
·68 lines (57 loc) · 1.36 KB
/
src2tex.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
## File type separated by space character. This is a pattern to search files.
FILE_TYPE="h c cc cpp"
## listings options
LSTSET='
breaklines=true,
tabsize=2,
numbers=left,
stepnumber=1,
language=C++,
basicstyle=\\scriptsize\\ttfamily,
numberstyle=\\color[cmyk]{0.11,0.95,0.37,0.92},
stringstyle=\\color[cmyk]{0.11,0.95,0.37,0.92},
commentstyle=\\color[cmyk]{0.61,0.33,0,0},
keywordstyle=\\color[cmyk]{0.71,0.05,1,0.17},
'
## hyperref options
HYPERSEtUP='
bookmarks=true,
bookmarksnumbered=true
'
## A preamble
PREAMBLE='
\\documentclass[12pt]{article}
\\usepackage{listings}
\\usepackage{color}
\\usepackage{hyperref}
\\hypersetup{'"$HYPERSEtUP"'}
\\lstset{'"$LSTSET"'}
\\setlength{\\textwidth}{5.6in}
\\setcounter{secnumdepth}{-1}
'
if test $# -ne 1; then
echo Bad argument!! 1>&2
exit 1
fi
target=`echo $1 | sed -e 's/\/*$//g'`
output=`basename $1`.tex
for i in $FILE_TYPE; do
pattern="${pattern}\|.*\.$i"
done
pattern=`echo $pattern | cut -b3-`
exec 1>$output
echo "$PREAMBLE"
echo '\\begin{document}'
echo '\\tableofcontents'
echo '\\clearpage'
target_len=`echo ${#target} + 2 | bc`
for f in `find . $target -regex $pattern`; do
f=`ls -dF $f`
name=`echo $f | cut -b${target_len}-`
escaped_name=`echo $name | sed -e 's/_/\\\\_/g'`
echo '\\subsection{'"$escaped_name"'}'
echo '\\lstinputlisting[]{'"$f"'}'
echo '\\clearpage'
done
echo "\end{document}"