There is a question about minuses in listings.
Is it possible to make (document-wide) the minus sign (−) to look like the typographic minus, but be copied from the resulting PDF as the hyphen (-), used in source code?
There is a question about minuses in listings.
Is it possible to make (document-wide) the minus sign (−) to look like the typographic minus, but be copied from the resulting PDF as the hyphen (-), used in source code?
\documentclass{article}
\usepackage{accsupp}
\newcommand\pdfminus{\BeginAccSupp{method=escape,ActualText=-}-\EndAccSupp{}}
\begin{document}
$\pdfminus A \pdfminus B = C$
$-A - B = C$
\end{document}
Copy/paste yields:
-A - B = C
A B = C
SUPPLEMENT
The OP comments on how it would be nice to have it done automatically. Unfortunately, redefining - as an active character everywhere I can only assume will break all negative numerical/length arguments. However, one could scope the \active nature of - to only apply it in places where it wouldn't break stuff:
\documentclass{article}
\let\svminus-
\usepackage{accsupp}
\newcommand\pdfminus{%
\BeginAccSupp{method=escape,ActualText=-}\svminus\EndAccSupp{}}
{\catcode`-=\active \gdef-{\pdfminus}}
\newcommand\pdfminusON{\catcode`-=\active }
\newcommand\pdfminusOFF{\catcode`-=12 }
\begin{document}
\pdfminusON$- A - B = C$ Special $-$\pdfminusOFF
\vspace{-1cm}$-A - B = C$ Normal $-$
\end{document}
-A - B = C Special -
A B = C Normal
pdflatex(maybe there is inlualatex...I don't know). What can be done is temporarily making-active and redirecting it to\pdfminuswithin the scope of the\activeminus. However, you can't leave it active all the time, or it screws up any calculation requiring a length or integer subtraction. – Steven B. Segletes Oct 31 '18 at 13:08siunitx\num{}command? I tried defining a new command with\pdfminusON ... \pdfminusOFFbut it doesn't compile. – homocomputeris Oct 31 '18 at 13:43siunitxto be able to fix that one, but I will keep thinking. You could always accept this answer and then ask that as a new question, citing this one. – Steven B. Segletes Oct 31 '18 at 14:10