We are writing a PDF document in LaTeX that contains various installation instructions and other technology text. Our idea is that the user reads various instructions in Serif font and then there's multiline monotype sections that he would copy-paste into a console or editor, that is the monotype inline is shellscript, C, such.

Finally we prefer those shell/C/etc. snippets to be unescaped (that is HEREDOC, <PRE> kind of behavior). For this reason, we tried the "listings" package and \lstset+\begin{lstlisting} forms for HEREDOC behavior for the text content that is the Tex file will contain the text without the use of any escape sequences, and then we tried \usepackage[space=true]{accsupp} to make copying text our of the PDF to work as expected.

Trying this has however not been successful and we don't understand why, specifically what happens is that the copied-out text tends to exclude empty lines and leading spaces.

Last details:

  • We like to use IBM Plex Mono for the tech font.

  • If needed, we can tolerate adding an empty space on each empty line.

  • We try to use some tricks for page footer (and any line number on the side) to not be included in the copypaste and that has worked quite well.

  • If the copy-paste would only work in some particular PDF viewers, it's okay. If so one of the crossplatform PDF viewers would be to prefer, those are: Evince, Chrome, Firefox, MuPDF. (If any more come to mind please share.) Limited-platforms PDF viewers would be Adobe Reader and PDF Exchange Viewer.

  • If heredoc style is impossible in latex then we can live without it, eg one BeginAccsupp per line or any other measure needed.

Can you please share your thoughts and examples on this?

If this cannot be done satisfactorily, what do you suggest - use some other output language such as HTML generated by "htlatex"? Would using PS be of any help, but if so what viewer software is there.

Tex code we tried

 % Configuration to make it unescaped and copy-paste right
 %literate={\ }{{\copyablespace}}1,
 % For the looks - make it monotype etc
 %numberstyle=\tiny\color{lightgray}\ttfamily, % \nonumbercopy,

%    \BeginAccSupp{method=hex,unicode,ActualText=0040}
%\ %
%    \EndAccSupp{}

% Make the line numbers not appear in copy-paste
% \newcommand{\nonumbercopy}[1]{
%   \BeginAccSupp{method=hex,unicode,ActualText=00A0}#1\EndAccSupp{}
% }

% Footer

    \noindent Beginning of document, serif outside unescaped part.
This is the uppermost-left unescaped monotyped text, it has no indentation.
  This is the second line, it has three letters of indentation
Here are some characters that prove that we can type without escaping: \{$
Now let's do an empty line:

The empty line worked fine. Copypaste this and see the copy is the same!
    End of document, serif outside unescaped part.


References to what we have already tried and which did not work:

There's more AccSup discussion at Techniques to make tabular contents copyable .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.