# Add space before \to iff preceding “[” [duplicate]

How can I automatically have a space added before \to iff there is a [ before it?

It's just that

$f\colon]a;b[\to[c;d]$


Thanks!

• I am not sure what you are trying to print.... It is awful anyway for me (not because of distances). May be a draw or something else would help. I can not imagine what you are trying to have as your output – koleygr Jan 26 '18 at 7:47
• Sorry, maybe I should have been more explicit. I want the definition of \to to include $[\to$ being automatically printed as $[~\to$ – user153484 Jan 26 '18 at 7:49
• I still want my code to be [\to due to readability.... – user153484 Jan 26 '18 at 8:02
• @egreg so slow:-) – David Carlisle Jan 26 '18 at 9:05

] is a mathclose by default but you need it to be a mathopen:
\documentclass{article}
$f\colon]a;b[\to[c;d]$
$f\colon\mathopen{]}a;b\mathclose{[}\to[c;d]$