From 73a1d8782de0159a4443f4b5627df0122ec9d9f1 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 15 Nov 2021 21:10:04 +0000 Subject: formal-grammar (15nov21) git-svn-id: svn://tug.org/texlive/trunk@61062 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/latex/formal-grammar/formal-grammar.sty | 54 +++++++++++----------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'Master/texmf-dist/tex/latex/formal-grammar') diff --git a/Master/texmf-dist/tex/latex/formal-grammar/formal-grammar.sty b/Master/texmf-dist/tex/latex/formal-grammar/formal-grammar.sty index 90eaa407da6..990b3e5a4d3 100644 --- a/Master/texmf-dist/tex/latex/formal-grammar/formal-grammar.sty +++ b/Master/texmf-dist/tex/latex/formal-grammar/formal-grammar.sty @@ -20,9 +20,9 @@ %% \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{formal-grammar}[2021/11/10 v1.0 A package to typeset formal grammars] +\ProvidesPackage{formal-grammar}[2021/11/15 v1.1 A package to typeset formal grammars] \RequirePackage{xparse} -\RequirePackage{float} +\RequirePackage{newfloat} \RequirePackage{xcolor} \RequirePackage{colortbl} \RequirePackage{array} @@ -30,49 +30,44 @@ %% \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} +\DeclareFloatingEnvironment[ +name=Grammar, +listname={List of Grammars}, +placement=tbhp, +]{floatgrammar} %% Taken from https://tex.stackexchange.com/a/26364/107341 -\newcommand*{\@rowstyle}{} +\newcommand*{\formal@rowstyle}{} \newcommand*{\rowstyle}[1]{% sets the style of the next row - \gdef\@rowstyle{#1}% - \@rowstyle\ignorespaces% + \gdef\formal@rowstyle{#1}% + \formal@rowstyle\ignorespaces% } -\newcolumntype{=}{% resets the row style - >{\gdef\@rowstyle{}}% +\newcolumntype{\formal@reset}{% resets the row style + >{\gdef\formal@rowstyle{}}% } -\newcolumntype{+}{% adds the current row style to the next column - >{\@rowstyle}% +\newcolumntype{\formal@add}{% adds the current row style to the next column + >{\formal@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} +\NewDocumentEnvironment{grammar} {o O{p} o} { -\IfNoValueTF{#1} { -}{ -\IfNoValueTF{#2}{ -\begin{floatgrammar}[p] -} { +\IfNoValueF{#1}{ \begin{floatgrammar}[#2] -} \centering } -\begin{tabular}{=l +r +l +l} +\begin{tabular}{\formal@reset l \formal@add r \formal@add l \formal@add l} }{ \end{tabular} -\IfNoValueTF{#1} { -\linebreak -} { +\IfNoValueF{#1}{ \caption{#1} -\IfNoValueTF{#3}{ -} { +\IfNoValueF{#3}{ \label{#3} } \end{floatgrammar} @@ -80,8 +75,8 @@ } \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{\firstcase}[3]{\(\mathcal{#1}\) & \(\formal@Coloneqq\) & \(#2\) & {\itshape \color{gray!90!black} #3}\\} +\newcommand{\firstcasesubtil}[3]{#1 & \(\formal@Coloneqq\) & \(#2\) & {\itshape \color{gray!90!black} #3}\\} \newcommand{\otherform}[2]{& \(|\) & \(#1\) & {\itshape \color{gray!90!black} #2}\\} @@ -96,6 +91,13 @@ \newcommand{\lochighlight}[1]{{\color{red} #1}} \newcommand{\downplay}[0]{\rowstyle{\color{white!80!black}}} +\AtBeginDocument{% +\ifdefined\Coloneqq +\let\formal@Coloneqq\Coloneqq +\else +\newcommand{\formal@Coloneqq}{::=} +\fi +} \endinput %% %% End of file `formal-grammar.sty'. -- cgit v1.2.3