texlive[61062] Master/texmf-dist: formal-grammar (15nov21)
commits+karl at tug.org
commits+karl at tug.org
Mon Nov 15 22:10:05 CET 2021
Revision: 61062
http://tug.org/svn/texlive?view=revision&revision=61062
Author: karl
Date: 2021-11-15 22:10:04 +0100 (Mon, 15 Nov 2021)
Log Message:
-----------
formal-grammar (15nov21)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/latex/formal-grammar/README.md
trunk/Master/texmf-dist/doc/latex/formal-grammar/formal-grammar.pdf
trunk/Master/texmf-dist/source/latex/formal-grammar/formal-grammar.dtx
trunk/Master/texmf-dist/tex/latex/formal-grammar/formal-grammar.sty
Modified: trunk/Master/texmf-dist/doc/latex/formal-grammar/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/formal-grammar/README.md 2021-11-15 21:09:49 UTC (rev 61061)
+++ trunk/Master/texmf-dist/doc/latex/formal-grammar/README.md 2021-11-15 21:10:04 UTC (rev 61062)
@@ -17,6 +17,12 @@
This package is provided under the terms of the LaTeX Project Public License,
version 1.3 or later.
+# Author
+
+The initial author of this package is Martin Vassor.
+
+Thanks to Enrico Gregorio (egreg) for suggesting improvements.
+
# See also
- [**simplebnf**](https://www.ctan.org/pkg/simplebnf): this package provides an
Modified: trunk/Master/texmf-dist/doc/latex/formal-grammar/formal-grammar.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/source/latex/formal-grammar/formal-grammar.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/formal-grammar/formal-grammar.dtx 2021-11-15 21:09:49 UTC (rev 61061)
+++ trunk/Master/texmf-dist/source/latex/formal-grammar/formal-grammar.dtx 2021-11-15 21:10:04 UTC (rev 61062)
@@ -16,9 +16,9 @@
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}
-%<package>\ProvidesPackage{formal-grammar}[2021/11/10 v1.0 A package to typeset formal grammars]
+%<package>\ProvidesPackage{formal-grammar}[2021/11/15 v1.1 A package to typeset formal grammars]
%<package>\RequirePackage{xparse}
-%<package>\RequirePackage{float}
+%<package>\RequirePackage{newfloat}
%<package>\RequirePackage{xcolor}
%<package>\RequirePackage{colortbl}
%<package>\RequirePackage{array}
@@ -26,6 +26,7 @@
%<*driver>
\documentclass{ltxdoc}
\usepackage{formal-grammar}
+\usepackage[hidelinks]{hyperref}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
@@ -35,7 +36,7 @@
%</driver>
% \fi
%
-% \CheckSum{83}
+% \CheckSum{97}
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
@@ -54,7 +55,8 @@
% Right brace \} Tilde \~}
%
%
-% \changes{v1.0}{2021/11/21}{Initial version for publication}
+% \changes{v1.1}{2021/11/15}{Use Coloneqq if defined, internal changes, typos}
+% \changes{v1.0}{2021/11/10}{Initial version for publication}
%
% \GetFileInfo{formal-grammar.sty}
%
@@ -75,7 +77,7 @@
% \section{Introduction}
%
% This package provides a new environment (|grammar|) and associated commands to
-% typeset BNF grammars. It allows to easily write formal grammars, for instance
+% typeset BNF grammars. It allows to easily write formal grammars. For instance,
% the syntax of the \(\lambda\) calculus is given in Grammar~\ref{gr:lambda}.
%
%\begin{grammar}[\(\lambda\) calculus syntax][][gr:lambda]
@@ -99,7 +101,7 @@
% optional arguments: the first one is a possible caption; the second is a
% positionning option; and the third is a label.
%
-% If none of the optional arguments is provided, the grammar is inlined (i.e.
+% If none of the optional arguments are provided, the grammar is inlined (i.e.
% not in a float environment. If the first argument is set (the optional
% caption), the grammar is typeset in a float, captionned with the provided
% caption.
@@ -131,7 +133,7 @@
% \otherform{\{\}}{Curly brackets}
% \end{grammar}
%
-% \paragraph{Referencing non-terminals}
+% \paragraph{Referencing non-terminals.}
%
% \DescribeMacro{\nonterm}
% This allows you to typeset a symbol as a non-terminal. In the current version,
@@ -167,8 +169,8 @@
% \begin{verbatim}
% \firstcase{B}{(\nonterm{B})\gralt \{\nonterm{B}\}}{Nested parenthesis or brackets}
% \end{verbatim}
-% \paragraph{Subtle typesetting of non-terminals}
-% Since nonterminal are, by default, typeset using \verb+\mathcal+, it can lead
+% \paragraph{Subtle typesetting of non-terminals.}
+% Since nonterminals are, by default, typeset using \verb+\mathcal+, it can lead
% to the usual issues of \verb+\mathcal+ (typically, for lowercases). Therefore, we provide \emph{subtle}
% variants of |\firstcase| and |\nonterm|, in which the non-terminal symbol is
% not typeset (i.e. as the user, you have to typeset it manually).
@@ -182,7 +184,7 @@
% \verb+\(\nontermsubtil{\nonterm{C}_1}\)+
%
% \DescribeMacro{\firstcasesubtil}
-% The subtil variant of |\firstcase|. Works similarly, except that the
+% The subtle variant of |\firstcase|. It works similarly, except that the
% non-terminal (i.e. the first argument) is not embedded in a \verb+\mathcal+
% macro. For instance, the \(\nontermsubtil{\nonterm{C}_1}\) in
% Grammar~\ref{gr:advanced_grammar} is typeset with the following command:
@@ -190,8 +192,8 @@
% \firstcasesubtil{\(\nonterm{C}_1\)}{\nonterm{B}}{Example of subtil non-terminal}
% \end{verbatim}
%
-% \paragraph{Highlighting and downplaying variants}
-% Three commands are provided to highlight or downplay some part of a grammar.
+% \paragraph{Highlighting and downplaying variants.}
+% Three commands are provided to highlight or downplay some parts of a grammar.
% |\highlight| highlights a whole line, |\loghighlight| highlights a part of a
% line, while |\downplay| downplays a line.
%
@@ -219,6 +221,15 @@
% \gralt \nonterm{A}}{Important item}
% \end{verbatim}
%
+% \paragraph{Customizing the \(::=\) symbol.}
+% At the end of the preamble (i.e. before the \verb+\begin{document}+), the
+% package checks if a command \verb+\Coloneqq+ is defined. If that is the case,
+% it is used instead of \(::=\). Typically, packages
+% \href{https://www.ctan.org/pkg/mathtools}{mathtools},
+% \href{https://www.ctan.org/pkg/txfonts}{txfonts} and
+% \href{https://www.ctan.org/pkg/pxfonts}{pxfonts} define this command, but you
+% can also define it manually if you use the symbol elsewhere in the document.
+%
% \StopEventually{\PrintIndex}
%
% \section{Implementation}
@@ -227,8 +238,11 @@
% This is a new float that contains floating grammars. This is needed so that
% they are labeled with 'Grammar'.
% \begin{macrocode}
-\newfloat{floatgrammar}{t b h p}{.gram}
-\floatname{floatgrammar}{Grammar}
+ \DeclareFloatingEnvironment[
+ name=Grammar,
+ listname={List of Grammars},
+ placement=tbhp,
+ ]{floatgrammar}
% \end{macrocode}
% \end{environment}
%
@@ -236,31 +250,34 @@
%% Taken from https://tex.stackexchange.com/a/26364/107341
%\fi
%
-% \begin{macro}{\@rowstyle}
+% \begin{macro}{\formal at rowstyle}
% The default \verb+rowstyle+ is empty.
% \begin{macrocode}
-\newcommand*{\@rowstyle}{}
+\newcommand*{\formal at rowstyle}{}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\rowstyle}
-% An internal command used to set the style of a row. In addition, we add column
+% An command used to set the style of a row. In addition, we add column
% types to reset the style (\verb:=:) and to keep the style from one column to
% the other (\verb:+:).
+% As of today, it is not advised for the user to use \verb+\rowstyle+ to define
+% their own style (i.e.\ I have not tested it), although I hope it will someday
+% be possible.
% \begin{macrocode}
\newcommand*{\rowstyle}[1]{% sets the style of the next row
- \gdef\@rowstyle{#1}%
- \@rowstyle\ignorespaces%
+ \gdef\formal at rowstyle{#1}%
+ \formal at rowstyle\ignorespaces%
}
% \end{macrocode}
% \begin{macrocode}
-\newcolumntype{=}{% resets the row style
- >{\gdef\@rowstyle{}}%
+\newcolumntype{\formal at reset}{% resets the row style
+ >{\gdef\formal at rowstyle{}}%
}
-\newcolumntype{+}{% adds the current row style to the next column
- >{\@rowstyle}%
+\newcolumntype{\formal at add}{% adds the current row style to the next column
+ >{\formal at rowstyle}%
}
% \end{macrocode}
% \end{macro}
@@ -274,33 +291,27 @@
% we embed the grammar into a \verb+floatgrammar+; then if the second argument
% is provided, we use it as the position, (otherwise, we use \verb+p+). Finally,
% if the third argument is provided, we use it as a label.
+% Notice that, if the grammar is not a float (is inline), we do \emph{not}
+% break line before and after the grammar.
% \begin{macrocode}
\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]
- } {
- \begin{floatgrammar}[#2]
- }
+ \IfNoValueF{#1}{
+ \begin{floatgrammar}[#2]
\centering
}
- \begin{tabular}{=l +r +l +l}
+ \begin{tabular}{\formal at reset l \formal at add r \formal at add l \formal at add l}
}{
\end{tabular}
- \IfNoValueTF{#1} {
- \linebreak
- } {
+ \IfNoValueF{#1}{
\caption{#1}
- \IfNoValueTF{#3}{
- } {
+ \IfNoValueF{#3}{
\label{#3}
}
\end{floatgrammar}
@@ -316,7 +327,7 @@
% cell is the rule (it is directly printed, without any modification), and the
% last cell is the description of the rule, in greyish color.
% \begin{macrocode}
-\newcommand{\firstcase}[3]{\(\mathcal{#1}\) & \(::=\) & \(#2\) & {\itshape \color{gray!90!black} #3}\\}
+\newcommand{\firstcase}[3]{\(\mathcal{#1}\) & \(\formal at Coloneqq\) & \(#2\) & {\itshape \color{gray!90!black} #3}\\}
% \end{macrocode}
% \end{macro}
%
@@ -324,7 +335,7 @@
% The |\firstcasesubtil| is implemented similarly to |\firstcase|, except that
% the first argument is not surrounded by \verb+\mathcal+.
% \begin{macrocode}
-\newcommand{\firstcasesubtil}[3]{#1 & \(::=\) & \(#2\) & {\itshape \color{gray!90!black} #3}\\}
+\newcommand{\firstcasesubtil}[3]{#1 & \(\formal at Coloneqq\) & \(#2\) & {\itshape \color{gray!90!black} #3}\\}
% \end{macrocode}
% \end{macro}
@@ -379,6 +390,18 @@
% \end{macrocode}
% \end{macro}
%
+% Finally, we check, at the end of the preamble, if there already exist a
+% \verb+::=+ symbol. We search for a command called \verb+Coloneqq+, e.g.
+% defined in the \href{https://www.ctan.org/pkg/mathtools}{mathtools}.
+% \begin{macrocode}
+\AtBeginDocument{%
+ \ifdefined\Coloneqq
+ \let\formal at Coloneqq\Coloneqq
+ \else
+ \newcommand{\formal at Coloneqq}{::=}
+ \fi
+}
+% \end{macrocode}
%
% \Finale
\endinput
Modified: trunk/Master/texmf-dist/tex/latex/formal-grammar/formal-grammar.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/formal-grammar/formal-grammar.sty 2021-11-15 21:09:49 UTC (rev 61061)
+++ trunk/Master/texmf-dist/tex/latex/formal-grammar/formal-grammar.sty 2021-11-15 21:10:04 UTC (rev 61062)
@@ -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,21 +30,24 @@
%% \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 at rowstyle}{}
\newcommand*{\rowstyle}[1]{% sets the style of the next row
- \gdef\@rowstyle{#1}%
- \@rowstyle\ignorespaces%
+ \gdef\formal at rowstyle{#1}%
+ \formal at rowstyle\ignorespaces%
}
-\newcolumntype{=}{% resets the row style
- >{\gdef\@rowstyle{}}%
+\newcolumntype{\formal at reset}{% resets the row style
+ >{\gdef\formal at rowstyle{}}%
}
-\newcolumntype{+}{% adds the current row style to the next column
- >{\@rowstyle}%
+\newcolumntype{\formal at add}{% adds the current row style to the next column
+ >{\formal at rowstyle}%
}
%% End of stackexchange
\ExplSyntaxOn
@@ -51,28 +54,20 @@
%% 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 at reset l \formal at add r \formal at add l \formal at 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 at Coloneqq\) & \(#2\) & {\itshape \color{gray!90!black} #3}\\}
+\newcommand{\firstcasesubtil}[3]{#1 & \(\formal at 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 at Coloneqq\Coloneqq
+\else
+\newcommand{\formal at Coloneqq}{::=}
+\fi
+}
\endinput
%%
%% End of file `formal-grammar.sty'.
More information about the tex-live-commits
mailing list.