I have XML code which I need to copy paste. Here's is the code
<joint name="joint1" type="continuous">
<parent link="link1"/>
<child link="link2"/>
<origin xyz="5 3 0" rpy="0 0 0" />
</joint>
I have used accsup to make it copy/paste-able as follows:
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{listings}
\lstset{
upquote=true,
columns=fullflexible,
literate={\ }{{\copyablespace}}1
}
\usepackage[space=true]{accsupp}
% requires the latest version of package accsupp
\newcommand{\copyablespace}{
\BeginAccSupp{method=hex,ActualText=00A0}
\ %
\EndAccSupp{}
}
I am new to LaTex and am not sure what exactly is happening here. But the BeginAccSupp part is replacing each space by 3 spaces in the pdf and as well when I copy paste.
<joint name="joint1" type="continuous">
<parent link="link1"/>
<child link="link2"/>
<origin xyz="5 3 0" rpy="0 0 0" />
</joint>
What am I doing wrong?
Edit !: After @Phelype Oleinik's solution, the PDF looks fine, also the indentation after I copy/paste is good, but the spaces in between the line are still the same
<joint name="joint1" type="continuous">
<parent link="link1"/>
<child link="link2"/>
<origin xyz="5 3 0" rpy="0 0 0" />
</joint>
Edit 2: A hack that works (not for the string spaces though) is replacing the spaces with tabs in the {lstlisting}.
So the code in tex looks like:
<joint name="joint1" type="continuous">
<parent link="link1"/>
<child link="link2"/>
<origin xyz="5 3 0" rpy="0 0 0" />
</joint>
And the copy/pasted code looks liḱe:
<joint name="joint1" type="continuous">
<parent link="link1"/>
<child link="link2"/>
<origin xyz="5 3 0" rpy="0 0 0" />
</joint
But not sure if I want to go with this hack.
\copyablespacemacro. If you put a%right after each line of the macro the problem should vanish. Use this:\newcommand{\copyablespace}{% \BeginAccSupp{method=hex,ActualText=00A0}% \ % \EndAccSupp{}% }– Phelype Oleinik Feb 15 '18 at 14:18%do? – harsh Feb 15 '18 at 14:24%correctly:\newcommand{\copyablespace}{%,\BeginAccSupp{method=hex,ActualText=00A0}%and\EndAccSupp{}%– egreg Feb 15 '18 at 14:51unicodein\BeginAccSupp? I could not paste anything after the 1st space without unicode, but with it, each space is replaced by 3. – harsh Feb 15 '18 at 15:01literateoption. – egreg Feb 15 '18 at 15:05%char is added to the end of the line to make TeX ignore what comes after, including the new line. For a more lengthy explanation see the first part of my answer here. – Phelype Oleinik Feb 15 '18 at 15:12