I don't know how to fix the double quote character (’"’) with the listings package when the code is in a separated file. Listing get this as the beginning of a string but it is not.

Many thanks to Gustavo Mezzetti for his answer with the moredelim/morestring options. Unfortunately even if thoses fixes are working well inside a latex file, morestring and moredelim fixes don't work when I include the code from a separated file.

Here is the new minimal example to show the problem :


This is working fine thanks to Gustavo Mezzetti answer's and the morestring=[b]' option :

file_name=$(cut -d '"' -f 2)
# This shoud be a comment
    echo "This should be a String"

This isn't working anymore when the same code is included from a separated file :

\lstinputlisting[language=Bash, morestring{[b]'}]{test.sh}

With the following separated file "test.sh" :

  file_name=$(cut -d '"' -f 2)
  # This shoud be a comment
  echo "This should be a String"

Results in :

enter image description here

Thanks for any help !

Note that this question is following this one : double quote charater (’"’) with listings create problem


1 Answer 1


Ok I get the fix : I just need to replace

\lstinputlisting[language=Bash, morestring{[b]'}]{test.sh}



The redundancy of listings options was the problem here I guess ;)

  • I cannot refrain from observing that the code you posted doesn’t work simply because it contains a syntax error: \lstinputlisting[language=bash, morestring={[b]'}]{test.sh} (note the = after morestrings) works just fine for me.
    – GuM
    Jun 27, 2015 at 15:47
  • I checked the previous question, and saw that it is my fault: the typo was already in my suggestion!
    – GuM
    Jun 27, 2015 at 15:53
  • Thanks again for your analyzed answer Gustavo ! I think you have the right answer for this question too : the problem here was this option syntax error in the \lstinputlisting[language=bash, morestring={[b]'}]{test.sh} line ! I just copied/pasted without checking what I was doing !
    – Marc
    Jun 28, 2015 at 15:12
  • As I have already said, this looks like a deficiency in the definition of the bash language: text delimited by single quotes is kind of an instance of a string in shell scripts, isn’t it? BTW, you might also want to try replacing, in the \lstset command, morestring=[b]' with morestring=[b][\color{magenta}]' (say).
    – GuM
    Jun 28, 2015 at 17:32

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.