TeX - LaTeX Asked by user218403 on January 11, 2021
Im trying to insert in my PDF some long bash commands like this one:
I like how it looks but, when trying to copy, it splits the command into 3 lines, which obviously is not how I would like it to work.
I provide the code which generates the image above:
documentclass[11pt,a4paper]{report}
RequirePackage{xcolor}
usepackage{listings}
lstdefinestyle{bashStyle}{
language=bash,
basicstyle=smallsffamily,
frame=tb,
columns=fullflexible,
backgroundcolor=color{yellow!20},
linewidth=linewidth,
xleftmargin=0.075linewidth,
breaklines=true,
literate =
{'}{{textquotesingle}}1
{-}{{-}}1
}
begin{document}
begin{lstlisting}[style=bashStyle]
user@machine:~$ apt-get install package1 package2 package3 package4 package5 package6 package7 package8 package9 package10 package11 package12
end{lstlisting}
end{document}
EDIT:
For clarification purposes, this is what I get when I paste the command after copying it:
Line 1: apt-get install package1 package2 package3 package4
Line 2: package5 package6 package7 package8 package9 package10
Line 3: package11 package12
And this is what I want:
Line 1: apt-get install package1 package2 package3 package4 package5 package6 package7 package8 package9 package10 package11 package12
You can add a button that will be used by the readers to copy content in the original format.
documentclass[11pt,a4paper]{report}
usepackage{listings}
lstdefinestyle{bashStyle}{
language=bash,
basicstyle=smallsffamily,
frame=tb,
columns=fullflexible,
backgroundcolor=color{yellow!20},
linewidth=linewidth,
xleftmargin=0.075linewidth,
breaklines=true,
literate =
{'}{{textquotesingle}}1
{-}{{-}}1
}
usepackage{accsupp}
usepackage{verbatim}
usepackage{color}
usepackage[misc]{ifsym}
definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9}
makeatletter
lst@RequireAspects{writefile}
% Use accsupp package to add listing content as copyable text.
lstnewenvironment{copyablelisting}{%
lst@BeginAlsoWriteFile{jobname.lsttmp}%
}
{%
lst@EndWriteFile
letverbatim@processlineadd@lstline
globalletlstfileempty
verbatiminput{jobname.lsttmp}%
marginpar{(BeginAccSupp{method=escape,ActualText={lstfile}}PaperPortraitEndAccSupp{})}
}
defadd@lstline
{xdeflstfile{unexpandedexpandafter{lstfile}theverbatim@linestring^^J}}
makeatother
begin{document}
lstset{breakatwhitespace=true,style=bashStyle,breaklines=true,language=[LaTeX]TeX,basicstyle=smallttfamily,flexiblecolumns,backgroundcolor=color{lstbgcolor}}
begin{copyablelisting}
user@machine:~$ apt-get install package1 package2 package3 package4 package5 package6 package7 package8 package9 package10 package11 package12
end{copyablelisting}
end{document}
Answered by chadoulis on January 11, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP