diff --git a/src/Makefile b/src/Makefile index 7f087b9a..0e87c202 100644 --- a/src/Makefile +++ b/src/Makefile @@ -11,8 +11,10 @@ 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) @@ -20,21 +22,27 @@ 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 ;\ @@ -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) diff --git a/src/colophon.tex b/src/colophon.tex index b2955680..ae1cbbc9 100644 --- a/src/colophon.tex +++ b/src/colophon.tex @@ -13,4 +13,9 @@ Scala code translation was done by \urlref{https://github.com/typelevel/CT_from_Programmers.scala}{Typelevel} contributors. } -\fi \ No newline at end of file +\fi +\ifdefined\OPTCustomLanguageKotlin{% +Kotlin code translation was done by +\urlref{https://github.com/arrow-kt/Category-Theory-for-Programmers.kt}{ΛRROW} contributors. +} +\fi diff --git a/src/content/editor-note.tex b/src/content/editor-note.tex index 0beb5c47..65c660cb 100644 --- a/src/content/editor-note.tex +++ b/src/content/editor-note.tex @@ -5,4 +5,10 @@ \addcontentsline{toc}{chapter}{A note from the editor} \input{content/\OPTCustomLanguage/editor-note} } -\fi \ No newline at end of file +\fi +\ifdefined\OPTCustomLanguageKotlin{% + \chapter*{A note from the editor} + \addcontentsline{toc}{chapter}{A note from the editor} + \input{content/\OPTCustomLanguageKotlin/editor-note} +} +\fi diff --git a/src/content/kotlin/editor-note.tex b/src/content/kotlin/editor-note.tex new file mode 100644 index 00000000..9fcbc8b5 --- /dev/null +++ b/src/content/kotlin/editor-note.tex @@ -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. diff --git a/src/ctfp-print-kotlin.tex b/src/ctfp-print-kotlin.tex new file mode 100644 index 00000000..4029b776 --- /dev/null +++ b/src/ctfp-print-kotlin.tex @@ -0,0 +1,3 @@ +\input{opt-kotlin} +\input{ctfp-print} +\input{postamble} diff --git a/src/ctfp-reader-kotlin.tex b/src/ctfp-reader-kotlin.tex new file mode 100644 index 00000000..a1ff5b55 --- /dev/null +++ b/src/ctfp-reader-kotlin.tex @@ -0,0 +1,3 @@ +\input{opt-kotlin} +\input{ctfp-reader} +\input{postamble} diff --git a/src/fig/icons/kotlin.png b/src/fig/icons/kotlin.png new file mode 100644 index 00000000..b7fac5d0 Binary files /dev/null and b/src/fig/icons/kotlin.png differ diff --git a/src/half-title.tex b/src/half-title.tex index 84c1b65b..f8ccf84f 100644 --- a/src/half-title.tex +++ b/src/half-title.tex @@ -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} @@ -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} \ No newline at end of file +\end{small} diff --git a/src/opt-kotlin.tex b/src/opt-kotlin.tex new file mode 100644 index 00000000..258c9eaf --- /dev/null +++ b/src/opt-kotlin.tex @@ -0,0 +1,3 @@ +\def\OPTCustomLanguageKotlin{kotlin} +\def\OPTCustomLanguageKotlinExt{kt} +\def\OPTCustomLanguageKotlinColor{orange} diff --git a/src/preamble.tex b/src/preamble.tex index e9feead5..cbb328dc 100644 --- a/src/preamble.tex +++ b/src/preamble.tex @@ -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}{