I understand that for quotation marks ` is required to open a quote, however I am listing a long code copied over from Python where some comments are written 'comment' or """comment""". Is there an easy way to make the quotation marks at the start of a comment appear the right way around without manually changing them all?

My LaTeX is roughly as follows:


\begin{lstlisting}[language=Python, showstringspaces=false, breaklines = true]

"""comment 1"""

'comment 2'

directory=input('apostrophes also appear in code sometimes: ')

  • Make a small but complete that can be used for tests. – Ulrike Fischer Apr 30 '18 at 10:04
  • maybe tex.stackexchange.com/questions/166790/… can be useful? – Marijn Apr 30 '18 at 10:25
  • Ideally I'd still like to have curly apostrophes but this is better than the current situation, thanks! – Matt Bradley Apr 30 '18 at 10:29
  • by "right way round" what do you mean, do you mean you want open and close quotes in the source listing? (most people would class that as wrong as it would be a python syntax error if the reader copied the code) – David Carlisle Apr 30 '18 at 10:41
  • I was looking for open and close quotes yeah, but without having to retype all the open quotes as `. The document in question is only for print so there wouldn't be any issues with copy/pasting, although I suppose if what I'm suggesting is considered incorrect then maybe I should just stick with the solution above. – Matt Bradley Apr 30 '18 at 10:58

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.