16

Suppose we have a script as follows:

a = LOAD 'data' USING BinStorage AS (user);
b = GROUP a BY user;
c = FOREACH b GENERATE COUNT(a) AS cnt;
d = ORDER c BY cnt;

How to write the latex code to achieve the following effect: enter image description here

1

4 Answers 4

13

I believe that a simple verbatim environment will suffice.

\documentclass{article}

\begin{document}
\begin{verbatim}
a = LOAD `data' USING BinStorage AS (user);
b = GROUP a BY user;
c = FOREACH b GENERATE COUNT(a) AS cnt;
d = ORDER c BY cnt;
\end{verbatim}
\end{document}

Output:

enter image description here

Notice that we have to use the left single quote ` and right single quote ' characters marks to get the right quotation marks.

1
  • The text flows out of the page, how do we wrap text here? Commented Nov 21, 2017 at 0:10
24

I would leave it to listings package which understands SQL among many many other languages.

\documentclass{article}
\usepackage{xcolor,listings}
\usepackage{textcomp}
\lstset{upquote=true}

\begin{document}
Here is an example 
\begin{lstlisting}[
           language=SQL,
           showspaces=false,
           basicstyle=\ttfamily,
           numbers=left,
           numberstyle=\tiny,
           commentstyle=\color{gray}
        ]
a = LOAD 'data' USING BinStorage AS (user);
b = GROUP a BY user;
/* Now we are ready to loop */
c = FOREACH b GENERATE COUNT(a) AS cnt;
d = ORDER c BY cnt;
\end{lstlisting}

\end{document}

enter image description here

2
  • Does listing provide a way to "correct" the quote.
    – Aditya
    Commented Nov 26, 2013 at 3:09
  • 1
    @Aditya Now fixed
    – percusse
    Commented Nov 26, 2013 at 3:12
5

Two easy ways:

\documentclass{article}
\begin{document}

For example:

{\obeylines\obeyspaces
\texttt{
a = LOAD 'data' USING BinStorage AS (user);
b = GROUP a BY user;
c = FOREACH b GENERATE COUNT(a) AS cnt;
d = ORDER c BY cnt;
}}

\medskip
Or:

\begin{verbatim}
a = LOAD 'data' USING BinStorage AS (user);
b = GROUP a BY user;
c = FOREACH b GENERATE COUNT(a) AS cnt;
d = ORDER c BY cnt;
\end{verbatim}


\end{document}

enter image description here

1
  • I can't remember -- does \texttt take \par tokens? It might be better in this case to use \ttfamily. Commented Nov 26, 2013 at 3:30
4

Little typing practice:

\documentclass{article}
%% \usepackage{listings} you can use this also see the manual
%\usepackage[scaled=.9]{beramono}
\begin{document}
Another case where Pig is able to know the type of a field even when the program has not declared types is when operators or user-defined functions (UDFs) have been applied whose return type is known. In the following example Pig will order the output data numerically since it knows that the return type of \texttt{COUNT} is \verb|long|.
\begin{verbatim}
a = LOAD `data' USING BinStorage AS (user);
b = GROUP a BY user;
c = FOREACH b GENERATE COUNT(a) AS cnt;
d = ORDER c BY cnt;
\end{verbatim}

\end{document}

enter image description here

3
  • You just beat me to it! I should add that you need to use the left single quote ` and right single quote ' characters to get the quotes "right". Commented Nov 26, 2013 at 2:27
  • @ILiketoCode I simply copy pasted :-)
    – user11232
    Commented Nov 26, 2013 at 2:35
  • 2
    Obligatory rant whenever I see wrong quotes typeset by TeX. Please use a unicode engine (xetex or luatex), load the fontspec package and a unicode teletype font.
    – Aditya
    Commented Nov 26, 2013 at 3:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .