# How can I insert the following WinBugs code into Latex as a text format?

How can I insert the following WinBugs code into LaTeX as a text format?

  model
{
for(i in 1:nSUB)
{
s[i] ~ dnorm(0,tau.precision);
}
}


I tried \texttt{}:

\texttt{model
\{   \par
for(i in 1:nSUB)   \par
\{   \par
s[i] $\sim$ dnorm(0,tau.precision);  \par
\}  \par
\}
}


However, it gives a error message:

{model \{
! Paragraph ended before \text@command was complete. ....


I tried \usepackage{listings}, and used language R because there's no WinBugs language included.

\begin{lstlisting}[language=R]

model
{
for(i in 1:nSUB)
{
s[i] ~ dnorm(0,tau.precision);
}
}
\end{lstlisting}


There's no error message, but the text still looks very strange.

• verbatim environment is the simple approach. – Steven B. Segletes Apr 5 '18 at 17:37
• HI, strange is a very relative concept, what do you mean by that ? – BambOo Apr 5 '18 at 18:09
• @BambOo I assume that, by strange, the OP means non-proportional spacing. – Steven B. Segletes Apr 5 '18 at 18:51
• @BambOo By strange I meant some words are bolded while some are not. I guess the bolded ones are considered as functions, but it's not consistent with WinBugs. Also, the ~ is weird looking. – celadonz Apr 5 '18 at 19:26
• @celadonz, check the listings (here) or minted packages. Both of them have great documentation. Check this post for instance as a starting point. This will help you make your own language style. – BambOo Apr 5 '18 at 20:19

I don't know WinBugs, but turns out there's a lexer for pygments. You can use the minted environment as follows.

\documentclass{article}
\usepackage{minted}

\begin{document}
\begin{minted}{winbugs}
model
{
for(i in 1:nSUB)
{
s[i] ~ dnorm(0,tau.precision);
}
}
\end{minted}
\end{document}


The result looks quite reasonable although you can apply a different style if you prefer fewer or more colors. I tend to go with bw.

• Your results look neat! However, I cannot reproduce on my computer. I pasted your original code to a tmp.tex file. When I compile it, there's an error message saying '!Latex Error: File 'tmp.pyg' not found'. Is there something I missed? – celadonz Apr 5 '18 at 20:21
• Possibly you need to run with --shell-escape argument... Not sure because I haven't use it... Just check this: tex.stackexchange.com/a/99476/120578 – koleygr Apr 5 '18 at 20:26
• Python and Pygments are prerequisites for minted, but easily installed as per section 2 of the minted manual. And you need to invoke latex with command-line option -shell-escape. – tucuxi Apr 5 '18 at 20:27
• @tucuxi I see. Unfortunately this is a company machine and I don't have admin rights to install anything. Thanks though. – celadonz Apr 5 '18 at 20:31