Skip to content

Commit

Permalink
WIP - Kotlin Edition configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
rachelcarmena committed Oct 2, 2019
1 parent 89589f8 commit 2f0edd8
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 7 deletions.
19 changes: 15 additions & 4 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)

# Other PDF files for the CTFP book
# 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:
@printf 'Creating output directory: $(GIT_VER)\n'
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
Loading
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

0 comments on commit 2f0edd8

Please # to comment.