1

I'm using the lstlisting package to write down the SQL queries. However, the word character appear in bold, because it is considered a keyword. I added it to the list of keyword to remove deletekeywords, but it does not seem to work. Although, if I put WHERE in the list of the deletekeywords list, it does work, unbolding it.

move it from the list o keywords.

\documentclass{article}
\usepackage{listings}
\usepackage{textcomp} % listings straight quote
\begin{document}
    \lstset{
        language=SQL,tabsize=2,upquote=true,
        %keywordstyle=\ttfamily\bfseries,basicstyle=\ttfamily,
        moredelim=[is][\underbar]{__}{__},
        morekeywords={ilike},
        sensitive=false,
        deletekeywords = {CHARACTER,character,WHERE},
    }
  \begin{lstlisting}
  SELECT m.title,c.id,p.name,ch.name
  FROM movie m
  JOIN casting c ON m.id = c.movie_id
  JOIN person p ON p.id=c.person_id
  JOIN character ch ON ch.id=c.char_id
  WHERE m.title ILIKE '%legend%';
  \end{lstlisting} 
\end{document}

Example of lstlisting that do not delete keyword

  • Welcome to TeX.SX! Please don't post code fragments. Instead, put your fragments into a complete compilable document that shows the problem. – BambOo Sep 8 at 12:24
  • @BambOo I've just updated the question. – Paulo Rodrigo Martins Sep 8 at 12:56
  • Is my answer conform with your request ? – BambOo Sep 8 at 19:47
  • Thank you so much, @BambOo. Your answer worked like a charm. If you could also vote my question, I'll would appreciate too. – Paulo Rodrigo Martins Sep 9 at 14:18
0

According to the listings manual, the passing arguments to the deletekeywords option should look like deletekeywords=[<number>]{<list of keywords>}. I did not find the correct <number> in the documentation, but playing a bit with values shows that <number>=2 works in your case.

\documentclass{article}
\usepackage{listings}
\usepackage{textcomp} % listings straight quote
\begin{document}
    \lstset{
        language=SQL,tabsize=2,upquote=true,
        %keywordstyle=\ttfamily\bfseries,basicstyle=\ttfamily,
        moredelim=[is][\underbar]{__}{__},
        morekeywords={ilike},
        sensitive=false,
        deletekeywords =[2]{CHARACTER,character,WHERE},
    }
  \begin{lstlisting}
  SELECT m.title,c.id,p.name,ch.name
  FROM movie m
  JOIN casting c ON m.id = c.movie_id
  JOIN person p ON p.id=c.person_id
  JOIN character ch ON ch.id=c.char_id
  WHERE m.title ILIKE '%legend%';
  \end{lstlisting} 
\end{document}

enter image description here

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.