Quantcast
Channel: Active questions tagged copy-paste - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 70

Produce copy-paste friendly code blocks in PDFs

$
0
0

I have used lslisting for inserting the code blocks. Requirement is to make the code blocks displayed correctly in the compiled PDF and make them as easy as possible to copy as plain text. Please take a look at the following in order to demonstrate the problem,

\documentclass{article}\usepackage{listings}\lstset{  breaklines=true,  frame=single,  gobble=8,  tabsize=4,  language=bash,  basicstyle=\ttfamily,  columns=fullflexible}\begin{document}    \begin{lstlisting}        test $(ls -la) = $(ls -l)     \end{lstlisting}    \begin{verbatim}        test $(ls -la) = $(ls -l)     \end{verbatim}\end{document}

PDF

When I copy the output generated by lslisting, what I get is the following plain text:

test$(ls -la) =$(ls -l)

Problems with that are white spaces before '$' character go missing for some reason, also it's hard to copy in the sense that 'triple click highlight' to select the block/line doesn't work.

When I copy the output generated by verbatim, I get the block of text as plain text correctly as following and the also 'triple click' seems to work.

test $(ls -la) = $(ls -l)

But the problem with that is I can't use gobble=8 to correct the relative indentation and the formatting possibilities are also limited.

I also want to mention that I'm aware that the PDF viewers also play a role here but what I need is something that supports most PDF viewers generally like verbatim does but with the formatting possibilities. I think it should be possible because if verbatim can do that, why can't we add onto it? Is there any better alternative to lslisting

Something like below (GitHub Markdown) would be ideal although 'copy' button might not be possible but at least text might be,

MD


Viewing all articles
Browse latest Browse all 70

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>