CT_from_Programmers.scala icon indicating copy to clipboard operation
CT_from_Programmers.scala copied to clipboard

Integrate with PDF gen somehow?

Open tpolecat opened this issue 6 years ago • 19 comments

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.

tpolecat avatar Sep 30 '17 15:09 tpolecat

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!

hmemcpy avatar Sep 30 '17 15:09 hmemcpy

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?

hmemcpy avatar Oct 13 '17 13:10 hmemcpy

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?

kailuowang avatar Oct 13 '17 14:10 kailuowang

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)

SystemFw avatar Oct 13 '17 15:10 SystemFw

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.

kailuowang avatar Mar 15 '18 18:03 kailuowang

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.

bbarker avatar Mar 15 '18 18:03 bbarker

@Zelenya just finished translation for all sections. This is exciting.

kailuowang avatar Jun 12 '18 19:06 kailuowang

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.

sake92 avatar Jun 13 '18 07:06 sake92

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

hmemcpy avatar Jul 15 '18 09:07 hmemcpy

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.

markus1189 avatar Jul 15 '18 17:07 markus1189

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!

hmemcpy avatar Jul 15 '18 19:07 hmemcpy

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 avatar Jul 30 '18 11:07 hmemcpy

@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.

kailuowang avatar Aug 07 '18 15:08 kailuowang

Little code to parse the tut file into multiple files

Zelenya avatar Sep 02 '18 17:09 Zelenya

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...

hmemcpy avatar Sep 18 '18 12:09 hmemcpy

That's exciting news @hmemcpy thanks!

kailuowang avatar Sep 18 '18 14:09 kailuowang

Playing with styles :) image

hmemcpy avatar Sep 22 '18 08:09 hmemcpy

Eek :) image

hmemcpy avatar Sep 27 '18 06:09 hmemcpy

First PDF (pre) release is available! https://github.com/hmemcpy/milewski-ctfp-pdf/releases/tag/v1.1-rc

hmemcpy avatar Nov 25 '18 05:11 hmemcpy