-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the ebook-example repo is now in this repo too
- Loading branch information
Showing
20 changed files
with
420 additions
and
6 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 @@ | ||
ebook-example |
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
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
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
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.0.0 |
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,10 @@ | ||
.sconsign.dblite | ||
*.mobi | ||
*.epub | ||
*.log | ||
*.html | ||
*.xhtml | ||
*.opf | ||
outdir | ||
bazel-* |
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,48 @@ | ||
load("@bazel_ebook//build:rules.bzl", | ||
"asymptote", | ||
"ebook_epub", | ||
"ebook_kindle", | ||
"ebook_pdf", | ||
"markdown_lib", | ||
) | ||
|
||
asymptote( | ||
name = "test", | ||
srcs = ["test.asy"], | ||
deps = ["//images:test2"], | ||
) | ||
|
||
markdown_lib( | ||
name = "md", | ||
srcs = [ | ||
"book.ch001.md", | ||
"book.ch002.md", | ||
"book.ch004.md", | ||
], | ||
deps = [ | ||
"//images:dot", | ||
"//images:md", | ||
":test", | ||
], | ||
) | ||
|
||
ebook_epub( | ||
name = "book_epub", | ||
deps = [":md"], | ||
metadata_xml = "epub-metadata.xml", | ||
title_yaml = "title.yaml", | ||
) | ||
|
||
ebook_pdf( | ||
name = "book_pdf", | ||
deps = [":md"], | ||
metadata_xml = "epub-metadata.xml", | ||
title_yaml = "title.yaml", | ||
) | ||
|
||
ebook_kindle( | ||
name = "book_kindle", | ||
deps = [":md"], | ||
metadata_xml = "epub-metadata.xml", | ||
title_yaml = "title.yaml", | ||
) |
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,79 @@ | ||
# Introduction | ||
|
||
Here is a minimal example of using Markdown to write a sciency book that | ||
includes source code listings or equations. "Sciency" because it's assumed | ||
that the amount of listings or equations is small, and their relationship | ||
uncomplicated. | ||
|
||
The book content is generated in several formats: | ||
|
||
* PDF (e.g. for printing on paper) | ||
* ePub (for electronic readers that support it, basically anything *except* | ||
Kindle) | ||
* mobi (for Kindle) | ||
|
||
# Prerequisites | ||
|
||
* [bazel](https://bazel.io), for building. | ||
* [docker](https://docker.io), because part of the bazel build process needs | ||
docker | ||
|
||
|
||
# Building | ||
|
||
``` | ||
bazel build //:all | ||
``` | ||
|
||
Yes, it's that easy. This will run the commands needed to produce a PDF file, | ||
an ePub file and a mobi (Kindle) format file. Find those files in the | ||
`bazel-bin` directory once the build process ends. | ||
|
||
If you want to build specific formats, the following commands apply: | ||
|
||
``` | ||
bazel build //:book_epub | ||
``` | ||
|
||
This will build a book in the EPUB format. Once build completes, find it in | ||
the directory `bazel-bin/book_epub.epub`. | ||
|
||
``` | ||
bazel build //:book_kindle | ||
``` | ||
|
||
This will build a book in Kindle's MOBI format. Once the build completes, find | ||
it in the directory `bazel-bin/book_kindle.mobi`. You should be able to upload | ||
this book to either your Amazon digital library, or your Kindle device and read | ||
it right away. | ||
|
||
# Cleanup | ||
|
||
``` | ||
bazel clean | ||
``` | ||
|
||
Yes, it's that easy. | ||
|
||
# Caveats | ||
|
||
* The equations for the mobi format are generated as 300dpi files. Epub is | ||
currently unusable because of this; if epub is needed, then we need a | ||
completely separate epub build rule that builds it directly. | ||
* The build script generates html with embedded images for equations. Probably | ||
we need something similar to epub production above. | ||
* The `epub-metadata.xml` file actually *must not* be well-formed XML. Only | ||
bare "Dublin core" markup elements are allowed if you want that markup XML to | ||
make it into the actual book contents. I don't quite understand why, but | ||
that is how things are today. | ||
* Apparently the `epub-metadata.xml` gets ignored if you build your ebook from | ||
markdown. This matters for the directly-generated epub version which is made | ||
directly from the Markdown source (in contrast to the `.mobi` version which | ||
requires several steps to produce) | ||
|
||
# TODO | ||
|
||
* Add an example title page. | ||
* Add an example generated figure e.g. with tikZ or some other involved | ||
drawing program. | ||
|
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,56 @@ | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") | ||
|
||
# Go build rules | ||
http_archive( | ||
name = "io_bazel_rules_go", | ||
sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", | ||
"https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", | ||
], | ||
) | ||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") | ||
go_rules_dependencies() | ||
go_register_toolchains(version = "1.18.3") | ||
http_archive( | ||
name = "bazel_gazelle", | ||
sha256 = "efbbba6ac1a4fd342d5122cbdfdb82aeb2cf2862e35022c752eaddffada7c3f3", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz", | ||
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz", | ||
], | ||
) | ||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") | ||
gazelle_dependencies() | ||
|
||
local_repository( | ||
name = "bazel_ebook", | ||
path = "..", | ||
) | ||
#git_repository( | ||
#name = "bazel_ebook", | ||
#remote = "https://github.com/filmil/bazel-ebook", | ||
#commit = "09181e87bb1e2ffb2988180438f0f6bb464061c5", | ||
#shallow_since = "1634887024 -0700", | ||
#) | ||
|
||
git_repository( | ||
name = "bazel_rules_bid", | ||
remote = "https://github.com/filmil/bazel-rules-bid.git", | ||
commit = "04b599ec790fe4572dfb851e145c791cb5022c15", | ||
shallow_since = "1676537869 -0800" | ||
) | ||
load("@bazel_rules_bid//build:repositories.bzl", "bazel_bid_repositories") | ||
bazel_bid_repositories() | ||
|
||
load("@gotopt2//build:deps.bzl", "gotopt2_dependencies") | ||
gotopt2_dependencies() | ||
|
||
load( | ||
"@bazel_ebook//build:repositories.bzl", | ||
"bazel_ebook_repositories", | ||
) | ||
|
||
bazel_ebook_repositories() | ||
|
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,91 @@ | ||
# Hello world! | ||
|
||
I'm a test Markdown document. | ||
|
||
**Here's some bold text** and *here's some italic text*. `This is inline code`. | ||
|
||
# Markdown Tables | ||
|
||
First Name | Last Name | Location | Allegiance | ||
------------|-------------|---------------------|----------------- | ||
Mance | Rayder | North of the Wall | Wildlings | ||
Margaery | Tyrell | The Reach | House Tyrell | ||
Danerys | Targaryen | Meereen | House Targaryen | ||
Tyrion | Lannister | King's Landing | House Lannister | ||
|
||
# Code blocks | ||
|
||
This code | ||
is in | ||
a code block. | ||
|
||
Here's a syntax-highlighted code block: | ||
|
||
```python | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
|
||
if __name__ == '__main__': | ||
print('This is highlighted Python code!') | ||
sys.exit(0) | ||
``` | ||
|
||
# Page Layout with \LaTeX\ Commands | ||
|
||
Here's a forced page break. | ||
|
||
\pagebreak | ||
|
||
# LaTeX support | ||
|
||
This document supports inline \LaTeX! | ||
|
||
Here's the proof: $\frac{n!}{k!(n-k)!} = \binom{n}{k}$ | ||
|
||
Creating a footnote is easy.\footnote{An example footnote.} | ||
|
||
Here's an equation: | ||
|
||
$$ | ||
x = a_0 + \cfrac{1}{a_1 | ||
+ \cfrac{1}{a_2 | ||
+ \cfrac{1}{a_3 + \cfrac{1}{a_4} } } } | ||
$$ | ||
|
||
Here are some numbered equations: | ||
|
||
$$ | ||
f(x)=(x+a)(x+b) | ||
$$ | ||
|
||
$$ | ||
5^2 - 5 = 20 | ||
$$ | ||
|
||
$$ | ||
a = bq + r | ||
$$ | ||
|
||
Here's some multi-line math stuff: | ||
|
||
$$ | ||
u(x) = | ||
\begin{cases} | ||
\exp{x} & \text{if } x \geq 0 \\ | ||
1 & \text{if } x < 0 | ||
\end{cases} | ||
$$ | ||
|
||
\begin{align*} | ||
f(x) &= (x+a)(x+b) \\ | ||
&= x^2 + (a+b)x + ab | ||
\end{align*} | ||
|
||
# Images | ||
|
||
Let's try some images. | ||
|
||
![Here is an image of a Pythagorean tree.](test.asy.png) | ||
|
||
|
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 @@ | ||
# Chapter two | ||
|
||
Some text here. | ||
|
||
![Here is an image of a Pythagorean tree again.](images/test1.asy.png) |
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 @@ | ||
# Chapter four | ||
|
||
Some text here. | ||
|
||
![Here is a simple graph](images/simple_graph.dot.png) |
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,3 @@ | ||
<dc:title id="epub-title-1">Ebook Example</dc:title> | ||
<dc:title id="epub-title-2">How to write an ebook in markdown.</dc:title> | ||
<dc:creator>Filip Filmar</dc:creator> |
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,31 @@ | ||
load("@bazel_ebook//build:rules.bzl", | ||
"asymptote", | ||
"dot_png", | ||
"markdown_lib", | ||
) | ||
|
||
package( | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
asymptote( | ||
name = "test2", | ||
srcs = ["test1.asy"], | ||
) | ||
|
||
asymptote( | ||
name = "test3", | ||
srcs = ["test2.asy"], | ||
) | ||
|
||
|
||
markdown_lib( | ||
name = "md", | ||
srcs = ["book.ch003.md",], | ||
deps = [":test3"], | ||
) | ||
|
||
dot_png( | ||
name = "dot", | ||
srcs = ["simple_graph.dot"], | ||
) |
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 @@ | ||
# Chapter three | ||
|
||
Some text here. | ||
|
||
![Local pythagorean tree](images/test2.asy.png) |
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,8 @@ | ||
graph { | ||
a -- b; | ||
b -- c; | ||
a -- c; | ||
d -- c; | ||
e -- c; | ||
e -- a; | ||
} |
Oops, something went wrong.