I know that \- is already used for hyphenation and inside tabbing. How can I patch this command such that it does something else, but only inside math environments? I tried the following:
\documentclass[12pt, preview]{article} % standalone, preview, varwidth=10cm
\usepackage[ngerman]{babel}
\usepackage{xparse, blindtext, etoolbox}
\usepackage{blindtext}
\let\hyphen\-\relax
\def\here{XXXXXXXXXXXX}
%\renewcommand{\-}{\relax\ifmmode(my cmd)\else\hyphen\fi\here}
%\renewrobustcmd{\-}{\relax\ifmmode(my cmd)\else\hyphen\fi\here}
\RenewDocumentCommand{\-}{}{\relax\ifmmode(my cmd)\else\hyphen\fi\here}
\begin{document}
a\-b $a\-b$
\Blindtext
\end{document}
However I observed some weird effects:
the
\renewcommandand\renewrobustcmdgenerally yield the same results, but with\RenewDocumentCommandsometimes things go out of margin.when using the
standaloneclass, weird things happen:- when using
previewoption, none of the commands work as intendent and theRenewDocumentCommandversion even throws an error! Argument of \OT1\" has an extra } - without
preview(remove blindtext) everything works as intended
- when using
What the heck is going on?
\-is robust, so a simple\let\hyphen\-won't do what you probably think. – campa Feb 21 '20 at 10:09\protect\defmeans nothing (in that place\protectis just\relax), maybe you meant\protected\def. – campa Feb 21 '20 at 10:12etoolbox'srenewrobustcmd. To be honest my knowledge of low level TeX is rather limited. – Hyperplane Feb 21 '20 at 10:19\0for the "narrow" minus. – barbara beeton Feb 22 '20 at 00:57