Categories
Tools

Pretty Printing Your Source Code

A picture is worth a thousand words, but how do you include source code in a presentation? By text or by image?

Nick Hodges asked about this on Facebook the other day.

Here are some of the suggestions from the community (with my commentary), followed by a few of my suggestions.

  • Robert Love suggested Slides.com – it is a paid web based presentation service centered around web standards. It includes built in features for making your code snippets look nice. Pro: Includes the code as text. Con: One more monthly fee (there is a free plan).
  • Glenn Dufke suggested pasting the code with Syntax Highlighting preserved – By default the RAD Studio/Delphi IDE doesn’t maintain this, but the GExperts IDE Plugin has a Source Code Export expert (I used to use this). I’m sure there are others (CnPack maybe?)
Source Export
GExperts Source Export Export
  • David Schwartz suggested just doing a screenshot from the IDE – this preserves your artistic view of how you have your IDE configured. Downside is the code can’t be easily extracted from the slides . . .
  • Bruce McGee suggested reveal.js – I’ve not used it yet, but it is a full web standard presentation framework, and looks promising. It uses highlight.js for the syntax highlighting, which I have used. With support for 185 languages, it has you covered. I’ll certainly be checking that one out. Thanks Bruce!

Now for my suggestions. In the past I’ve used the rich export options like Glenn suggested, colorized the text by hand, or used an intermediary like Notepad++, etc. But here are some options specifically around creating code screenshots.

Greenshot – is my current preferred desktop screenshot tool for pulling images directly from the IDE. It includes a nice editor for your screenshots too, so you can quickly annotate them, blur things out, etc.

Greenshot screen shot image editor

Carbon.now.sh is a web page that takes your code and converts it into a nice image with a macOS style window. There are a few customization options. If you embed it or share it via URL then it provides both the source code and the preview. It doesn’t list Delphi as a language, but the Pascal support is close enough.

Sample from Carbon.now.sh

Codeimg.io is similar to Carbon, but has more configuration options. The best part is that you can use templates sized exactly for different social media platforms. A lot more customization options, including both Windows and macOS window styles. It doesn’t appear to offer a share by URL or embed option, and only does the image generation. For some reason it defaults to a JPG instead of a PNG for the image though (also supports SVG). Newer addition and still in beta.

Codeimg.io

src2img is a no-nonsense straightforward converter that turns out Source into a PNG file. Just select language (auto detects Delphi) and style. It is based on highlight.js and the source is on GitHub. Doesn’t offer a link share, just image download.

Instacode is the Instagram of the bunch, with image filters like tilt shift and 3D rotation. Directly supports Delphi language, and you can share via a URL that allows someone to access the code and remix the image. Even has wallpaper generator.

Image result for photoshop logo

Lastly, if you have some Photoshop skills (or can follow tutorials like I do) then you can make your own. This is a combination of screenshots, with perspective warps, a few filters, background images, etc.

Did I mention CodeRage 2019 is coming soon?

How do you pretty print your source code? Which of the above is your favorite, or what did I miss?