2

The proper formatting I need to use includes the line \mathsurround=2pt, but this ruins the arrow placement in tikzcd environments. Can I temporarily turn \mathsurround off, either by recovering the default behavior or else manually placing arrows in my commutative diagrams?

Here is an example of how bad the arrow placement looks with \mathsurround: Commutative square with arrow shifted to the right of their correct places

The image above was generated by the following:

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-cd}
\mathsurround=2pt

\begin{document}
  \[
    \begin{tikzcd}
      B_{\sigma} (\bar{n}_{\bullet}) \ar[r, "\mathrm{diag}"] \ar[d, "\mathbf{y}_{\mathbf{i}_{\sigma}}" left] &
      B (n_{\bullet}) \ar[d, "\mathbf{y}_{\mathbf{i}}"]
      \\
      A_0^{\mathbf{i}_{\sigma}} (\bar{n}_{\bullet}) \ar[r,  "\iota"] &
      A_0^{\mathbf{i}} (n_{\bullet})
    \end{tikzcd}
  \]
\end{document}

1 Answer 1

1

Set \mathsurround to zero at each tikz environment.

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-cd}

\setlength{\mathsurround}{30pt}
\AtBeginEnvironment{tikzcd}{\setlength{\mathsurround}{0pt}}

\begin{document}

Text $0=0$ text
\[
\begin{tikzcd}
B_{\sigma} (\bar{n}_{\bullet}) 
  \arrow[r, "\mathrm{diag}"] 
  \arrow[d, "\mathbf{y}_{\mathbf{i}_{\sigma}}" left] &
B (n_{\bullet}) \arrow[d, "\mathbf{y}_{\mathbf{i}}"]
\\
A_0^{\mathbf{i}_{\sigma}} (\bar{n}_{\bullet}) 
  \arrow[r,  "\iota"] &
A_0^{\mathbf{i}} (n_{\bullet})
\end{tikzcd}
\]
Text $0=0$ text

\end{document}

enter image description here

The value of \mathsurround has been set to a humongous value just to make it clear that the setting is resumed after the tikzcd environment.

2
  • And just to be sure, this resets the length to 2pt at the end of the tikzcd environment?
    – jackson
    May 18 at 15:40
  • 1
    @jackson Yes, I added an example with a very large value just to clearly see that the value is restored.
    – egreg
    May 18 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.