#Use GNU sed to make modifications to the LaTeX version before producing a PDF

#But first, some HTML tweaks:
# Background color of side pane should match rest of document
sed -i "/background-color/ s|:.*|: #FFFFDE;|" html/navtree.css
sed -i "/nav_h.png/ d" html/navtree.css

# We no longer live in an ASCII-only world.
sed -i 's/pdflatex/xelatex/' latex/Makefile

#PDF: a 170pp document shouldn't be typeset in sans serif
sed -i "/familydefault.*sfdefault/ d" latex/refman.tex

#No fancyheaders
sed -i -e "/fancy/d" -e '/footrulewidth/d'  -e "/Generated by Doxygen/ d" latex/refman.tex

##Set title, for headers and such.
#sed '/begin.document/i
#\\title[Apophenia]{Apophenia}' latex/refman.tex

# Nicer lists.
sed -i '/begin.document/a\
\\setlength\\itemsep{0pt} \\renewcommand\\labelitemi{$\\circ$} \\renewcommand\\labelitemii{$\\circ$} \\renewcommand\\labelitemiii{$\\cdot$}' latex/refman.tex

#I can't make the index look not-stupid
sed -i '/makeindex/d' latex/refman.tex
sed -i '/makeindex/d' latex/Makefile


#Fix enumerations -> model documentation
sed -i -f edit_group.sed latex/group__models.tex
#Rm header list
sed -i -e '/subsection.*Enumer/d' -e'/begin{DoxyCompactItemize}/,/end{DoxyCompactItemize}/d' latex/group__models.tex
##sed -i -e 's/\\cline{.*}$//' -e's/begin{TabularN*C}.*/begin{tabular}{ll}/' -e's/end{TabularN*C}.*/end{tabular}/' latex/group__models.tex
#sed -i -e's/\(TabularC}\){2}/\1{3}/' latex/group__models.tex

#redundant with the struct defns.
fdline=$((`grep -n 'subsection.Function Documentation.' latex/group__all__public.tex|sed 's/:.*//'`-1))
sed -i "/subsection.Typedef Documentation./,$fdline d" latex/group__all__public.tex

#Unclutter the ToC by using section*=omit from ToC
sed -i -e 's/subsection{Detailed Description}/subsection*{Detailed Description}/' -e 's/subsection{Field Documentation}/subsection*{Field Documentation}/' latex/*tex

#Bare references to subpages
#sed -i -e's|^\\hyperlink.*hypertarget.*subsection.*label{[^}]*}$||' latex/*tex
sed -i -e's|^\\hyperlink{[^}]*}{[^}]*}$||' latex/*tex

#the hyperlink insertion into sample code sometimes creates needless newlines with a
#six-space indent.
sed -i '$!N;s/\n      \(\\hyperlink\)/\1/;P;D' latex/*tex

#code looks too small to me. Go one step bigger.
sed -i -e 's/scriptsize/footnotesize/' latex/doxygen.sty

#paragraphs have a lot of space after the header; tighten
#sed -i -e'/DoxyParagraph/,+15 s|\(end{list}\)|\1\\vspace{-10pt}|' latex/doxygen.sty

#offset description labels by a few cm
sed -i '$a\
\\renewcommand{\\descriptionlabel}[1]{\\hspace{-1.5cm}\\emph{#1}}' latex/doxygen.sty

sed -i -e 's/xtab\*{\\linewidth}/xtab/g' -e 's/xtab\(ular\|\)/supertabular/g' -e 's/\\tablefirsthead.*}//' -e '/\\par%/d' latex/doxygen.sty
#sed latex/doxygen.sty



#Want search box in header
sed -i -e '/position: *absolute/d' html/search/search.css
sed -i -e 's/display: *block/display: inline/' html/search/search.css
#magnifying glass is hard-coded, and span="left" covers left and  middle of search box
sed -i -e '/mag_sel.png/,+3d' html/*html

#100% of the search results are doubled. Can't work out why.
sed -i -e 's/\],\[[^]]\+\]/]/' html/search/*js

