Skip to content

Commit 9745145

Browse files
committed
2.andresraba6
1 parent 1e820c4 commit 9745145

File tree

290 files changed

+160623
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

290 files changed

+160623
-2
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.json
2+
*.vim
3+
*.swp
4+
*~
5+
\#*\#

LICENSE

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
LICENSING TERMS
2+
3+
The HTML files of the book and illustrations in
4+
directory 'html/fig' are licensed under Creative Commons
5+
Attribution-ShareAlike 3.0 Unported License
6+
(http://creativecommons.org/licenses/by-sa/3.0/).

LICENSE.src

+687
Large diffs are not rendered by default.

META-INF/container.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
3+
<rootfiles>
4+
<rootfile full-path="content.opf" media-type="application/oebps-package+xml" />
5+
</rootfiles>
6+
</container>

Makefile

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Makefile for compiling sicp.epub from the sources.
2+
# (c) 2014 Andres Raba, GNU GPL v.3.
3+
4+
DIR = html/
5+
SRC = sicp-pocket.texi # book's Texinfo source
6+
GOAL = ../sicp.epub # the end product of compilation
7+
NEXUS = $(DIR)index.xhtml # the central file with table of contents
8+
META = content.opf toc.xhtml # epub metafiles generated from NEXUS
9+
HTML = $(DIR)*.xhtml # all the HTML files of the book
10+
FIG = $(DIR)fig/*/*.svg # SVG diagrams
11+
CSS = $(DIR)css/*.css # style files
12+
FONT = $(DIR)css/fonts/* # WOFF fonts
13+
JS = $(DIR)js/*.js # javascript libraries
14+
CONV = texi2any lib/Texinfo/Convert/HTML.pm # Texinfo converter scripts
15+
MATH = get-math.js put-math.js mathcell.xhtml # LaTeX -> MathML converter
16+
HIGHL = $(DIR)js/highlight/
17+
PRETTY = $(HIGHL)prettify.js $(HIGHL)lang-lisp.js batch-prettify.js
18+
COVER = index.xhtml $(DIR)fig/coverpage.std.svg $(DIR)fig/bookwheel.jpg
19+
THUMB = $(DIR)fig/cover.png # thumbnail cover image
20+
SHELL = /bin/bash
21+
22+
JQ = <script src=\"js/jquery.min.js\" type=\"text/javascript\"></script>
23+
FT = <script src=\"js/footnotes.js\" type=\"text/javascript\"></script>
24+
BR = <script src=\"js/browsertest.js\" type=\"text/javascript\"></script>
25+
26+
all: $(GOAL)
27+
# Add scripts to the unpacked HTML5 version that is to be read in a browser.
28+
@if ! grep -m 1 -l 'browsertest' $(NEXUS); then \
29+
for file in $(HTML); do \
30+
perl -0p -i.bak -e \
31+
"s{\s*</head>}{\n\n$(JQ)\n$(FT)\n$(BR)\n</head>}" $$file; \
32+
done; \
33+
rm $(DIR)*.bak; \
34+
fi
35+
36+
html: $(NEXUS)
37+
38+
exercises.texi figures.texi: ex-fig-ref.pl
39+
@./ex-fig-ref.pl -e > exercises.texi; \
40+
./ex-fig-ref.pl -f > figures.texi
41+
42+
$(NEXUS): $(SRC) $(CONV) $(MATH) $(PRETTY) exercises.texi figures.texi
43+
@echo -n "Converting Texinfo file to HTML..."; \
44+
./texi2any --no-warn --html --iftex $(SRC)
45+
@# Remove temporary files.
46+
@grep -lZ 'This file redirects' $(HTML) | xargs -0 rm -f --
47+
@echo "done."
48+
49+
@echo -n "Replacing LaTeX with MathML..."; \
50+
./get-math.js db.json $(HTML); \
51+
./put-math.js db.json $(HTML); \
52+
echo "done."
53+
54+
@echo -n "Syntax highlighting Scheme code..."; \
55+
./batch-prettify.js $(HTML); \
56+
echo "done."
57+
58+
@# Add xml declaration
59+
@for file in $(HTML); do \
60+
perl -0p -i -e \
61+
's/^<!DOC/<?xml version="1.0" encoding="utf-8"?>\n<!DOC/' \
62+
$$file; \
63+
done
64+
65+
@# Fix broken link
66+
@perl -0p -i -e \
67+
's{\.\./dir/index\.xhtml}{../index.xhtml}g' $(NEXUS)
68+
69+
epub: $(GOAL)
70+
71+
$(META): $(NEXUS) create_metafiles.rb
72+
@echo -n "Building ePub3 file, saving to parent directory..."
73+
@# Remove 'xmlns:xml' attribute inserted by batch-prettify.
74+
@for file in $(HTML); do \
75+
sed -i.bak "s/xmlns:xml[^ ]\+[ ]//" $$file; \
76+
done; \
77+
rm $(DIR)*.bak; \
78+
./create_metafiles.rb
79+
80+
$(THUMB): $(COVER)
81+
@inkscape -C -e $(THUMB) -f $(DIR)fig/coverpage.std.svg > /dev/null
82+
83+
$(GOAL): $(META) $(THUMB) $(FIG) $(CSS) $(FONT) mimetype META-INF/* LICENSE
84+
@if [ -f $(GOAL) ]; then rm $(GOAL); fi; \
85+
if grep -q -m 1 -l 'browsertest' $(NEXUS); then \
86+
for file in $(HTML); do \
87+
perl -0p -i.bak -e \
88+
"s{\n$(JQ)\n$(FT)\n$(BR)\n}{}" $$file; \
89+
done; \
90+
rm $(DIR)*.bak; \
91+
fi; \
92+
zip -0Xq $(GOAL) mimetype; \
93+
zip -Xr9Dq $(GOAL) $(META) $(HTML) META-INF/* LICENSE \
94+
index.xhtml $(DIR)css/* $(DIR)fig/* ; \
95+
echo "done."
96+
97+
.PHONY: all epub html

README.md

+45-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,47 @@
1-
sicp
1+
SICP
22
====
33

4-
HTML5/EPUB3 version of SICP
4+
<img src="http://sicpebook.files.wordpress.com/2013/09/smile0.png"
5+
alt="Par smiling" align="right" />
6+
7+
This is a new HTML5 and EPUB3 version of "Structure and Interpretation of Computer Programs" by Abelson, Sussman, and Sussman. It comes from the lineage of [Unofficial Texinfo Format](http://www.neilvandyke.org/sicp-texi/) that was converted from the original [HTML version](http://mitpress.mit.edu/sicp/) at The MIT Press.
8+
9+
<b>The book in EPUB3 format: [sicp.epub](https://drive.google.com/file/d/0B-2S-gwdOpdaTFJVZEdHbS1Td0U/edit?usp=sharing)</b>
10+
11+
Modern solutions such as scalable vector graphics, mathematical markup with MathML and MathJax, embedded web fonts, and syntax highlighting are used. Rudimentary scaffolding for responsive design is in place, which adapts the page for viewing on pocket devices and tablets. More tests on small screens are needed to adjust the font size and formatting, so I encourage feedback from smartphone and tablet owners.
12+
13+
Source
14+
------
15+
16+
The root directory contains the Texinfo source in `sicp-pocket.texi.` To recreate the HTML files and build EPUB, enter:
17+
18+
```bash
19+
$ make
20+
```
21+
22+
All the files in `html` directory, but not in subdirectories, will be overwritten, so the preferred place to make changes is `sicp-pocket.texi.` The EPUB file will be created in the parent directory, outside of the project tree.
23+
24+
You will need [Texinfo 5.1](http://ftp.gnu.org/gnu/texinfo/), Perl 5.12 or later, Ruby 1.9.3 or newer, [Nokogiri](http://nokogiri.org/) gem, [PhantomJS](http://phantomjs.org/), and Internet connection to compile the book.
25+
26+
Acknowledgements
27+
----------------
28+
29+
* Lytha Ayth
30+
* Neil Van Dyke
31+
* Gavrie Philipson
32+
* Li Xuanji
33+
* J. E. Johnson
34+
35+
License
36+
-------
37+
38+
The source file `sicp-pocket.texi,` the HTML content of the book, and the diagrams in directory `html/fig` are licensed under Creative Commons Attribution-ShareAlike 3.0 Unported License ([cc by-sa](http://creativecommons.org/licenses/by-sa/3.0/)).
39+
40+
Most of the scripts are licensed under GNU General Public License version 3 (for details, see LICENSE.src).
41+
42+
Fonts are under SIL Open Font License version 1.1. Other files, like Javascript libraries, have their own licenses.
43+
44+
Sister project
45+
--------------
46+
47+
A [PDF version](https://github.com/sarabander/sicp-pdf) built from LaTeX source accompanies this HTML version.

batch-prettify.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env phantomjs
2+
3+
// Usage: ./batch-prettify.js file1 [file2 ...]
4+
// It prettifies Scheme code in the HTML files.
5+
6+
// (c) 2014 Andres Raba, GNU GPL v.3.
7+
8+
// Heads of the files should have these scripts:
9+
// <script class="prettifier" src="js/highlight/prettify.js" type="text/javascript"></script>
10+
// <script class="prettifier" src="js/highlight/lang-lisp.js" type="text/javascript"></script>
11+
12+
// General structure of the program follows this example:
13+
// https://github.com/ariya/phantomjs/blob/master/examples/follow.js
14+
15+
var system = require('system'),
16+
fs = require('fs');
17+
18+
// Put command-line arguments to an array, filter out nonexistent files.
19+
if (system.args.length <= 1) {
20+
console.log("Usage: ./batch-prettify.js file1 [file2 ...]");
21+
phantom.exit();
22+
}
23+
else {
24+
var files = system.args.slice(1);
25+
files = files.filter(function (file) {
26+
if (fs.exists(file)) { return true; }
27+
else { console.log('No such file: ' + file); return false; }
28+
});
29+
}
30+
31+
// Open the file as webpage and run prettifier over it.
32+
function loadpage(file, callback) {
33+
var page = require('webpage').create();
34+
page.onAlert = function (doc) {
35+
fs.write(file, doc, 'w');
36+
page.close();
37+
callback.apply();
38+
};
39+
page.open(file, function (status) {
40+
if (status !== 'success') {
41+
console.log('Failed to open file: ' + file);
42+
}
43+
else {
44+
page.evaluate(function () {
45+
prettyPrint(function () {
46+
// When prettified, remove the scripts from document,
47+
var scripts = document.getElementsByClassName('prettifier');
48+
var scripts_length = scripts.length;
49+
for (var i = 0; i < scripts_length; i++) {
50+
scripts[0].parentNode.removeChild(scripts[0]);
51+
};
52+
// and send the processed page as alert to onAlert handler.
53+
alert('<!DOCTYPE ' + document.doctype.name + '>\n'
54+
+ document.childNodes[1].outerHTML);
55+
});
56+
});
57+
}
58+
});
59+
};
60+
61+
// Recursively process all the files
62+
function process() {
63+
if (files.length > 0) {
64+
var file = files.shift();
65+
loadpage(file, process);
66+
}
67+
else {
68+
phantom.exit();
69+
}
70+
}
71+
72+
process();

0 commit comments

Comments
 (0)