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:
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:
Notice that we have to use the left single quote `
and right single quote '
characters marks to get the right quotation marks.
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}
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}
\texttt
take \par
tokens? It might be better in this case to use \ttfamily
.
Commented
Nov 26, 2013 at 3:30
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}
`
and right single quote '
characters to get the quotes "right".
Commented
Nov 26, 2013 at 2:27
\usepackage{minted}