10

The command \tikzcdset{arrow style=math font} seems to break the rendering of arrows with the package tikz-cd, whatever math font is chosen: enter image description here

\documentclass{article}
\usepackage{unicode-math}
\usepackage{tikz-cd}
\tikzcdset{arrow style=math font}

\begin{document}
    \begin{tikzcd}
        a\arrow[r]&b
    \end{tikzcd}

    \setmathfont{Libertinus Math}
    \begin{tikzcd}
        a\arrow[r]&b
    \end{tikzcd}

    \setmathfont{Latin Modern Math}
    \begin{tikzcd}
        a\arrow[r]&b
    \end{tikzcd}

    \setmathfont{STIX Two Math}
    \begin{tikzcd}
        a\arrow[r]&b
    \end{tikzcd}
\end{document}

What can be done about this?

If this is not fixable, I would also be interested in other ways to make the arrow of tikz-cd match the math font.

  • It should be \tikzcdset{arrow style=math font}, but the stem gets misplaced. – egreg Mar 14 '18 at 13:46
  • The effect is quite evident at high resolutions: picture – egreg Mar 14 '18 at 13:59
7
+50

tikz-cd assumes two things when drawing the arrows:

  1. That the line width of the arrow is the same as the width of a fraction rule, and
  2. that the arrow goes along the math axis.

Both is not true for every math font. Imho it is not possible from inside luatex to get the correct values. You would have to look at the glyph definition with e.g. font forge. The following is not perfect but shows how one can adjust the values:

\documentclass{article}
\usepackage{unicode-math}
\usepackage{tikz-cd}
\tikzcdset{arrow style=math font}

\begin{document}

    \setmathfont{Libertinus Math}

    $\frac{1}{b}\rightarrow xxx$

    \begin{tikzcd}
        a\arrow[r]&b
    \end{tikzcd}

\tikzcdset{every arrow/.append style={line width=0.52pt}}%smaller    
\pgfmathdeclarefunction*{axis_height}{0}{%
    \begingroup%      
      \pgfmathreturn2.65pt % smaller than the original
    \endgroup}% 
    \begin{tikzcd}
        a\arrow[r]&b
    \end{tikzcd}


\end{document}

enter image description here

  • Thank you very much. I also tried down arrows, they also look very good now. Could you maybe add, which the values from the glyph definition are needed, and how they must be used? – John Dorian Mar 16 '18 at 11:27
  • 1
    You need the line width and the position of the line relative to the baseline. Btw: The values naturally depend on the font size. So the code above is not meant as usable directly, only as proof of concept. – Ulrike Fischer Mar 16 '18 at 12:06
  • 1
    @UlrikeFischer I really appreciated your answer. +1 – Sebastiano Mar 17 '18 at 0:00
3

Based on the answer by Ulrike Fischer I wrote a small package which stores the values for a few commonly used fonts, namely: Libertinus Math, TeX Gyre Pagella Math, TeX Gyre Schola Math, TeX Gyre Bonum Math, STIX Two Math, Cambria Math. I thought I would share them here in case someone encounters the same problem. Maybe I will also updated the answer in case I add more fonts.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mycd}

\RequirePackage{tikz-cd}

\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{tikz-cd}}

\newcommand{\tikzcdarrowdimens}[2]{%
    \tikzcdset{every arrow/.append style={line width=#1}}%
    \pgfmathdeclarefunction*{axis_height}{0}{%
        \begingroup%      
        \pgfmathreturn#2%
        \endgroup%
    }%
}

\DeclareOption{Libertinus}{%
    \tikzcdset{arrow style=math font}%
    \tikzcdarrowdimens{0.052em}{0.250em}%
}

\DeclareOption{Pagella}{%
    \tikzcdset{arrow style=math font}%
    \tikzcdarrowdimens{0.060em}{0.250em}%
}

\DeclareOption{Schola}{%
    \tikzcdset{arrow style=math font}%
    \tikzcdarrowdimens{0.070em}{0.260em}%
}

\DeclareOption{Bonum}{%
    \tikzcdset{arrow style=math font}%
    \tikzcdarrowdimens{0.072em}{0.260em}%
}

\DeclareOption{STIX}{%
    \tikzcdset{arrow style=math font}%
    \tikzcdarrowdimens{0.068em}{0.259em}%
}

\DeclareOption{Cambria}{%
    \tikzcdset{arrow style=math font}%
    \tikzcdarrowdimens{0.06494140625em}{0.285888671875em}%
}

\ProcessOptions\relax

Basic usage is as follows:

\documentclass{article}

\usepackage{unicode-math}
\setmathfont{Libertinus Math}

\usepackage[Libertinus]{mycd}

\begin{document}
    \begin{tikzcd}
        a\arrow[r]&b
    \end{tikzcd}
\end{document}
  • How would go about adding an entry in your package for Minion Math? – msx Jul 30 '18 at 20:15
  • @msx Unfortunately, I don't own this font. – John Dorian Jul 30 '18 at 22:04
  • What would be involved if I were to do it myself? – msx Aug 1 '18 at 10:46
  • Could you add kpfonts please? – Damien L Feb 1 at 5:42

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.