%% %% This is file `formal-grammar.sty', %% generated with the docstrip utility. %% %% The original source files were: %% %% formal-grammar.dtx (with options: `package') %% This is a generated file. %% Copyright (C) 2021 by Martin Vassor %% %% This file may be distributed and/or modified under the %% conditions of the LaTeX Project Public License, either %% version 1.3 of this license or (at your option) any later %% version. The latest version of this license is in: %% %% http://www.latex-project.org/lppl.txt %% %% and version 1.3 or later is part of all distributions of %% LaTeX version 2005/12/01 or later. %% \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{formal-grammar}[2021/11/10 v1.0 A package to typeset formal grammars] \RequirePackage{xparse} \RequirePackage{float} \RequirePackage{xcolor} \RequirePackage{colortbl} \RequirePackage{array} \definecolor{LightCyan}{rgb}{0.8,1,1} %% \begin{abstract} %% The \textsf{formal-grammar} package provides commands to typeset formal grammars. %% \end{abstract} \newfloat{floatgrammar}{t b h p}{.gram} \floatname{floatgrammar}{Grammar} %% Taken from https://tex.stackexchange.com/a/26364/107341 \newcommand*{\@rowstyle}{} \newcommand*{\rowstyle}[1]{% sets the style of the next row \gdef\@rowstyle{#1}% \@rowstyle\ignorespaces% } \newcolumntype{=}{% resets the row style >{\gdef\@rowstyle{}}% } \newcolumntype{+}{% adds the current row style to the next column >{\@rowstyle}% } %% End of stackexchange \ExplSyntaxOn %% 1st argument: caption (makes it float) %% 2nd argument: positionning option (`p` by default) %% 3rd argument: label \NewDocumentEnvironment{grammar} {o o o} { \IfNoValueTF{#1} { }{ \IfNoValueTF{#2}{ \begin{floatgrammar}[p] } { \begin{floatgrammar}[#2] } \centering } \begin{tabular}{=l +r +l +l} }{ \end{tabular} \IfNoValueTF{#1} { \linebreak } { \caption{#1} \IfNoValueTF{#3}{ } { \label{#3} } \end{floatgrammar} } } \ExplSyntaxOff \newcommand{\firstcase}[3]{\(\mathcal{#1}\) & \(::=\) & \(#2\) & {\itshape \color{gray!90!black} #3}\\} \newcommand{\firstcasesubtil}[3]{#1 & \(::=\) & \(#2\) & {\itshape \color{gray!90!black} #3}\\} \newcommand{\otherform}[2]{& \(|\) & \(#1\) & {\itshape \color{gray!90!black} #2}\\} \newcommand{\nonterm}[1]{\mathcal{#1}} \newcommand{\nontermsubtil}[1]{#1} \newcommand{\gralt}[0]{\quad |\quad } \newcommand{\highlight}[0]{\rowcolor{LightCyan}} \newcommand{\lochighlight}[1]{{\color{red} #1}} \newcommand{\downplay}[0]{\rowstyle{\color{white!80!black}}} \endinput %% %% End of file `formal-grammar.sty'.