Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to not copy numeration of listings package - LaTeX

Community Beginner ,
Aug 19, 2018 Aug 19, 2018

Context

I use Acrobat Reader DC on my PC to display documents made with LaTeX code. Sometimes I need to write and display code, so I use a package called listings.

That package has an option for add numeration to the code displayed in the document. For example this is a PDF output:

  1. Example code line 1
  2. *
  3. ... and 3

The numbers (1, 2 and 3) will not be copied if I use this command (inside LaTeX code):

numberstyle=\noncopynumber,

because if we copy a complete program made with, for example, C++ from that PDF output (always using listings) will generate errors, because the enumeration should not be copied.

Describing the problem

This non-copy-numbers works for me as long as the document stay in my computer, using Acrobat. But it does not work anymore if I upload the same document in a email of Outlook, for example. The enumeration is copied too, generating problems in a C++ program.

I contacted the maintainer of the listings package and he told me that it is probably a problem with the Adobe viewer. So I want to know how to solve this problem, because in "offline" mode the PDF works fine, but in "online" mode it does not.

Also I created a question in the TeX.StackExchange forum and they told me the same thing that the maintainer. You can see the post here​ and a GIF that I uploaded in Imgur to describe the problem visually (compiling in my computer -> seeing the PDF output with Adobe -> comparing it with the same document uploaded in Outlook).

You can test the PDF output with code of the listings package using this code given in that forum and pasting it in Overleaf:

\documentclass{article}

\usepackage{enumitem}

\usepackage{listings}

\usepackage{accsupp}
\newcommand{\noncopynumber}[1]{%
  
\BeginAccSupp{method=escape,ActualText={}}%
  #1
%
  
\EndAccSupp{}%
}

\lstset {%
  numbers
= left,%
  numberstyle
=\tiny\noncopynumber
}

\begin{document}

\begin{lstlisting}
Example code line 1
*
... and 3
\end{lstlisting}

\end{document}

You must download the PDF to try to copy the text inside the document.

If you need more information please let me know.

Thanks!

Examples

PDF output in my PC

Good.jpg

The same PDF uploaded in Outlook

Good.jpg

Technical Information

  • Acrobat Reader

Continuous Release: 2018.011.20058

File Version: 18.011.20058.33888

AGM Version: 4.030.00078

CoolType Version: 5.014.00033

Core Version: 18.2816

JP2K Version: 1.002.00002.41223

  • Browser

Google Chrome, version 68.0.3440.106 (Official Build) (64 bits)

  • OS

Microsoft Windows 10 Home Single Language, version 10.0.17134 compilation 17134

4.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 19, 2018 Aug 19, 2018

Does it work when you open the file directly in Reader? If so, the problem is with whatever PDF plugin used in Outlook to display the file, not with Reader itself. And there's no such thing as an "online" or an "offline" version of a PDF file. Any PDF file you view is first saved to the local machine, even if only as a temporary file. The difference is between what application is used to then open it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 19, 2018 Aug 19, 2018

Thanks for your answer. So you're saying it's NOT a Reader problem? Should I publish the problem in the Microsoft community? Yes, it works when I open the file directly in Reader. I mentioned "online" and "offline" so you can visualize the problem. I mean that if I upload the document to the Internet it stops working, either as an attachment on a page, or in Google Drive or Outlook, etc. What should I do now? If the answer is to change the program, I think it's a poor solution, because I use the documents to share with other people, and I should tell all of them to change their program so that it works well. Maybe Microsoft's can fix it in a later version.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 19, 2018 Aug 19, 2018

Depends. If you open it in Chrome then you're most likely use the Chrome PDF plugin, which is known to be a bit buggy.

If that's the case then you should report the issue to Google, which developed this plugin.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 19, 2018 Aug 19, 2018

Chrome PDF plugin has bugs? Lol. Should I publish in "Google Chrome Help Forum" on this page?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 19, 2018 Aug 19, 2018

Yes, plenty... The Chromium bug report page is located here: Issues - chromium - An open-source project to help move the web forward. - Monorail

But maybe start with the forums and move your way to it later on.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 19, 2018 Aug 19, 2018

Thanks! Interesting link. Yes, I'd better start with the forums, because I do not have technical knowledge to publish an official bug, and maybe they can fix it quickly through the forum. Thanks again, I'll do that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 19, 2018 Aug 19, 2018

