Skip to content

Instantly share code, notes, and snippets.

@Chubek
Last active September 24, 2024 08:32
Show Gist options
  • Save Chubek/1f191c859e9a6af45a1d34a752b31e05 to your computer and use it in GitHub Desktop.
Save Chubek/1f191c859e9a6af45a1d34a752b31e05 to your computer and use it in GitHub Desktop.
SimpleTRS: A LaTeX Package for typesetting Term-rewriting systems!

I am writing a literate program (with NoWEB), a toolset for Lua that happens to include a Partial evaluator, a Meta-tracer, a pretty-printer etc.

In the appendix, I provide extra information like Lua's BNF grammar (using SimpleBNF) and the Term-rewriting rules for Partial evaluation.

I did not find a LaTex package intended for typesetting TRS, so (with some help from GPT), I created simpletrs.sty (below), which povides the simpletrs package. It's a package for typesetting Term-rewriting rules.

It's a quite simple package. Providse 4 commands:

1- \trule for typesetting normal TRS rules;

2- \truleif for adding conditionals;

3- \ctrule for contextual TRS;

4- \ntrule for named (labeld) TRS;

It's very, very simple to use! Here's an example:

\documentclass{article}
\usepackage{simpletrs}

\begin{document}

% Simple term-rewriting system
\trule{f(x, y)}{g(x, y)}

% Conditional rewriting
\truleif{f(x)}{g(x)}{x > 0}

% Contextual rule
\ctrule{C}{f(x)}{g(x)}

% Named rule
\ntrule{\alpha}{f(x, y)}{g(x, y)}

\end{document}

Put this in the same directory as your LaTeX file.

My contacts are in my Github frontpage, where you can find lots of other work. Link. If you need any help, lemme know.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{simpletrs}[2024/9/15 A simple package for typesetting Term-rewriting systems]
\RequirePackage{amsmath}
\RequirePackage{xparse}
% Simple command for basic term-rewriting rules
\NewDocumentCommand{\trule}{m m}{
\[ #1 \to #2 \]
}
% For conditional term-rewriting rules
\NewDocumentCommand{\truleif}{m m m}{
\[ #1 \to #2 \quad \text{if} \quad #3 \]
}
% For contextual term-rewriting rules
\NewDocumentCommand{\ctrule}{m m m}{
\[ #1[#2] \to #1[#3] \]
}
% For named term-rewriting rules
\NewDocumentCommand{\ntrule}{m m m}{
\[ #1 \colon \quad #2 \to #3 \]
}
\newcommand{\relarrow}{\to}
\endinput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment