Skip to content

Instantly share code, notes, and snippets.

@yangzhixuan
Created April 7, 2024 22:16
Show Gist options
  • Save yangzhixuan/5e9074f8007da31654c407a19b445f0a to your computer and use it in GitHub Desktop.
Save yangzhixuan/5e9074f8007da31654c407a19b445f0a to your computer and use it in GitHub Desktop.
Using lhs2tex code in mathmode
\documentclass{article}
\usepackage{amsmath}
%include polycode.fmt
\newenvironment{autohscode}%
{\relax\ifmmode\expandafter\pmboxed\else\expandafter\plainhscode\fi}%
{\relax\ifmmode\expandafter\endpmboxed\else\expandafter\endplainhscode\fi}
\sethscode{autohscode}
\begin{document}
\begin{gather*}
\int_x{\left(
\begin{code}
foldr f z [] = z
foldr f z (x:xs) = f x (foldr f z xs)
\end{code}
\right)}
= \mathit{nonsense}
\end{gather*}
In text mode:
\begin{code}
foldl f z [] = z
foldl f z (x:xs) = foldl f (f z x) xs
\end{code}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment