'How to insert code in Word, export to pdf, and keep formatting?

I've written some Python code for my thesis, and wish to add this to my report in Word. I have to hand it in in pdf format. But when I convert the word document, the code cannot be copy pasted and used again, as the tabs are replaced by a single space.

Is there any solution for this?



Solution 1:[1]

found the answer: replace all spaces by _ , and possibly make them invisible (white).

If you want to copy paste and use the code, just replace all _ by spaces again.

Solved!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mark