1

I have the following MWE for SQL typesetting. What doesn't work for me and for which I need help are two things:

  1. I would like to add "SUCH AS" as a keyword (or make it bold in the text without defining it as a keyword); and
  2. I need "domain" not to be bold, but it insists in typesetting it bold even when I include it in deletekeywords. Don't know what is happening there.

    \documentclass[border=2pt]{standalone}
    
    \usepackage{newtxtext,newtxmath} 
    \usepackage{listings}
    
    \lstset{language=SQL,basicstyle=\ttfamily,keywordstyle=\bfseries,
      showspaces=false,showstringspaces=false, 
      morekeywords={*,IF,DEFINE,OPTIONS, SERVER, MENTIONS, SUCH THAT}, 
      deletekeywords={domain}, mathescape=true, aboveskip=0pt, belowskip=6pt}
    
    \begin{document}   
    \begin{lstlisting} 
    FROM Relation SUCH THAT domain-condition 
    \end{lstlisting}
    \end{document}
    

Would appreciate any help. Here is what comes out when I typeset it.

enter image description here

  • Sorry -- I don't know why the MWE is coming out this way... I did enter it as a code fragment but it is not being typeset as such. – ozsu Mar 21 at 1:45
2

To get rid of the domain keyword, you have to spell it in uppercase in deletekeywords because that's how it is defined in the drivers file.

Additionally, spaces may not occur in keywords. You could perhaps make the space a letter or other character and define keywords based on that, but this would likely cause problems with the word-breaking mechanism.

An easy solution is to use the literate option to replace each literal occurrence of SUCH THAT by the same string with the corresponding style being applied.

In sum, the new listings setup would look like this (modified options are highlighted):

    \lstset{
        language=SQL,
        basicstyle=\ttfamily,
        keywordstyle=\bfseries,
        showspaces=false,
        showstringspaces=false,
        morekeywords={*,IF,DEFINE,OPTIONS,SERVER,MENTIONS},
        deletekeywords={DOMAIN},
        mathescape=true,
        aboveskip=0pt,
        belowskip=6pt,
        literate={SUCH\ THAT}{\bfseries SUCH\ THAT}{9}
    }

enter image description here

  • Many thanks. I'll try these. – ozsu Mar 21 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.