forked from sarabander/sicp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e820c4
commit 9745145
Showing
290 changed files
with
160,623 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.json | ||
*.vim | ||
*.swp | ||
*~ | ||
\#*\# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
LICENSING TERMS | ||
|
||
The HTML files of the book and illustrations in | ||
directory 'html/fig' are licensed under Creative Commons | ||
Attribution-ShareAlike 3.0 Unported License | ||
(http://creativecommons.org/licenses/by-sa/3.0/). |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0"?> | ||
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container"> | ||
<rootfiles> | ||
<rootfile full-path="content.opf" media-type="application/oebps-package+xml" /> | ||
</rootfiles> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Makefile for compiling sicp.epub from the sources. | ||
# (c) 2014 Andres Raba, GNU GPL v.3. | ||
|
||
DIR = html/ | ||
SRC = sicp-pocket.texi # book's Texinfo source | ||
GOAL = ../sicp.epub # the end product of compilation | ||
NEXUS = $(DIR)index.xhtml # the central file with table of contents | ||
META = content.opf toc.xhtml # epub metafiles generated from NEXUS | ||
HTML = $(DIR)*.xhtml # all the HTML files of the book | ||
FIG = $(DIR)fig/*/*.svg # SVG diagrams | ||
CSS = $(DIR)css/*.css # style files | ||
FONT = $(DIR)css/fonts/* # WOFF fonts | ||
JS = $(DIR)js/*.js # javascript libraries | ||
CONV = texi2any lib/Texinfo/Convert/HTML.pm # Texinfo converter scripts | ||
MATH = get-math.js put-math.js mathcell.xhtml # LaTeX -> MathML converter | ||
HIGHL = $(DIR)js/highlight/ | ||
PRETTY = $(HIGHL)prettify.js $(HIGHL)lang-lisp.js batch-prettify.js | ||
COVER = index.xhtml $(DIR)fig/coverpage.std.svg $(DIR)fig/bookwheel.jpg | ||
THUMB = $(DIR)fig/cover.png # thumbnail cover image | ||
SHELL = /bin/bash | ||
|
||
JQ = <script src=\"js/jquery.min.js\" type=\"text/javascript\"></script> | ||
FT = <script src=\"js/footnotes.js\" type=\"text/javascript\"></script> | ||
BR = <script src=\"js/browsertest.js\" type=\"text/javascript\"></script> | ||
|
||
all: $(GOAL) | ||
# Add scripts to the unpacked HTML5 version that is to be read in a browser. | ||
@if ! grep -m 1 -l 'browsertest' $(NEXUS); then \ | ||
for file in $(HTML); do \ | ||
perl -0p -i.bak -e \ | ||
"s{\s*</head>}{\n\n$(JQ)\n$(FT)\n$(BR)\n</head>}" $$file; \ | ||
done; \ | ||
rm $(DIR)*.bak; \ | ||
fi | ||
|
||
html: $(NEXUS) | ||
|
||
exercises.texi figures.texi: ex-fig-ref.pl | ||
@./ex-fig-ref.pl -e > exercises.texi; \ | ||
./ex-fig-ref.pl -f > figures.texi | ||
|
||
$(NEXUS): $(SRC) $(CONV) $(MATH) $(PRETTY) exercises.texi figures.texi | ||
@echo -n "Converting Texinfo file to HTML..."; \ | ||
./texi2any --no-warn --html --iftex $(SRC) | ||
@# Remove temporary files. | ||
@grep -lZ 'This file redirects' $(HTML) | xargs -0 rm -f -- | ||
@echo "done." | ||
|
||
@echo -n "Replacing LaTeX with MathML..."; \ | ||
./get-math.js db.json $(HTML); \ | ||
./put-math.js db.json $(HTML); \ | ||
echo "done." | ||
|
||
@echo -n "Syntax highlighting Scheme code..."; \ | ||
./batch-prettify.js $(HTML); \ | ||
echo "done." | ||
|
||
@# Add xml declaration | ||
@for file in $(HTML); do \ | ||
perl -0p -i -e \ | ||
's/^<!DOC/<?xml version="1.0" encoding="utf-8"?>\n<!DOC/' \ | ||
$$file; \ | ||
done | ||
|
||
@# Fix broken link | ||
@perl -0p -i -e \ | ||
's{\.\./dir/index\.xhtml}{../index.xhtml}g' $(NEXUS) | ||
|
||
epub: $(GOAL) | ||
|
||
$(META): $(NEXUS) create_metafiles.rb | ||
@echo -n "Building ePub3 file, saving to parent directory..." | ||
@# Remove 'xmlns:xml' attribute inserted by batch-prettify. | ||
@for file in $(HTML); do \ | ||
sed -i.bak "s/xmlns:xml[^ ]\+[ ]//" $$file; \ | ||
done; \ | ||
rm $(DIR)*.bak; \ | ||
./create_metafiles.rb | ||
|
||
$(THUMB): $(COVER) | ||
@inkscape -C -e $(THUMB) -f $(DIR)fig/coverpage.std.svg > /dev/null | ||
|
||
$(GOAL): $(META) $(THUMB) $(FIG) $(CSS) $(FONT) mimetype META-INF/* LICENSE | ||
@if [ -f $(GOAL) ]; then rm $(GOAL); fi; \ | ||
if grep -q -m 1 -l 'browsertest' $(NEXUS); then \ | ||
for file in $(HTML); do \ | ||
perl -0p -i.bak -e \ | ||
"s{\n$(JQ)\n$(FT)\n$(BR)\n}{}" $$file; \ | ||
done; \ | ||
rm $(DIR)*.bak; \ | ||
fi; \ | ||
zip -0Xq $(GOAL) mimetype; \ | ||
zip -Xr9Dq $(GOAL) $(META) $(HTML) META-INF/* LICENSE \ | ||
index.xhtml $(DIR)css/* $(DIR)fig/* ; \ | ||
echo "done." | ||
|
||
.PHONY: all epub html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,47 @@ | ||
sicp | ||
SICP | ||
==== | ||
|
||
HTML5/EPUB3 version of SICP | ||
<img src="http://sicpebook.files.wordpress.com/2013/09/smile0.png" | ||
alt="Par smiling" align="right" /> | ||
|
||
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. | ||
|
||
<b>The book in EPUB3 format: [sicp.epub](https://drive.google.com/file/d/0B-2S-gwdOpdaTFJVZEdHbS1Td0U/edit?usp=sharing)</b> | ||
|
||
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. | ||
|
||
Source | ||
------ | ||
|
||
The root directory contains the Texinfo source in `sicp-pocket.texi.` To recreate the HTML files and build EPUB, enter: | ||
|
||
```bash | ||
$ make | ||
``` | ||
|
||
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. | ||
|
||
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. | ||
|
||
Acknowledgements | ||
---------------- | ||
|
||
* Lytha Ayth | ||
* Neil Van Dyke | ||
* Gavrie Philipson | ||
* Li Xuanji | ||
* J. E. Johnson | ||
|
||
License | ||
------- | ||
|
||
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/)). | ||
|
||
Most of the scripts are licensed under GNU General Public License version 3 (for details, see LICENSE.src). | ||
|
||
Fonts are under SIL Open Font License version 1.1. Other files, like Javascript libraries, have their own licenses. | ||
|
||
Sister project | ||
-------------- | ||
|
||
A [PDF version](https://github.com/sarabander/sicp-pdf) built from LaTeX source accompanies this HTML version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env phantomjs | ||
|
||
// Usage: ./batch-prettify.js file1 [file2 ...] | ||
// It prettifies Scheme code in the HTML files. | ||
|
||
// (c) 2014 Andres Raba, GNU GPL v.3. | ||
|
||
// Heads of the files should have these scripts: | ||
// <script class="prettifier" src="js/highlight/prettify.js" type="text/javascript"></script> | ||
// <script class="prettifier" src="js/highlight/lang-lisp.js" type="text/javascript"></script> | ||
|
||
// General structure of the program follows this example: | ||
// https://github.com/ariya/phantomjs/blob/master/examples/follow.js | ||
|
||
var system = require('system'), | ||
fs = require('fs'); | ||
|
||
// Put command-line arguments to an array, filter out nonexistent files. | ||
if (system.args.length <= 1) { | ||
console.log("Usage: ./batch-prettify.js file1 [file2 ...]"); | ||
phantom.exit(); | ||
} | ||
else { | ||
var files = system.args.slice(1); | ||
files = files.filter(function (file) { | ||
if (fs.exists(file)) { return true; } | ||
else { console.log('No such file: ' + file); return false; } | ||
}); | ||
} | ||
|
||
// Open the file as webpage and run prettifier over it. | ||
function loadpage(file, callback) { | ||
var page = require('webpage').create(); | ||
page.onAlert = function (doc) { | ||
fs.write(file, doc, 'w'); | ||
page.close(); | ||
callback.apply(); | ||
}; | ||
page.open(file, function (status) { | ||
if (status !== 'success') { | ||
console.log('Failed to open file: ' + file); | ||
} | ||
else { | ||
page.evaluate(function () { | ||
prettyPrint(function () { | ||
// When prettified, remove the scripts from document, | ||
var scripts = document.getElementsByClassName('prettifier'); | ||
var scripts_length = scripts.length; | ||
for (var i = 0; i < scripts_length; i++) { | ||
scripts[0].parentNode.removeChild(scripts[0]); | ||
}; | ||
// and send the processed page as alert to onAlert handler. | ||
alert('<!DOCTYPE ' + document.doctype.name + '>\n' | ||
+ document.childNodes[1].outerHTML); | ||
}); | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
// Recursively process all the files | ||
function process() { | ||
if (files.length > 0) { | ||
var file = files.shift(); | ||
loadpage(file, process); | ||
} | ||
else { | ||
phantom.exit(); | ||
} | ||
} | ||
|
||
process(); |
Oops, something went wrong.