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
\LoadClass[a4paper,12pt,openright,oneside,chapter=TITLE,section=TITLE,hidelinks] {article}\documentclass{article}\RequirePackage[utf8]{inputenc}\RequirePackage[a4paper,margin=2cm]{geometry}\RequirePackage{plex-mono}\usepackage[space=true]{accsupp}\usepackage[T1]{fontenc}\usepackage{textcomp}\usepackage{listings}\RequirePackage{xcolor}\lstset{ % Configuration to make it unescaped and copy-paste right %upquote=true, %columns=fullflexible, %showstringspaces=true, %literate={\ }{{\copyablespace}}1, % For the looks - make it monotype etc %frame=tb, %aboveskip=3mm, %belowskip=3mm, %numbers=left, %numberstyle=\tiny\color{lightgray}\ttfamily, % \nonumbercopy, %keywordstyle=\color{green}, %commentstyle=\color{blue}, %stringstyle=\color{red}, %breaklines=true, %breakatwhitespace=true, %tabsize=2, %numbersep=0.5em, %framerule=0pt, %xleftmargin=10pt, %xrightmargin=0pt, breaklines=true, backgroundcolor=\color{yellow}, %keepspaces=true, basicstyle=\fontsize{9}{11}\ttfamily%, %columns=fixed, %fontadjust=true, %showlines=false, %showstringspaces=false} %\newcommand{\copyablespace}{% \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\renewcommand{\title}[1]{ \pagestyle{fancy} \lhead{} \rhead{} \cfoot{\squelch{\thepage}}}\begin{document} \noindent Beginning of document, serif outside unescaped part. \begin{lstlisting}This is the uppermost-left unescaped monotyped text, it has no indentation. This is the second line, it has three letters of indentationHere 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{lstlisting} End of document, serif outside unescaped part.\end{document}
References
References to what we have already tried and which did not work:
- Viewer-independent copyable spaces at the beginning of a line?
- How to make listings code indentation remain unchanged when copied from PDF?
- produce copy-paste-able pdf output with correct indentation with listing
- How to copy/paste multiple spaces from lstlistings? - ** note here that they say "space characters cannot reliably be copied from a PDF" with reference to another article. Not sure this is a correct statement, this is why we publish this post, to go to the bottom of this question :)
- Copy-pasting leading whitespace and blank lines in listings package (pdf)
- https://www.monperrus.net/martin/copy-pastable-listings-in-pdf-from-latex
There's more AccSup discussion at Techniques to make tabular contents copyable .