summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/naive-ebnf/naive-ebnf.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/naive-ebnf/naive-ebnf.dtx')
-rw-r--r--macros/latex/contrib/naive-ebnf/naive-ebnf.dtx32
1 files changed, 26 insertions, 6 deletions
diff --git a/macros/latex/contrib/naive-ebnf/naive-ebnf.dtx b/macros/latex/contrib/naive-ebnf/naive-ebnf.dtx
index 6213cf6d52..cdd047a30f 100644
--- a/macros/latex/contrib/naive-ebnf/naive-ebnf.dtx
+++ b/macros/latex/contrib/naive-ebnf/naive-ebnf.dtx
@@ -50,7 +50,7 @@
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{naive-ebnf}
%<*package>
-[2023-01-29 0.0.2 EBNF in Plain Text]
+[2023-01-30 0.0.3 EBNF in Plain Text]
%</package>
%<*driver>
\documentclass{ltxdoc}
@@ -81,7 +81,7 @@
%
% \section{Introduction}
%
-% This package helps render a
+% This package helps render an
% \href{https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form}{Extended Backus-Naur Form}
% using plain text notation:
% \begin{docshot}
@@ -97,6 +97,8 @@
% \end{document}
% \end{docshot}
+% \DescribeMacro{ebnf}
+% The |ebnf| environment \emph{doesn't} add any formatting to the paragraph, but only replaces the plain text symbols, such as ``|:=|'' and ``|<Var>|'' with proper \LaTeX{} commands.
% The following syntax is understood inside the |ebnf| environment:
% \begin{itemize}
% \item |:=| separates the left-hand side from the right-hand side of the production rule;
@@ -133,6 +135,19 @@
% with \terminal{)}.
% \end{document}
% \end{docshot}
+% It's possible to use them in math-mode too, for example:
+% \docshotOptions{firstline=6,lastline=8}
+% \begin{docshot}
+% \documentclass{article}
+% \pagestyle{empty}
+% \usepackage[paperwidth=3in]{geometry}
+% \usepackage{naive-ebnf}
+% \begin{document}
+% If $\terminal{(} f_1 \nonterminal{Var}
+% \terminal{)}$ is always true, then
+% $f_1$ is a tautology.
+% \end{document}
+% \end{docshot}
% \section{Package Options}
@@ -187,12 +202,15 @@
% \begin{macro}{\terminal}
% \changes{0.0.2}{2023/01/29}{New command \texttt{\char`\\terminal} added, to enable rendering terminal symbols outside of the \texttt{ebnf} environment.}
+% \changes{0.0.3}{2023/01/30}{Quotes fixed in both text and math modes.}
% Then, we a command to render a single terminal:
% \begin{macrocode}
\makeatletter
-\newcommand\terminal[1]{%
+\newcommand\terminal[1]{{%
\relax\ifmmode\else\ttfamily\fi%
- \ebnf@color{gray}{"}#1\ebnf@color{gray}{"}}
+ \ebnf@color{gray}{\relax\ifmmode\textsf{``}\else{\sffamily``}\fi}%
+ #1%
+ \ebnf@color{gray}{\relax\ifmmode\textsf{''}\else{\sffamily''}\fi}}}
\makeatother
% \end{macrocode}
% \end{macro}
@@ -202,8 +220,10 @@
% Then, we a command to render a single non-terminal:
% \begin{macrocode}
\makeatletter
-\newcommand\nonterminal[1]
- {\(\ebnf@color{gray}{\langle}\textsf{#1}\ebnf@color{gray}{\rangle}\)}
+\newcommand\nonterminal[1]{%
+ \ebnf@color{gray}{\relax\ifmmode\langle\else\(\langle\)\fi}%
+ \relax\ifmmode\textsf{#1}\else{\sffamily#1}\fi%
+ \ebnf@color{gray}{\relax\ifmmode\rangle\else\(\rangle\)\fi}}
\makeatother
% \end{macrocode}
% \end{macro}