I started this project on June 20, 2023.
This project generates LaTeX files that display “Hello World” programs in various languages on a poster. The Python script reads program files, each specifying a language name and code, then uses the “minted” package for syntax highlighting. The result is a multi-column LaTeX document that showcases each language's code snippet. Dependencies and Python environment details are defined in pyproject.toml
and .python-version
.
Each "Hello World" program outputs "Hello World" and a newline (i.e. \n
) to standard output (stdout).
- Make sure you've got the necessary fonts installed on your system
(in a place where XeLaTeX can find them).
See
poster_starter.tex
to see which fonts it references. - Do
uv run generate_tex.py
. That will generate some.tex
files, each in its own directory (because problems arose when they were all in the same directory). - Use XeLaTeX to compile the
.tex
files to PDF, e.g.
xelatex -synctex=1 -interaction=nonstopmode hw_poster_v1.tex
You need to run that command at least two times. I usually do it three times.
You could also use an editor like TeXstudio or TeXworks to do that.
Note: In the past, you had to call XeLaTeX with the -shell-escape
option,
but with newer versions of minted that's no longer necessary.
For more information, see the minted documentation; you can get that from
CTAN.
I use uv
to do Python version and environment management.
.python-version
specifies the Python version to use.pyproject.toml
defines the project name, version, package dependencies, and more.
To add a new Python package to the project, use uv add <package-name>
.
To upgrade a specific Python package, use uv lock --upgrade-package <package-name>
.
To update the virtual environment (in .venv/
), use uv sync
.
(That will also create the virtual environment if it doesn't exist yet.)
To generate the .tex
files, do:
uv run generate_tex.py
That runs generate_tex.py
in the virtual environment, with the right version of Python.
At first, I tried the "listings" package, but then I switched to the newer "minted" package, which uses the Python Pygments package.
-
It must be a programming language where one can write a program that, when run, outputs "Hello, world!" (sans quotes) to standard output (stdout).
-
Stick with "high level" languages, i.e. no assembly or machine code.
-
I wanted the top languages in use today (by some measure). Used the 2023 Stack Overflow Survey (all respondents): https://survey.stackoverflow.co/2023/#section-most-popular-technologies-programming-scripting-and-markup-languages See numbered list below.
-
I wanted a broad selection of programming languages from across computer programming history.
- COBOL (two examples, old and modern), Fortran (two examples), ALGOL, Smalltalk, BASIC, Erlang
-
I wanted to illustrate different types of programming languages, so:
- APL, Common Lisp, Swift
-
Don't forget Brainf**k, because it's funny.
-
I also wanted to include some new-ish / interesting languages:
- Nim, Zig, Mojo
- JavaScript
- HTML/CSS --- SKIP
- Python
- SQL --- SKIP
- TypeScript
- Bash/Shell
- Java
- C#
- C++
- C
- PHP
- PowerShell
- Go
- Rust
- Kotlin
- Ruby
- Lua
- Dart
- Assembly --- SKIP, Assembly is not just one language!
- Swift
- R
- Visual Basic .NET
- MATLAB --- SKIP, not intended for making console apps
Another consideration is that there should be a lexer for the language in the Pygments package. The Pygments documentation lists all the (currently) available lexers at:
https://pygments.org/docs/lexers/
Idea 1: Use the default font used by Visual Studio Code, which is currently the most popular IDE. The following answer on Stack Overflow https://stackoverflow.com/a/45931531/8193159 led me to the current source code (on the main branch):
const DEFAULT_WINDOWS_FONT_FAMILY = 'Consolas, \'Courier New\', monospace';
const DEFAULT_MAC_FONT_FAMILY = 'Menlo, Monaco, \'Courier New\', monospace';
const DEFAULT_LINUX_FONT_FAMILY = '\'Droid Sans Mono\', \'monospace\', monospace';
(That is as of June 2023.)
Idea 2: Maybe those fonts look nice on screens (in IDEs), but I'm making a poster for print, so maybe choose a font that looks good in print? For example, we'd like the number 0 to have a dot or a slash through it, to distinguish it from the letter O. Droid Sans Mono has no dot or slash in the zero. Noto Sans Mono has a slash through the zero, so use it. And use the Noto Sans Display font for non-code text, so there is some consistency.
Bonus: The "minted" package works really well with Noto Sans Mono; it's able to make some tokens more bold than others.
To get a list of all available minted styles, do pygmentize -L styles
Note: You might have to install the Python Pygments package first before you can run that command.
I tried many styles until I found some that I liked.
I currently have:
- light theme, grayscale
- dark theme, grayscale