From 2f0edd83dc3639f9bede6315307f5230f3e79d88 Mon Sep 17 00:00:00 2001 From: Rachel Date: Thu, 29 Aug 2019 21:14:51 +0200 Subject: [PATCH] WIP - Kotlin Edition configuration files --- src/Makefile | 19 +++++++++++++++---- src/colophon.tex | 7 ++++++- src/content/editor-note.tex | 8 +++++++- src/content/kotlin/editor-note.tex | 29 +++++++++++++++++++++++++++++ src/ctfp-print-kotlin.tex | 3 +++ src/ctfp-reader-kotlin.tex | 3 +++ src/fig/icons/kotlin.png | Bin 0 -> 4329 bytes src/half-title.tex | 10 +++++++++- src/opt-kotlin.tex | 3 +++ src/preamble.tex | 5 +++++ 10 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 src/content/kotlin/editor-note.tex create mode 100644 src/ctfp-print-kotlin.tex create mode 100644 src/ctfp-reader-kotlin.tex create mode 100644 src/fig/icons/kotlin.png create mode 100644 src/opt-kotlin.tex 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 0000000000000000000000000000000000000000..b7fac5d0b6d47c8e10e770baef46b7d3f76d3fba GIT binary patch literal 4329 zcmZ`-c{J4D`=2p(Gib;%)*(V+Fv^mQnZZ!Qn?{yC$)2T>WJzQUM%HXeLNiQxn@=LC ztVxB^rZJT2Z3=W(MP;_wq`Fe$SaoA!~{ItR>-dp$oYXbapmBzqat3J5dvi$?)9W2BYwR*|>nC;U6u+Ki=L$5EBo@ieO67D{JMITkMiu7p%qy(^LtfMJ0!>ghW4kcO1%=2==_yn69+zQ|w5aai8 z+YOnJ&D4|&JV%NXjF9fi(u-Xh@gb{fA1s6$&*OY;C#Ar|-;aGAbfy;$xTY8Q5kiJL-yocq{u=Kym$>@LfS)s2?hC#Z zDl%btCU1<*OLeNO^>1=|a_k^Uf>wNRo+%^MdeRt_Wjn+fp5-jje+Bx%_@FeVnHYAS z)WY}V{zl%7iVVfg!}9gdJ;|j^GdR|iG$_8zX>gRtlryZcQy&n9xV{*_3OewSm7SmA z5!`F**XFAlbc+}zWC2On*W;%^2N+q;`I%Lf%lOJqnP)-$@WFF|G-jhj;6hHLfXdVpOU?Voxw-;! zC+3c75hApKvpJdyI&J@4I=GXV3Nu(&V5}>%6%x#DVBG<`iEo=Rt;=~ig*N>CvM+!^ z39b?;4-zpQ(&BmLoM8YB=cg+J=PBR@6R`Zu%^L$$I9L?i&!_?ZXs7QMW@#1ofCVlceW5{abJfKgRF}>^)9Z820gq#ey`OryS zmMbl$awFdItEJmNXBpm-yFIAO7$TrVcv~CaA4VNJy5kA+`-M@Uqa5xaaV@FRkoSF~ zp%)IAaqgpwdK2CP-oxLb_qkAGq$-0-`x-Ukqi!7^a1&A@ARf9GKB5+=C%-&JvWweT zIM6aQk&}E!OZYmI{-3e86C1iLPSsO^7b9&53xz5Hfi)FoOsN9=UBs-Q6EF~@`!w}a4;LT%*T20_1=|ql}YLd zsSwU95>4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aty}wm>JI);UW9V&blA^dK#5uZ~rkc}J#6%FDr`m+WQkAIB)Xk^s&Jp_O7 zf)yKje7$KFx)ikXN>~xjs{qcte*U)iQKX2o*u;mE;;81~cR(CsFD^`IxwV7BpE!X}@1g^lUHka_cSF(vzhq!- y7`u7zO^z{k(`r@`7k8!q|0BIkSKE)-wfKVHUGiGLi9@@e5)eCU2jWA#7wvzy2Hw>G literal 0 HcmV?d00001 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}{