1

This is a follow-up to this question. The problem was that if tikz-cd is used with the command \tikzcdset{arrow style=math font} in order to make the arrow heads fit the math font, the stems of the arrow do no longer render nicely. One has to find out line width and x-height of the arrow stems in the used math font and adjust the arrows like so:

\documentclass{standalone}
\usepackage{unicode-math}
\usepackage{tikz-cd}

\setmathfont{Libertinus Math}

%%%% Adjustment for tikz-cd arrows under Libertinus Math
\tikzcdset{arrow style=math font}
\tikzcdset{every arrow/.append style={line width=0.052em}}%
\pgfmathdeclarefunction*{axis_height}{0}{%
    \begingroup%      
    \pgfmathreturn0.265em%
    \endgroup}%
%%%%

\begin{document}

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

\end{document}

Now I thought I would like to write a small package for me that contains the values of line width and axis height for my favorite math fonts that I use on a regular basis. The package should detect automatically if one of these math fonts is used and make the appropriate adjustments.

However, I have no idea how I can find out the used math font. Since I mostly use unicode-math, I would be satisfied with a solution working for unicode-math and otf.-fonts. But it would be great if one could also add support for font packages like eulervm, newtxmath and so on.

  • What happens if you open the resulting PDF, and see which fonts are embedded, in a PDF reader? –  Mar 24 '18 at 19:32
  • @RobtAll It seems I did not formulate my issue clear enough: I myself do of course know the font that I use. I need TeX to find out the font. The package should work like this: IF(math font = libertinus math) THEN (do XYZ) –  Mar 24 '18 at 19:34
  • Ah. The name of the math font is stored as an internal variable. You can look into the unicode-math code to see its variable name. Then you can do an ordinary \iftenelse test (as with package xifthen). I'd provide a better answer, but I'm sitting at a pub as I type this, and can barely think. –  Mar 24 '18 at 19:39
  • 1
    The maths font is stored in \l__um_fontname_tl. So you could use a \tl_if... to set stuff conditionally. Probably you should first test if this variable exists: if it doesn't, do nothing (or branch to non-unicode-math code); if it does, then test it against the values you want and tweak stuff if you get a match. A non-unicode-math configuration will be using multiple maths fonts, so this case would be a bit more complex to deal with. And obviously, you should provide for some kind of safe fall-back in either case. – cfr Mar 24 '18 at 20:15
  • Seems like @cfr doesn't visit the pub as often as I do. :) –  Mar 24 '18 at 20:35
  • 1
    @RobtAll :-) Or I visit quieter pubs? – cfr Mar 24 '18 at 20:49
  • Please: always provide a link to the question you are following up when asking a follow-up. This is often incredibly helpful to the people trying to help you and may help other users, too. – cfr Mar 25 '18 at 00:42

1 Answers1

1

This solution supports unicode-math only. Comments indicate where additional lines must be added to support further fonts.

\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{unicode-math}
\usepackage{tikz-cd}

\setmathfont{Libertinus Math}

% Adjustment for tikz-cd arrows under Libertinus Math
\tikzcdset{
  match-arrows/.is choice,
  % copy and adjust the next three lines for each font required other than Latin Modern Math
  match-arrows/libertinus/.style={
    match-arrows aux={0.052em}{0.265em}
  },
  % next part is standard
  match-arrows aux/.code n args=2{%
    \tikzcdset{%
      arrow style=math font,
      every arrow/.append style={line width=#1},
    }%
    \pgfmathdeclarefunction*{axis_height}{0}{%
      \begingroup
        \pgfmathreturn#2%
      \endgroup
    }%
  },
}
\ExplSyntaxOn
% create a new variable for each maths font you want to support
\tl_new:N \l_john_dorian_libertinus_tl
\tl_new:N \l_john_dorisan_lmm_tl
% set the variable to the name of the approproate font, substituting tildes for any spaces
\tl_set:Nn \l_john_dorisan_lmm_tl { Latin ~ Modern ~ Math }
\tl_set:Nn \l_john_dorian_libertinus_tl { Libertinus ~ Math}
\AtBeginDocument{
  \tl_if_exist:NT \l__um_fontname_tl
  {
    \tl_case:Nn \l__um_fontname_tl 
    {% add a line here with the variable on the left and the code which should be executed on the right in curly brackets
      \l_john_dorisan_lmm_tl  {  }
      \l_john_dorian_libertinus_tl  { \tikzcdset{ match - arrows = libertinus, } }
    }
  }
}
\ExplSyntaxOff

\begin{document}

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

\end{document}

As shown, the code produces the following arrow:

Libertinus Math arrow

If we comment out the switch to Libertinus Math, the code produces the following arrow instead:

Latin Modern Math arrow

cfr
  • 198,882