mirror of
https://github.com/cs341-illinois/coursebook.git
synced 2026-10-01 23:54:40 +08:00
Beta of epub build
This commit is contained in:
@@ -228,5 +228,7 @@ main.pdf
|
||||
_out/*
|
||||
*pdf
|
||||
order.tex
|
||||
*.epub
|
||||
# Don't ask about it
|
||||
-B
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ matrix:
|
||||
- name: Wiki Build
|
||||
python: '3.6'
|
||||
env: BUILD_FOCUS=WIKI
|
||||
- name: Epub Build
|
||||
python: '3.6'
|
||||
env: BUILD_FOCUS=EPUB
|
||||
- name: PDF Build
|
||||
python: '3.6'
|
||||
env: BUILD_FOCUS=PDF
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# Find all tex files one directory down
|
||||
TEX=$(shell find . -path "./.git*" -prune -o -type f -iname "*.tex" -print)
|
||||
MAIN_TEX=main.tex
|
||||
MAIN_TEX=main_wrapper.tex
|
||||
PDF_TEX=$(patsubst %.tex,%.pdf,$(MAIN_TEX))
|
||||
MAIN_OUT=main.pdf
|
||||
BASE=$(patsubst %.tex,%,$(MAIN_TEX))
|
||||
OTHER_FILES=$(addprefix $(BASE),.aux .log .synctex.gz .toc .out .blg .bbl .glg .gls .ist .glo)
|
||||
BIBS=$(shell find . -maxdepth 2 -mindepth 2 -path "./.git*" -prune -o -type f -iname "*.bib" -print)
|
||||
@@ -14,7 +15,7 @@ TEX_ORDER=$(shell sh -c "cat order.yaml | sed 's/^- //'")
|
||||
CHAPTER_PDF=$(patsubst %,%.pdf,$(TEX_ORDER))
|
||||
|
||||
.PHONY: all
|
||||
all: $(PDF_TEX) chapters
|
||||
all: $(MAIN_OUT) chapters
|
||||
-@latexmk -c
|
||||
-@rm *aux *bbl *glg *glo *gls *ist *latexmk *fls
|
||||
-@rm **/*aux **/*bbl **/*glg **/*glo **/*gls **/*ist **/*latexmk **/*fls
|
||||
@@ -36,14 +37,15 @@ $(CHAPTER_PDF): %.pdf: %.tex
|
||||
@ls $@ > /dev/null
|
||||
-@rm $@.tmp
|
||||
|
||||
$(PDF_TEX): $(TEX) $(MAIN_TEX) $(BIBS) Makefile $(ORDER_TEX)
|
||||
-@latexmk -quiet -interaction=nonstopmode -f -pdf $(MAIN_TEX) # 2>&1 >/dev/null
|
||||
$(MAIN_OUT): $(TEX) $(MAIN_TEX) $(BIBS) Makefile $(ORDER_TEX)
|
||||
-@latexmk -quiet -interaction=nonstopmode -f -pdf $(MAIN_TEX)
|
||||
@ls $(PDF_TEX) > /dev/null
|
||||
@mv $(PDF_TEX) $(MAIN_OUT)
|
||||
@echo "Finished"
|
||||
|
||||
$(PDF_TEX)-debug: $(TEX) $(MAIN_TEX) $(BIBS) Makefile
|
||||
-@latexmk -interaction=nonstopmode -f -pdf $(MAIN_TEX) > latexmk.out
|
||||
-@mv $(PDF_TEX) $(PDF_TEX-debug)
|
||||
@mv $(PDF_TEX)-debug $(MAIN_OUT)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
@@ -10,6 +10,8 @@ if test $BUILD_FOCUS = WIKI; then
|
||||
|
||||
# Run the actual script
|
||||
bash _scripts/push_to_wiki.sh;
|
||||
elif test $BUILD_FOCUS = "EPUB"
|
||||
ls
|
||||
else
|
||||
# Copy main to a tempfile, so we don't get any checkout errors
|
||||
TMP_DIR=`mktemp -d`;
|
||||
|
||||
@@ -13,6 +13,7 @@ then
|
||||
sudo dpkg -i pandoc-2.7-1-amd64.deb
|
||||
popd
|
||||
else
|
||||
# EPUB and MD
|
||||
echo ""
|
||||
fi;
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Pandoc filter to change each relative URL to absolute
|
||||
"""
|
||||
|
||||
from panflute import run_filter, Str, Header, Image, Math, Link, RawInline
|
||||
import sys
|
||||
import re
|
||||
import os.path
|
||||
|
||||
default_image_alt = 'image'
|
||||
|
||||
class NoAltTagException(Exception):
|
||||
pass
|
||||
|
||||
def replace_suffix(content, suffix_old, suffix_new):
|
||||
ret = content
|
||||
if content.endswith(suffix_old):
|
||||
ret = content[:-len(suffix_old)] + suffix_new
|
||||
return ret
|
||||
|
||||
def deserialize(x):
|
||||
"""
|
||||
Takes a panflute element x and returns
|
||||
a basic stringified version of that element
|
||||
"""
|
||||
|
||||
if type(x) == Str:
|
||||
return x.text
|
||||
return ' '
|
||||
|
||||
def doc_filter(elem, doc):
|
||||
if type(elem) == Image:
|
||||
# Get the number of chars for the alt tag
|
||||
alt_name = ''.join(map(deserialize, elem._content.list))
|
||||
alt_length = len(elem._content)
|
||||
# No alt means no compile
|
||||
# Accessibility by default
|
||||
if alt_length == 0 or alt_name.lower() == default_image_alt:
|
||||
raise NoAltTagException(elem.url)
|
||||
|
||||
# Otherwise link to the raw user link instead of relative
|
||||
# That way the wiki and the site will have valid links automagically
|
||||
new_url = replace_suffix(elem.url, '.eps', '.png')
|
||||
if not os.path.isfile(new_url):
|
||||
raise ValueError('{} Not found'.format(new_url))
|
||||
elem.url = new_url
|
||||
return elem
|
||||
|
||||
|
||||
def main(doc=None):
|
||||
return run_filter(doc_filter, doc=doc)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Every script should have thisj
|
||||
# Every script should have this
|
||||
set -e
|
||||
|
||||
DOCS_SHA=$(git rev-parse --short HEAD)
|
||||
|
||||
@@ -5,6 +5,16 @@ set -o errexit;
|
||||
if test $BUILD_FOCUS = "WIKI"
|
||||
then
|
||||
echo "Dummy Step"
|
||||
elif test $BUILD_FOCUS = "EPUB"
|
||||
pandoc --toc -s -f latex \
|
||||
-t epub \
|
||||
--filter pandoc-citeproc \
|
||||
--filter _scripts/pandoc_epub_filter.py \
|
||||
-M link-citations=true \
|
||||
--epub-cover-image _images/cover.png \
|
||||
-M author="B. Venkatesh, L. Angrave, et Al." \
|
||||
-o main.epub \
|
||||
main.tex
|
||||
else
|
||||
make
|
||||
fi;
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
\renewcommand{\keyword}[1]{\texttt{#1}}
|
||||
\renewenvironment{proof}{\\ \textbf{(Optional) Proof:} \\}{\\ \textbf{(Optional) ■} \\}
|
||||
|
||||
\renewenvironment{titlepage}
|
||||
{
|
||||
\comment
|
||||
}
|
||||
{
|
||||
\endcomment
|
||||
}
|
||||
%% Begin unicode math
|
||||
|
||||
\renewcommand{\neg}[0]{¬}
|
||||
|
||||
@@ -68,12 +68,33 @@
|
||||
%% Add some space to the table of contents justification
|
||||
\addtolength{\cftsecnumwidth}{10pt}
|
||||
|
||||
%% Epub command
|
||||
|
||||
\ifcsname ifepub\endcsname\else
|
||||
\expandafter\let\csname ifepub\expandafter\endcsname
|
||||
\csname iffalse\endcsname
|
||||
\fi
|
||||
|
||||
\ifepub
|
||||
\include{github_redefinitions}
|
||||
\usepackage{filecontents}
|
||||
\begin{filecontents}{title.tex}
|
||||
%% These are not the droids you are looking for
|
||||
\end{filecontents}
|
||||
\fi
|
||||
|
||||
\begin{document}
|
||||
|
||||
\raggedbottom
|
||||
|
||||
%% The title so that it isn't included in the chapters
|
||||
|
||||
\include{title}
|
||||
|
||||
\setcounter{secnumdepth}{1}
|
||||
\setcounter{tocdepth}{1}
|
||||
|
||||
\tableofcontents
|
||||
\fancyhf{}
|
||||
|
||||
%% Introduction, background, then the book starts
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
\let\ifepub\iffalse\input{main.tex}
|
||||
@@ -1,6 +1,18 @@
|
||||
\pagestyle{fancy}
|
||||
\setcounter{secnumdepth}{1}
|
||||
\setcounter{tocdepth}{1}
|
||||
|
||||
\ifepub
|
||||
%% Really gross hack for epub
|
||||
%% Comment out all the environments that would output something and put them back in after
|
||||
%% Why can't we just comment out the titlepage command?
|
||||
%% Latex and pandoc make it difficult with macros
|
||||
|
||||
\let\oldbf\textbf
|
||||
\renewcommand{\textbf}[1]{}
|
||||
|
||||
\let\oldgraphics\includegraphics
|
||||
\renewcommand{\includegraphics}[2][]{}
|
||||
|
||||
\fi
|
||||
|
||||
\begin{titlepage}
|
||||
\newgeometry{left=6cm} %defines the geometry for the titlepage
|
||||
@@ -13,7 +25,9 @@
|
||||
\par
|
||||
{\color{linecolor}\makebox[0pt][l]{\rule{1.3\textwidth}{3pt}}\color{white}}
|
||||
\vfill
|
||||
|
||||
\includegraphics[width=10cm]{_images/duck-alpha-cropped.png}
|
||||
|
||||
\vfill
|
||||
\noindent
|
||||
\textbf{ {\huge B. Venkatesh, L. Angrave, et Al.} }
|
||||
@@ -22,9 +36,12 @@
|
||||
\vskip\baselineskip
|
||||
\end{titlepage}
|
||||
|
||||
\ifepub
|
||||
\let\textbf\oldbf
|
||||
\let\includegraphics\oldgraphics
|
||||
\fi
|
||||
|
||||
\restoregeometry % restores the geometry
|
||||
\nopagecolor% Use this to restore the color pages to white
|
||||
|
||||
\tableofcontents
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user