BSD-3-Clause licensed by Alice Rixte
Maintained by [email protected]
This version can be pinned in stack with:ghci4luatex-0.1.2@sha256:5dd3547b2450a6b755096fc597de5965a6195e5c63728e9ddbcc75cd049d8df1,2548

Module documentation for 0.1.2

ghci4luatex : a GHCi session in LuaTeX

Haskell BSD3 License Hackage Nightly LTS

Run a GHCi session within a LaTeX document :

  • The ghci environment evaluates Haskell code without printing anything :
\begin{ghci}
x :: Int
x = 4

y :: Int
y = 5
\end{ghci}
  • The hask command evaluates any GHCi command and prints in Haskell what GHCi printed :
The sum of $x$ and $y$ when $x = \hask{x}$ and $y = \hask{y}$ is $\hask{x + y}$.

Documentation

You can find the full pdf documentation in here

Quick start

  1. Install haskell and cabal or stack

  2. Install ghci4luatexby running either

cabal install ghci4luatex

or

stack install ghci4luatex
  1. Copy ghci.sty and dkjson.lua in the folder containing a main.tex file with the following content :
\documentclass{article}

\usepackage{ghci}

\begin{document}

\begin{ghci}
x :: Int
x = 5

y :: Int
y = 6
\end{ghci}

The sum of $x$ and $y$ when $x = \hask{x}$ and $y = \hask{y}$ is $\hask{x + y}$.

\end{document}
  1. Within that folder, run the ghci4luatex server :
ghci4luatex
  1. Open another shell and compile with luatex :
latexmk -shell-escape -lualatex main.tex

Use any Haskell library

HaTeX


\begin{ghci}
:set -XOverloadedStrings
\end{ghci}

\begin{ghci}
import Text.LaTeX
import Text.LaTeX.Base.Pretty

printTex = putStrLn . prettyLaTeX
\end{ghci}

\hask{printTex (section "A section using HaTeX")}

Diagrams


\usepackage{svg}

\begin{ghci}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleContexts          #-}
{-# LANGUAGE TypeFamilies              #-}

import Diagrams.Prelude hiding (section)
import Diagrams.Backend.SVG

myDia = circle 1 # fc green
\end{ghci}

\begin{ghci}
  renderSVG "myDia.svg" (dims2D 400 300) myDia
\end{ghci}

\begin{figure}[h]
  \centering
  \includesvg[width=0.2\textwidth]{myDia}
  \caption{A circle using Diagrams}
\end{figure}

Workflow with lhs2tex in Visual Studio Code with LaTeX workshop

In this repository, you will find an example that contains a Makefile.

You can take inspiration from this to use make in a LateX Workshop receipe :

  1. Install the LaTeX Workshop extension.
  2. In settings.json , add the following
"latex-workshop.latex.recipes": [
        {
            "name": "ghci4luatex",
            "tools": [
                "mklatex"
            ]
        }
    ],
"latex-workshop.latex.outDir": "./build/",
"latex-workshop.latex.tools": [
        {
            "name": "mklatex",
            "command": "make",
            "args": [
                "latex",
                "main=%DOCFILE%"
            ],
            "env": {}
        }
    ],

Changes

Changelog for ghci4luatex

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to the Haskell Package Versioning Policy.

0.0 - 2025-07-04

  • A server that executes GHCi commands and memoizes the results
  • A LuaTeX package that sends commands to that server

0.1 - 2025-07-07

  • Fix missing test for cabal install ghci4luatex

0.1.1 - 2025-07-10

  • Bump Quickcheck version for stackage upload

0.1.2 - 2025-07-10

  • Windows compatibility
  • Loosen lower bounds