File: html2latex

package info (click to toggle)
camlp5 6.06-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,428 kB
  • sloc: ml: 77,055; sh: 1,417; makefile: 1,211
file content (133 lines) | stat: -rwxr-xr-x 5,637 bytes parent folder | download | duplicates (2)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/sh
# $Id: html2latex,v 6.4 2012-01-09 14:22:20 deraugla Exp $

FILES1="index.html strict.html ptools.html"
FILES2="parsers.html lexers.html fparsers.html bparsers.html grammars.html"
FILES3="printers.html pprintf.html pretty.html"
FILES4="locations.html ml_ast.html ast_transi.html ast_strict.html q_ast.html pcaml.html directives.html syntext.html opretty.html redef.html quot.html revsynt.html scheme.html macros.html pragma.html extfun.html"
FILES5="commands.html library.html sources.html about.html"
VERSION="$(grep "value version =" ../../main/pcaml.ml | sed -e 's/^[^"]*"\([^"]*\).*$/\1/')"

FILES="$FILES1 1 $FILES2 2 $FILES3 3 $FILES4 4 $FILES5"

/bin/echo '\documentclass[twoside]{report}
\marginparwidth 0pt \oddsidemargin 0pt \evensidemargin 0pt \marginparsep 0pt
\topmargin 0pt \textwidth 6.5in \textheight 8.5 in
\usepackage{longtable}
\usepackage{fancyhdr}
\fancyhead{}
\fancyhead[LE,RO]{\leftmark}

\newcommand{\clearemptydoublepage}{%
\newpage{\pagestyle{empty}\cleardoublepage}}

\begin{document}
'

/bin/echo "\def\cslversion{$(grep "value version =" ../../main/pcaml.ml | sed -e 's/^[^"]*"\([^"]*\).*$/\1/')}"

/bin/echo '
\pagestyle{empty}
\begin{center}
~\vfill
\Huge           Camlp5 - Reference Manual \\
\Large          version \cslversion \\[1cm]
\large          Daniel de Rauglaudre \\
                \today \\[1cm]
\vfill
\normalsize	Copyright \copyright\ 2007-2012 Institut National de
                Recherche en Informatique et Automatique

This document was generated by a shell script from the html documentation
pages.
\end{center}
\clearemptydoublepage
\setcounter{page}{1}
\pagestyle{plain}
\tableofcontents'

