I'm using the Listings package and am having a bit of trouble properly highlighting a string such as

string x = 'a'

with single quotes. The issue is that in Latex the left single quote operator (`) and right single quote operator (') are not the same. I added the following modifiers to my \lstset to try and fix this:


(where mauve is \definecolor{mauve}{rgb}{0.58,0,0.82})

but this simply gives me output like the following (note how the semicolon is still mauve and thus the delimiters aren't working correctly):

enter image description here

So I can't figure out how to indicate that ' and ` should both be delimiters. Alternatively, perhaps there is just some symmetric (i.e. not left or right) single quote I can use in Latex?

Thanks so much

  • I am a bit confused with your question. Are you actually typing char c = `f' inside your listing? If so, why? – Willie Wong Feb 24 at 5:10
  • 1
    In any case, according to tex.stackexchange.com/a/378367/119 if you use morestring=[d]{`} this means that you are declaring strings to be contained between a pair of backticks ([d] requires the two delimiters to be the same). If you want to have a pair of unequal delimiters, you need to use [s] instead. Probably [s][]{`}{'} would work, but I don't use the package. – Willie Wong Feb 24 at 5:21
  • aha thanks for this morestring=[s]{`}{'} ended up working! – Evan Feb 24 at 5:29

Your Answer

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

Browse other questions tagged or ask your own question.