4

I wanted to know which standard symbol should be used as a delimiter when recursively defining a (formal) language, such as this fragment of arithmetic expressions :

X ::= 0 | 1 | X+X | X*X |

I use |, but I have to put by hand the spaces between the bar and the left and right symbols. Moreover, in other documents or papers, the bar looks like bigger than the standard one, so I wondered if there was a particular symbol or a best practice.

Edit : Here a short version of the kind of code I'm using right now :

\documentclass[11pt,letterpaper]{report}

\usepackage{amssymb,amsmath,amsfonts,amsxtra,amsthm}
% etc...

\begin{document}

% ...

\[ A ::= 0 | 1 | A+A | A \times A \]

%...

\end{document}

While I'm looking for spacing more like the definition at page 4, around the end of 1.1 in http://perso.ens-lyon.fr/olivier.laurent/folgames.pdf for example. I think its called Backus-Naur Form or something like that.

  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out how best to help when we have compilable code, starting with \documentclass{...} and ending with \end{document}. Thanks :-) – darthbith Jul 14 '14 at 14:27
  • 2
    I guess it's \mid, but probably you want to define \newcommand{\bnfor}{\mid} so you can easily change your mind. – egreg Jul 14 '14 at 15:23
  • @egreg I thought |, \vert and \mid were aliases but indeed \mid seems to render better ! I'll do with this for now, thanks. – yago Jul 14 '14 at 15:44
  • \mid prints the same symbol as \vert or | (these two are the same), but treats it as a relation symbol. – egreg Jul 14 '14 at 15:47
3

Those bars look like relation symbols, so \mid should be the choice.

However, defining an own command for it can surely be considered best practice: you can easily change the appearance of the symbol by just changing its definition. Here's an example, where the \renewcommand serves for the purpose of showing how you can modify the symbol without changing the document code.

\documentclass[11pt,letterpaper]{report}
\usepackage{amsmath,amssymb,amsthm}

\usepackage{bm} % for the second version

\newcommand{\bnfor}{\mid}

\begin{document}

\[ A ::= 0 \bnfor 1 \bnfor A+A \bnfor A \times A \]

\renewcommand{\bnfor}{\mathrel{\big\bracevert}}

\[ A ::= 0 \bnfor 1 \bnfor A+A \bnfor A \times A \]

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.