tags:

views:

820

answers:

2

I'm looking for a package to typeset SQL statements in LaTeX. So far I have heard of listings and lgrind, are there any other suggestions?

[edit] Added requirement: I'd like the package to be able in intelligently insert page breaks, so that where possible statements do not span multiple pages. Still reading documentation, so it is possible that either of the a/m are able to do this already- Please let me know if this is the case.

Related: question

+3  A: 

You want to use the listings package. Is there a specific thing you want to do with it, or are you just asking which package works best in general? I've never encountered any big problems with listings, though getting it to do Exactly What I Want is sometimes tricky (it's LaTeX; to expect anything else would be folly).

Edit (to address your edit): intelligent page breaking might be problematic; it's certainly beyond my abilities. listings might be able to do it with explicit markup (escape to LaTeX and insert a negative page break penalty at appropriate place; likely macro-izable), but I don't think listings can do it automatically, and I doubt LGrind can do it either. You might have better luck searching or asking on a LaTeX-specific list (comp.text.tex on Usenet is a great place to try), but page breaking in TeX has never been as good as line breaking, and so I wouldn't hold out too much hope, unfortunately.

kquinn
+2  A: 

I use the listings package, but mostly for snippets. I haven't needed to worry about page breaks in general. One of the great things about listings is the high degree of flexibility available. For instance, I don't capitalize my SQL, but I can print my listings with capitalized keywords:

\makeatletter
\newcommand{\lstuppercase}{\uppercase\expandafter{\expandafter\lst@token
                           \expandafter{\the\lst@token}}}
\newcommand{\lstlowercase}{\lowercase\expandafter{\expandafter\lst@token
                           \expandafter{\the\lst@token}}}
\makeatother

\lstdefinestyle{Oracle}{basicstyle=\ttfamily,
                        keywordstyle=\lstuppercase,
                        emphstyle=\itshape,
                        showstringspaces=false,
                        }

And define more keywords as I need them:

\lstdefinelanguage[Oracle]{SQL}[]{SQL}{
  morekeywords={ACCESS, MOD, NLS_DATE_FORMAT, NVL, REPLACE, SYSDATE,
                TO_CHAR, TO_NUMBER, TRUNC},
}

To make use of these definitions:

\lstset{language=[Oracle]SQL,
        style=Oracle,
       }

If I were to print out larger pieces of code, I'd either not worry about page breaks or write a preprocessor to divide the code up before passing it to LaTeX.

Jon Ericson