Overleaf LaTeX: Double quotes showing as End Quotes in Latex when using listings package

236 Views Asked by At

Hey Stack Overflow Community,

I am getting the following issue with the following code in LaTeX:

\begin{lstlisting}[language=Python]

for file in files:
    print(file) #Printing the file helped us know visually what was being run
    temp = pd.read_csv(file, compression = 'gzip', header = 0, sep= '\t', quotechar='"', error_bad_lines = False, lineterminator = "\n"
    temp['date'] = pd.to_datetime(temp['date']).dt.date
    temp["is_geotweet"] = temp[["latitude", "longitude"]].notnull().all(axis=1)
    temp["latitude"] = temp["latitude"]
    temp["longitude"] = temp["longitude"]


\end{lstlisting}

The code shows as End Quotes whenever I try to use Double Quotes. I have tried using the upquote package in LaTeX and that helped me out with my single quotes. However, the double quotes were not fixed as a result of this. I tried using the backticks in the for loop listed, but that didn't help.

Please help me out if you can!

1

There are 1 best solutions below

0
On

Aren't double quotes (") used to delimit arguments or mark the beginning and end of a string?

When you use double quotes within the 'lstlisting' environment, LaTeX interprets them as the beginning and end of a string, causing the code to appear incorrectly.

You can give 'morestring' option a shot; specify the character that should be treated as string delimiter.

\begin{lstlisting}[language=Python,morestring=[s]{"""}{"""}]
for file in files:
    print(file) #Printing the file helped us know visually what was being run
    temp = pd.read_csv(file, compression = 'gzip', header = 0, sep= '\t', quotechar='"', error_bad_lines = False, lineterminator = "\n")
    temp['date'] = pd.to_datetime(temp['date']).dt.date
    temp["is_geotweet"] = temp[["latitude", "longitude"]].notnull().all(axis=1)
    temp["latitude"] = temp["latitude"]
    temp["longitude"] = temp["longitude"]
\end{lstlisting}

Also, make sure to have 'listings' package included in your document preamble for the 'lstlisting' environment to work properly.

I hope this helps! Take care!