I have many overlapping paths in a drawing and they end up passing over labels (I am not opposed to paths passing over paths). How can I put the label in the foreground, but keep it positioned on the path and sloped? Is there a way to do it with layers or the backgrounds library?
For instance:
\node at (0,0) (1) {x};
\node at (2,2) (2) {y};
\node at (0,2) (3) {m};
\node at (2,0) (4) {n};
\begin{scope}[on background layer]
\draw[->] (1) -- node[midway, sloped, fill=white] {-} (2);
\draw[->] (3) -- node[near start, sloped, fill=white] {+} (4);
\end{scope}
Here, I would want the node[midway, sloped, fill=white] {-} to go into the foreground so it isn't covered by the next path.
Can this be accomplished in a way that every node is affected by some simple operation ideally? Something like usetikzlibrary{all paths in background}?

node on layerto put a node sitting on a path onto a certain layer. You could even addevery node/.append style={node on layer={front}}as option to the scope (having defined a foreground layer using\usetikzlibrary{backgrounds} \pgfdeclarelayer{front} \pgfsetlayers{main,front}). – Jasper Habicht Jul 13 '23 at 20:22$+$and$-$to get proper and equally sized plus and minus signs. – Jasper Habicht Jul 13 '23 at 20:33