for i in $FILES; do
  /bin/echo '\clearemptydoublepage'
  if [ "$i" = "1" ]; then
    /bin/echo '\part{Parsing tools}'
  elif [ "$i" = "2" ]; then
    /bin/echo '\part{Printing tools}'
  elif [ "$i" = "3" ]; then
    /bin/echo '\part{Language extensions}'
  elif [ "$i" = "4" ]; then
    /bin/echo '\part{Appendix}'
    /bin/echo '\appendix{}'
  else
    cat $i |
    sed \
      -e 's/\\/\\backslash/g' \
      -e 's/%/\\%/g' \
      -e 's|<p [^>]*>|<p>|g' |
    sed \
      -e '{:b; /<\/p>$/N; s|<\/p>\n *|<\/p>|g; tb}' \
      -e 's|</p><p>|\n\n\\\n\n\\noindent |g' \
      -e '{s/^ *<p>/\\noindent /; s|</p>|\n\n|}' |
    sed \
      -e '{/<table[^>]*>$/N; :b; /<tr>$/N; s/\n *//; tb; /<\/tr>$/N; s/\n *//; tb; /<\/th>$/N; s/\n *//; tb; /<\/td>$/N; s/\n *//; tb; /<thead>$/N; s/\n *//; tb; /<\/thead>$/N; s/\n *//; tb; /<tbody>$/N; s/\n *//; tb; /<\/tbody>$/N; s/\n *//; tb}' |
    sed \
      -e 's/{/\\{/g' -e 's/}/\\}/g' \
      -e '0,/<div id="content">/d' \
      -e '/<div id="tableofcontents">/,/<\/div>/d' \
      -e 's/^ *<h1[^>]*>/\\pagestyle{fancy}\\chapter{/' -e 's|</h1>|}|' \
      -e 's/^ *<h2>/\\section{/' -e 's|</h2>|}|' \
      -e 's/^ *<h3>/\\subsection{/' -e 's|</h3>|}|' \
      -e 's/^ *<h4>/\\subsubsection{/' -e 's|</h4>|}|' \
      -e 's/^ *<h5>/\\textbf{/' -e 's|</h5>|}|' \
      -e 's| *<table width[^>]*>\(.*\)</table>|\\begin{center}\n\\begin{tabular}\1\\hline\n\\end{tabular}\n\\end{center}|' \
      -e 's| *<table[^>]*>\(.*\)</table>|\\small\n\\begin{center}\n\\begin{longtable}\1\\hline\n\\end{longtable}\n\\end{center}\\normalsize|' \
      -e 's/<thead>//g' -e 's|</thead>||g' \
      -e 's/<tbody>//g' -e 's|</tbody>||g' \
      -e 's/<tr>\(<th[^>]*>.*<th[^>]*>.*<th[^>]*>\)/{|l|c|l|}\ntr\1/' \
      -e 's/<tr>\(<th[^>]*>.*<th[^>]*>\)/{|l|l|}\ntr\1/' \
      -e 's/tr<th/\\hline\n<th/' \
      -e 's|</th><th|} \& <th|g' \
      -e 's/<th[^>]*class="half"[^>]*>/\\makebox[5.5cm][l]{/g' \
      -e 's/<th[^>]*>/\\makebox[3cm][l]{/g' \
      -e 's|</th></tr>|} \\\\\n\\hline\n|g' \
      -e 's|<tr><td[^>]*>|{|g' \
      -e 's|</td><td[^>]*>|} \& {|g' \
      -e 's|</td></tr>|} \\\\\n|g' \
      -e 's|<br/>|\\\\|g' \
      -e 's/^ *<ul>/\\begin{itemize}/' -e 's|^ *</ul>|\\end{itemize}|' \
      -e 's/^ *<ol>/\\begin{enumerate}/' -e 's|^ *</ol>|\\end{enumerate}|' \
      -e 's/^ *<li>/\\item /' -e 's| *</li>||' \
      -e 's/^ *<dl><dd>/\\begin{description}\n\\item[\\ \\ \\ \\ \\ ]/' \
      -e 's|</dd></dl>|\\end{description}|' \
      -e 's/^ *<dl[^>]*>/\\begin{description}/' -e 's|</dl>|\\end{description}|' \
      -e 's/^ *<dt>/\\item[/' -e 's|</dt>|]|' \
      -e 's/^ *<dd>/\n\\\n\n/' -e 's|</dd>||' \
      -e 's/^ *<pre[^>]*>/\\begin{verbatim}/' -e 's|^ *</pre>|\\end{verbatim}|' \
      -e 's/<code>/\\texttt{/g' -e 's|</code>|}|g' \
      -e 's/<tt[^>]*>/\\texttt{/g' -e 's|</tt>|}|g' \
      -e 's/<em>/\\emph{/g' -e 's|</em>|}|g' \
      -e 's/<i>/\\emph{/g' -e 's|</i>|}|g' \
      -e 's/<b>/\\textbf{/g' -e 's|</b>|}|g' \
      -e 's/<a [^>]*>//g' -e 's|</a>||g' \
      -e 's/<span [^>]*>//g' -e 's|</span>||g' \
      -e 's/&lt;/</g' -e 's/&gt;/>/g' -e 's/&amp;/\\\&/g' -e 's/&nbsp;/\\ /g' \
      -e 's/_/\\_/g' \
      -e 's/#/\\#/g' \
      -e 's/~/\\~{}/g' \
      -e 's/\$/\\$/g' \
      -e 's/\^/\\^/g' \
      -e 's/\\backslash/$\\backslash$/g' \
      -e '/\\begin{verbatim}/,/\\end{verbatim}/s/\\_/_/g' \
      -e '/\\begin{verbatim}/,/\\end{verbatim}/s/\\#/#/g' \
      -e '/\\begin{verbatim}/,/\\end{verbatim}/s/$\\backslash\$/\\/g' \
      -e '/\\begin{verbatim}/,/\\end{verbatim}/s/\\\$/$/g' \
      -e '/\\begin{verbatim}/,/\\end{verbatim}/s/\\{/{/g' \
      -e '/\\begin{verbatim}/,/\\end{verbatim}/s/\\}/}/g' \
      -e '/\\begin{verbatim}/,/\\end{verbatim}/s/\\^/^/g' \
      -e '/<div class="trailer">/,$d' \
      -e 's/<div[^>]*>/\\noindent /' -e 's|</div>||' \
      -e "s|<version/>|$VERSION|" \
      -e '/<licence\/>/r ../../LICENSE' -e '/<licence\/>/d'
  fi
done

/bin/echo '\end{document}'