The packages listings and minted present source code inline.

My publication target is PDF. From my own documents as well as from the documentation for those two packages, copying and pasting the source code listings omits all indentation. My students are not happy to have to fix the indentation to try a sample snippet of Python.

I suspect this is down to an inherent limitation in PDF, which places characters (not whitespace) on the page. Is there any way to make a TeX source code listing published in PDF whose indentation can be copied and pasted?

marked as duplicate by subham soni, DG', Phelype Oleinik, Zarko, leandriis May 10 at 17:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.