# Own equation environment for - R syntax formulas

I'd like to be able to write down formulas in R syntax as equations, i.e. I'd like to do something like this:

\begin{requation}
time ~ (poly(I(1/nprocs), 2) + poly(ndoms, 2) + poly(nDOF, 2))^3
\end{requation}


while the equation would be numbered together with ordinary equations and its content would be the simple text with \texttt{}. So, I need no math-mode inside the environment.

Do you know, how to do it?

### EDIT

I've tried something like this

\newenvironment{requation}
{%
\VerbatimEnvironment
\begin{Verbatim}
}
{
\end{Verbatim}
\refstepcounter{equation}\hfill(\theequation)}


The only problem is, that in this case there is a newline after \end{Verbatim} which I don't want - is there any possibility to get rid of it?

• This has been asked before, eg: tex.stackexchange.com/q/161674/15036 – Thruston Apr 9 '17 at 20:13
• The simplest way to do that might be just to use ordinary equation environments, and mark the R code with \verb|...|. – Thruston Apr 9 '17 at 20:37
• @Thruston I'm not interested in just numbering verbatims. I want to use them the same way as equation, including the common numbering for both of them. I.e. if I have 3 equations, then I want my requation to have number 4 and following equation to have number 5. – Eenoku Apr 9 '17 at 23:12
• @Thruston And yes, your advice with verb is exactly, what I'm looking for. Could you, please, expand your comment into an answer, so I could accept it? – Eenoku Apr 9 '17 at 23:21

Here's a simple way to get what you want without defining a new environment, or using any extra packages:

\documentclass{article}
\begin{document}
$$\verb"time ~ (poly(I(1/nprocs), 2) + poly(ndoms, 2) + poly(nDOF, 2))^3"$$
\end{document}


Notice that the equation number has been pushed to the line below; that's because the R code you gave as an example is rather long, and the default text width is not that wide.

You could avoid typing the \verb bit if you use the shortvrb package.

\documentclass{article}
\usepackage{shortvrb}\MakeShortVerb{"}
\begin{document}
$$"time ~ (poly(I(1/nprocs), 2) + poly(ndoms, 2) + poly(nDOF, 2))^3"$$
\end{document}


but that would have an effect on the rest of your document, and you might struggle to find a short verb character that is not part of R syntax. The advantage of the first solution is that you can change the character each time, as required:

\documentclass{article}
\begin{document}
$$\verb|time ~ (poly(I(1/nprocs), 2) + poly(ndoms, 2) + poly(nDOF, 2))^3|$$
\end{document}


In all cases, the verbatim bit must be all on one line.