Skip to content

Sometimes whitespace can't be copied from PDF #671

Closed as not planned
Closed as not planned

Description

@Xmoe

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
Screenshot_20230408_152514
Selecting text to copy
Screenshot_20230408_152535
Pasting text reveals missing indentation
Screenshot_20230408_152607

While pdf is not the best format to store code, it should not break whitespace-sensitive contents.

Activity

  1. user202729 commented on Apr 8, 2023

    @user202729
    Contributor

    Easier said than done. There seems to be not much good solutions even when LaTeX can use \pdfspecial to 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.

  2. added
    pdf
    on Apr 11, 2023
  3. laurmaedje commented on Apr 11, 2023

    @laurmaedje
    Member

    We do export the spaces, but apparently many PDF viewers ignore it.

  4. disbolog commented on Oct 20, 2023

    @disbolog

    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?

  5. 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
  6. added
    feature request
    on Nov 14, 2023
  7. changed the title [-]Can't copy whitespace from raw block in PDF[/-] [+]Sometimes whitespaces can't be copied from PDF[/+] on Nov 14, 2023
  8. changed the title [-]Sometimes whitespaces can't be copied from PDF[/-] [+]Sometimes whitespace can't be copied from PDF[/+] on Nov 14, 2023
  9. added
    bug
    and removed
    feature request
    on Nov 14, 2023
  10. added
    text
    on Jul 15, 2024
  11. LaurenzV commented on Aug 27, 2024

    @LaurenzV
    Collaborator

    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.

  12. laurmaedje commented on Aug 27, 2024

    @laurmaedje
    Member

    That's a bummer.

  13. removed
    bug
    on Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pdftext

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions