3

I'm using the backnaur package to write the BNF of a simple programming language I made. But now I have a fairly long definition and it gives an overflow. I tried adding newlines using \\ but this results in an odd alignment. I've also tried \newline but this doesn't do anything. I can't anything about newlines in the package documentation (http://ctan.sharelatex.com/tex-archive/macros/latex/contrib/backnaur/backnaur.pdf). This is my code:

\documentclass[dutch]{arabart}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
\usepackage{amsmath}
\usepackage{amsthm}

\makeatletter
\numberwithin{equation}{section}
\numberwithin{figure}{section}

\usepackage{backnaur}

\makeatother

\usepackage{babel}
\begin{document}
\section{Syntax van de taal}
\begin{bnf*}
\bnfprod{function\_call\_void}{
    \bnfts{setLight} \bnfpn{expression} \bnfpn{light} \bnfpn{expression} \bnfpn{expression} \bnfpn{expression}
    \bnfor
    \bnfts{drive} \bnfpn{expression} \bnfpn{direction} \bnfpn{expression}
    \bnfor
    \bnfts{closeBot} \bnfpn{expression}
    \bnfor
    \bnfts{print} \bnfpn{expression}
    \bnfor
    \bnfts{printLn} \bnfpn{expression}
    \bnfor
    \bnfts{sleep} \bnfpn{expression}
}\\
\end{bnf*}
\end{document}

And this is an image showing my problem:

enter image description here

1

I don't think the package provides for line breaks; you can add them as follows.

\documentclass[draft,dutch]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{geometry}
\geometry{tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
\usepackage{backnaur}

\newenvironment{bnfsplit}[1][0.7\textwidth]
 {\minipage[t]{#1}$}
 {$\endminipage}

\begin{document}
\section{Syntax van de taal}
\begin{bnf*}
\bnfprod{function\_call\_void}{
  \begin{bnfsplit}
  \bnfts{setLight} \bnfpn{expression} \bnfpn{light} 
    \bnfpn{expression} \bnfpn{expression} \bnfpn{expression}
  \\ \bnfor
    \bnfts{drive} \bnfpn{expression} \bnfpn{direction} \bnfpn{expression}
  \bnfor
    \bnfts{closeBot} \bnfpn{expression}
  \\ \bnfor
    \bnfts{print} \bnfpn{expression}
  \bnfor
    \bnfts{printLn} \bnfpn{expression}
    \bnfor
    \bnfts{sleep} \bnfpn{expression}
  \end{bnfsplit}
}\\
\end{bnf*}
\end{document}

enter image description here

The bnfsplit environment takes an optional argument, default 0.5\textwidth; adjust it manually with

\begin{bnfsplit}[0.7\textwidth]

or whatever.

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.