You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sometimes whitespace can't be copied from PDF #671
When including a #raw code block, it will render whitespace and indentation as intended, however when copying from the pdf, indentation is not included.
Visualization of the problem:
Generated pdf looks fine
Selecting text to copy
Pasting text reveals missing indentation
While pdf is not the best format to store code, it should not break whitespace-sensitive contents.
Reacted by Oleksandr Babak, Pēteris Pakalns , Andrew Voynov and lumi-a
Would it be possible to render some characters in place (e.g. a dot in the middle of a line), that indicate whitespace?
I would also like to get your opinion on 2 different approaches to solve such an issue: after copying the text which includes such characters,
the characters are either preserved as dots or as whatever char was specified (less desirable, but probably is easier to implement, if not implemented already);
or these chars are "converted" to whitespace on copy (more desirable obviously).
Either way, the copy buffer gets the correct indentation.
Would such a functionality be possible to implement?
changed the title [-]Significant whitespace is removed from #raw blocks in generated pdf[/-][+]Can't copy whitespace from raw block in PDF[/+]on Nov 14, 2023
I've played around quite a bit with this, but it seems there just isn't a way of doing this. Whenever there is a glyph that is mapped to the space character in the CMAP, it just refuses to copy/select it properly and each viewer applies there own logic of handling it. Each of the approaches mentioned in the links above have their own quirks and don't work universally and have other issues. So I would suggest to close this issue, even though it's somewhat unfortunate, but there is, to the best of my knowledge, no way of implementing this properly.
I've also tried if this can be made to work if the space character has outlines, but it doesn't seem to change anything. It seems like most readers just rely on the CMAP here.
Activity
user202729 commentedon Apr 8, 2023
Easier said than done. There seems to be not much good solutions even when LaTeX can use
\pdfspecialto include "arbitrary" content in the PDF.listings - How make a LaTeX document that generates a PDF from which copy-paste works correctly for empty lines and leading space indentation? - TeX - LaTeX Stack Exchange
Read through all the linked questions. If I recalled correctly, all of them break in one viewer or another.
laurmaedje commentedon Apr 11, 2023
We do export the spaces, but apparently many PDF viewers ignore it.
disbolog commentedon Oct 20, 2023
Would it be possible to render some characters in place (e.g. a dot in the middle of a line), that indicate whitespace?
I would also like to get your opinion on 2 different approaches to solve such an issue: after copying the text which includes such characters,
Either way, the copy buffer gets the correct indentation.
Would such a functionality be possible to implement?
[-]Significant whitespace is removed from #raw blocks in generated pdf[/-][+]Can't copy whitespace from raw block in PDF[/+][-]Can't copy whitespace from raw block in PDF[/-][+]Sometimes whitespaces can't be copied from PDF[/+][-]Sometimes whitespaces can't be copied from PDF[/-][+]Sometimes whitespace can't be copied from PDF[/+]LaurenzV commentedon Aug 27, 2024
I've played around quite a bit with this, but it seems there just isn't a way of doing this. Whenever there is a glyph that is mapped to the space character in the CMAP, it just refuses to copy/select it properly and each viewer applies there own logic of handling it. Each of the approaches mentioned in the links above have their own quirks and don't work universally and have other issues. So I would suggest to close this issue, even though it's somewhat unfortunate, but there is, to the best of my knowledge, no way of implementing this properly.
I've also tried if this can be made to work if the space character has outlines, but it doesn't seem to change anything. It seems like most readers just rely on the CMAP here.
laurmaedje commentedon Aug 27, 2024
That's a bummer.