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 in lualatex
...I don't know). What can be done is temporarily making -
active and redirecting it to \pdfminus
within the scope of the \active
minus. However, you can't leave it active all the time, or it screws up any calculation requiring a length or integer subtraction.
Commented
Oct 31, 2018 at 13:08
siunitx
\num{}
command? I tried defining a new command with \pdfminusON ... \pdfminusOFF
but it doesn't compile.
Commented
Oct 31, 2018 at 13:43
siunitx
to 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.
Commented
Oct 31, 2018 at 14:10