If my understanding that it is possible to specify the programming language for the listings globally as well as on the listing by listing basis is correct, than the following should work:
\documentclass[11pt,letterpaper]{book}
\usepackage{listings}
\begin{document}
\lstloadlanguages{SQL,Basic} %Listings manual, pp. 11, 13
\lstset{
frameround=fttt
,language=SQL
,numbers=left
,breaklines=true
,showstringspaces=false
,basicstyle=\small
}
\begin{lstlisting}[language=Basic,label={lst:ssrscurmon}]
=MonthName(DatePart(DateInterval.Month, Today()))
\end{lstlisting}
\end{document}
But it instead throws
Package Listings Error: Couldn't load requested language \lstloadlanguages{SQL,Basic}
How can I specify Basic for some listings in the document, where the majority are in SQL?
Best Answer
This can be considered a bug in
listings
; inlstdvrs.dtx
, more specifically.The
lstdvrs.dtx
file is where alllistings
languages and dialects are defined. In particular, a language calledBasic
(together with only one dialect,Visual
) is defined there.The problem is that, even though the
Basic
language comes with only one dialect (Visual
), the default dialect for Basic is defined nowhere inlstdvrs.dtx
. Therefore, if you simply specifylistings
has no clue which language you're referring to! The same problem arises, for the same reason, if you try to load theAssembler
language without also specifying a dialect.To fix the problem, you have two options:
Whenever you want to use Basic, specify its only dialect (
Visual
) also:Fix that bug in
listings
yourself by defining the default dialect forBasic
:(As Peter notes, this should preferably be done in your preamble. You should endeavour to separate style from content; the former should go in the preamble, whereas the latter should go in the body of your document.)
Then you should be able to use the
Basic
language without mishap. No need to use\lstloadlanguages
at all (although, as pointed out by Peter, you may still want to load the languages you use right after loading thelistings
package, for efficiency reasons; see the note at the bottom of section 2.2 in the documentation).