Info: Google Chrome doesn't use Acrobat Reader.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 19, 2018 Aug 19, 2018

It's been a rule for 20 years and more: PDF is a terrible way to distribute text for exact copying, and software code is perhaps the worst example of that. PDF only seems suitable for this, it just isn't. Consider attaching source code as an attachment in the PDF if it must be one file. Though that won't be accessible if you use non-Adobe viewers. Unfortunately, most users don't understand the different viewers and their implications.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 19, 2018 Aug 19, 2018

Thanks for your reply. Unfortunately I can not change the rules of how a document is displayed for people. My idea is not to attach the code to a file, but to have the numbered code available to copy directly from the PDF document. Up to now all the PDFs that I have made (be it with Word or LaTeX) have gone out excellent, except for own errors that later I realized the program was not responsible. It is clear that I can not add the numbers to the code, but I am surprised that the document works well on my computer but not attached to the Internet. I have been told that I should report the problem to the Google forums.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 19, 2018 Aug 19, 2018

Chrome has its own PDF viewer. So does Firefox. Edge uses the Microsoft Reader app. Mac Safari and Preview use the built in Mac PDF functionality. On iOS there is a built in PDF viewer and a wide range of alternative apps. Email apps may use their own viewers. Windows and Mac preview too. Sometimes a PDF is rendered server side. You have a lot to test.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 19, 2018 Aug 19, 2018

I tried with Edge and the results are the same:

Bad 3.jpg

I don't have Firefox. I should not try anything else. It should work correctly in Google Chrome and others.

Anyway, I already raised the problem here.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 19, 2018 Aug 19, 2018

Can you share a simple sample PDF? I'd be interested to find out what technique it is using to have "non copy text", which isn't a thing in PDF.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 19, 2018 Aug 19, 2018

Sure. There is no technique... just copy the text of the PDF document and paste it anywhere (notepad, etc.).

I don't know how to attach a file in the forum, so I share with you through Google Drive:

PDF with command numberstyle=\noncopynumber: https://drive.google.com/open?id=1ZuhLI-G7GUGrEdkRFlDLxNMjqK78eP6e

PDF without command numberstyle=\noncopynumber: https://drive.google.com/open?id=1WB0e-nhIKmk0zP0yHBWhqcCvxe0-VOF-

In my case both PDF copy the numbers (because they are hosted in Google Drive), but if I open the first PDF with Acrobat Reader in my Windows 10 the numbers are not copied anymore (with the second are copied).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 19, 2018 Aug 19, 2018

Ah, but there is a technique, by which "no copy" text is added to a PDF. I mean, what the LaTeX macros do.

I found what it is. A PDF file can be "accessible" or "tagged" meaning it has detailed and exact information about structure and text. A PDF reader can use this detailed info for copying.

Acrobat Reader does this - it understands about accessibility, and is designed to aid people who have difficulty seeing the screen but still want access to all of the contents. The line numbers are given an "actualtext" value of nothing at all, meaning that while there is text on the page, it does not copy. Most PDF readers, however, do not support accessibility. This is not a bug, it is the lack of a feature, a very complex and specialist feature. So what you are asking for is not a bug fix but full accessibility support. Good luck with that, the authors of PDF reading software ignore large parts of the rules of PDF.

HOWEVER, the PDF is faulty. Here are the rules of actualtext: " "The ActualText value is not a description but a replacement for the content, pro viding text that is equivalent to what a reader with sight would see when viewing the content. "" While the "no copy" feature is convenient, it is a clear abuse of accessibility, because it means an unsighted person is not given access to the entire document. Instead, information is left out to get what amounts to a trick. This would fail a proper check of accessibility and hence may be illegal for some purposes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 19, 2018 Aug 19, 2018

Thanks. I think you got it. So are you saying that some of the Reader versions on Internet can copy the numbers because they don't have a feature (accessibility feature)?

On the other hand, I understand that the \actualtext command to which you refer makes an act of illegality in which some Readers can not accept. This is why some can copy the text (or numbers), right?

In these cases it is not a bug; Acrobat authors should implement this functionality for all versions. If they do not, what would you recommend me to do? Remove the numbers?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 20, 2018 Aug 20, 2018
LATEST

Yes remove the numbers or accept my point that PDF is not for distributing text.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines