Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Kotlin Edition configuration files #217

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/kotlin-edition.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: KotlinEdition

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Build Kotling Edition
run: |
export NIX_CURL_FLAGS=-sS
wget --retry-connrefused --waitretry=1 -O /tmp/nix-install https://nixos.org/releases/nix/nix-2.0.4/install
sh /tmp/nix-install
. ~/.nix-profile/etc/profile.d/nix.sh
nix-env --version
nix-instantiate --eval -E 'with import <nixpkgs> {}; lib.version or lib.nixpkgsVersion'
nix-shell --pure --command 'cd src; make kotlin' || echo "Skipping the failures for now..."
- name: Show PDF files
run: |
echo -e "INFO:\n\tOK: PDF file in out directory\n\tFAILURE = PDF file in src directory"
find . -name "*.pdf"
mkdir pdf-files
mv `find . -name "*.pdf"` pdf-files
- uses: actions/upload-artifact@master
with:
name: partial-book
path: pdf-files
17 changes: 14 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,38 @@ DEFAULTTOPTEX = ctfp-reader.tex ctfp-print.tex

SCALATEXFILES = ctfp-reader-scala.tex ctfp-print-scala.tex # todo make this a macro

KOTLINTEXFILES = ctfp-reader-kotlin.tex ctfp-print-kotlin.tex # todo make this a macro

# Top-level LaTeX files from which CTFP book can be generated
TOPTEXFILES = version.tex $(DEFAULTTOPTEX) $(SCALATEXFILES)
TOPTEXFILES = version.tex $(DEFAULTTOPTEX) $(SCALATEXFILES) $(KOTLINTEXFILES)

# Default PDF file to make
DEFAULTPDF:=$(DEFAULTTOPTEX:.tex=.pdf)

# Scala PDF file to make
SCALAPDF:=$(SCALATEXFILES:.tex=.pdf)

# Kotlin PDF file to make
KOTLINPDF:=$(KOTLINTEXFILES:.tex=.pdf)

# Other PDF files for the CTFP book
TOPPDFFILES:=$(TOPTEXFILES:.tex=.pdf)

# Configuration files
OPTFILES = opt-print-ustrade.tex \
opt-reader-10in.tex \
opt-scala.tex
opt-scala.tex \
opt-kotlin.tex

# All the LaTeX files for the CTFP book in order of dependency
TEXFILES = $(TOPTEXFILES) $(SCALATEXFILES) $(OPTFILES)
TEXFILES = $(TOPTEXFILES) $(SCALATEXFILES) $(KOTLINTEXFILES) $(OPTFILES)

default: $(DEFAULTPDF) copy # todo cover

scala: version.tex $(SCALAPDF) copy-scala

kotlin: version.tex $(KOTLINPDF) copy-kotlin

# Main targets
$(TOPPDFFILES) : %.pdf : %.tex $(TEXFILES)
if which latexmk > /dev/null 2>&1 ;\
Expand All @@ -53,6 +61,9 @@ copy: copy-task
copy-scala: suffix = '-scala'
copy-scala: copy-task

copy-kotlin: suffix = '-kotlin'
copy-kotlin: copy-task

copy-task:
echo 'Creating output directory: $(GIT_VER)'
mkdir -p ../out/$(GIT_VER)
Expand Down
7 changes: 6 additions & 1 deletion src/colophon.tex
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@
Scala code translation was done by
\urlref{https://github.com/typelevel/CT_from_Programmers.scala}{Typelevel} contributors.
}
\fi
\fi
\ifdefined\OPTCustomLanguageKotlin{%
Kotlin code translation was done by
\urlref{https://github.com/arrow-kt/Category-Theory-for-Programmers.kt}{ΛRROW} contributors.
}
\fi
8 changes: 7 additions & 1 deletion src/content/editor-note.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
\addcontentsline{toc}{chapter}{A note from the editor}
\input{content/\OPTCustomLanguage/editor-note}
}
\fi
\fi
\ifdefined\OPTCustomLanguageKotlin{%
\chapter*{A note from the editor}
\addcontentsline{toc}{chapter}{A note from the editor}
\input{content/\OPTCustomLanguageKotlin/editor-note}
}
\fi
29 changes: 29 additions & 0 deletions src/content/kotlin/editor-note.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
% !TEX root = ctfp-print.tex

\lettrine[lhang=0.17]{T}{his is the Kotlin edition} of \emph{Category Theory for Programmers}.
It's been a tremendous success, making Bartosz Milewski's blog post series available as a nicely
typeset \acronym{PDF}, as well as a hardcover book. There have been numerous contributions made
to improve the book, by fixing typos and errors, as well as translating the code snippets into
other programming languages.

I am thrilled to present this edition of the book, containing the original Haskell code, followed by
its Kotlin counterpart. The Kotlin code snippets were generously provided by
\urlref{https://github.com/arrow-kt/Category-Theory-for-Programmers.kt}{ΛRROW} contributors, slightly
modified to suit the format of this book.

To support code snippets in multiple languages, I am using a \LaTeX{} macro to load the code snippets
from external files. This allows easily extending the book with other languages, while leaving the
original text intact. Which is why you should mentally append the words ``and Kotlin'' whenever you see
``in Haskell'' in the text.

The code is laid out in the following manner: the original Haskell code, followed by Kotlin code.
To distinguish between them, the code snippets are braced from the left with a vertical bar, in the primary
color of the language's logo, \raisebox{-.2mm}{\includegraphics[height=.3cm]{fig/icons/haskell.png}},
and \raisebox{-.2mm}{\includegraphics[height=.3cm]{fig/icons/kotlin.png}} respectively, e.g.:

\srcsnippet{content/1.5/code/haskell/snippet15.hs}{blue}{haskell}
\unskip
\srcsnippet{content/1.5/code/kotlin/snippet15.kt}{orange}{kotlin}
\NoIndentAfterThis
TODO: In addition, some Scala snippets make use of the
\urlref{https://github.com/non/kind-projector}{Kind Projector} compiler plugin, to support nicer syntax for partially-applied types.
3 changes: 3 additions & 0 deletions src/ctfp-print-kotlin.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\input{opt-kotlin}
\input{ctfp-print}
\input{postamble}
3 changes: 3 additions & 0 deletions src/ctfp-reader-kotlin.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\input{opt-kotlin}
\input{ctfp-reader}
\input{postamble}
Binary file added src/fig/icons/kotlin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion src/half-title.tex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
}
}
\fi
\ifdefined\OPTCustomLanguageKotlin{%
\vspace*{1cm}
\small\selectfont{
\textbf{\titlecap{\OPTCustomLanguageKotlin} Edition}\\
\textit{Contains code snippets in Haskell and \titlecap{\OPTCustomLanguageKotlin}}\\
}
}
\fi
\vspace*{1cm}
\fontsize{16pt}{18pt}\selectfont \textit{By } \textbf{Bartosz Milewski}\\
\vspace{1cm}
Expand Down Expand Up @@ -63,4 +71,4 @@
\noindent
\LaTeX{} source code is available on GitHub: \href{https://github.com/hmemcpy/milewski-ctfp-pdf}{https://github.com/hmemcpy/milewski-ctfp-pdf}
\end{center}
\end{small}
\end{small}
3 changes: 3 additions & 0 deletions src/opt-kotlin.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\def\OPTCustomLanguageKotlin{kotlin}
\def\OPTCustomLanguageKotlinExt{kt}
\def\OPTCustomLanguageKotlinColor{orange}
5 changes: 5 additions & 0 deletions src/preamble.tex
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@
\srcsnippet{\currfileabsdir/code/\OPTCustomLanguage/#1.\OPTCustomLanguageExt}{\OPTCustomLanguageColor}{\OPTCustomLanguage}{#2}
}
\fi
\ifdefined\OPTCustomLanguageKotlin{%
\unskip
\srcsnippet{\currfileabsdir/code/\OPTCustomLanguageKotlin/#1.\OPTCustomLanguageKotlinExt}{\OPTCustomLanguageKotlinColor}{\OPTCustomLanguageKotlin}{#2}
}
\fi
\NoIndentAfterThis
}
\NewDocumentCommand\srcsnippet{mmmm}{
Expand Down