CT_from_Programmers.scala
CT_from_Programmers.scala copied to clipboard
Integrate with PDF gen somehow?
I just ran across this by @hmemcpy … it would be awesome if we could get on that train somehow and have a printable Scala version.
I would love to have a separate version with Scala code :) Would love to help in the effort of making it happen!
This was my first attempt ever at LaTeX, it's incredibly powerful and surprisingly, not at all difficult!
I was thinking of making all source code listings in external .tex files, so they could be included. This would allow to re-use the original .tex structure and substitute the Scala listings. I wonder, can the code be generated in a .tex listings format?
I confess, never used LaTex myself either. Right now the code here is just vanilla scala code, I believe it's jekyll somehow through some other lib to add the syntax highlights. How would that translate to .tex file?
Depends on what Latex
package you're using for syntax highlighting, but it's almost always something like
\begin{sectionName}
code
\end{sectionName}
Where sectionName
depends on the package, as I said above. (plus, it could have an attribute list for things like two-columns listings and so on)
related PR https://github.com/hmemcpy/milewski-ctfp-pdf/pull/117 by @bbarker
Since we also write the Haskell code in our translation markdown files, it should be easy to write a program that replaces the haskell code with matching scala code.
So far all I did in the above PR was to make a Dockerfile that should be able to build the original book, but I like where this thread is going. Unfortunately, though I did write my dissertation in LaTeX, it sort of soured on me and I didn't really keep up with it, and never became an expert - so I'm not quite sure why it is failing.
@Zelenya just finished translation for all sections. This is exciting.
I did PDF generation in my Hepek project (static content generator). Feel free to use/copy this code.
It uses https://github.com/danfickle/openhtmltopdf to parse HTML and generate PDF.
But I needed some JS to load so I can take that HTML snapshot and pass it to openhtmltopdf.
For that I used Selenium's ChromeDriver to talk to Chrome. You need to download chrome webdriver and point to it via webdriver.chrome.driver
env var.
BTW, hepek supports markdown, LaTeX via KaTeX library, code highlighting etc...
Also, plug your own Scala code to do literally anything... 😄
Hope it helps. Ping me if you have any questions.
FYI, @markus1189 just contributed a nix-based build to the PDF that just works beautifully! Perhaps you could use it to fork the book and use it for Scala code :) https://github.com/hmemcpy/milewski-ctfp-pdf/pull/126
I think it would be easiest to use minted
for source code (https://github.com/gpoore/minted/blob/master/source/minted.pdf especially chapter 6 shortcuts is good). I thought this was already used because it was needed in the build, but it doesn't seem to be actually used :thinking:
If @hmemcpy would include snippets using something like the following:
\inputminted[autogobble]{haskell}{source-code/functors.hs}
that would make it very easy to just provide *.scala
files instead.
That's a great suggestion, in fact I wanted to do something like this initially, conditionally (depending on the language) include snippets from files. Unfortunately, I barely knew LaTeX when I started, and to be honest, I almost forgot everything I've learned since :(
I'd be happy to restructure the PDF, and move all (large) code snippets to external files, so they could be easily replaced!
Update: I finally made some tweaks to help me build the PDF on Travis using the exact fonts as my local build on the Mac. So now, the nix script produces the exact PDF :)
Like I said, I would be happy to modify the PDF to extract the code snippets to external file and use minted
to include them. Then, the files could be replaced with the corresponding .scala files (and maybe even conditionally included, without forking the PDF).
Would it be possible (for tut?) to generate individual .scala files from the markdown snippets?
@hmemcpy sorry I missed your message. I think tut output one markdown file per source markdown file. However, it shouldn't be hard to write a little code to parse the file and split it into multiple files one per snippets. Then we just need to define a naming scheme so that these files are interchangable with the haskell ones.
Little code to parse the tut file into multiple files
I started a refactoring branch in the PDF book to load the haskell snippets from external files. I can add a conditional flag to load the scala counterparts. Then, I can generate a "scala edition" easily :) Watch this space...
That's exciting news @hmemcpy thanks!
Playing with styles :)
Eek :)
First PDF (pre) release is available! https://github.com/hmemcpy/milewski-ctfp-pdf/releases/tag/v1.1-rc