5

How can I (globally in the document, I hope) change the shape of TikZ arrowheads (including those in tikzcd environments) so match the arrowheads from the TeX Gyre Terms Math font (using XeLaTeX)?

The style Straight Barb almost matches, but the ends of the barbs are different: in TeX Gyre Termes Math, the ends of the barbs are horizontal, whereas in TikZ Straight Barb heads, the ends of the bars are perpendicular to the body of the barb.

\documentclass[12pt]{article}
\usepackage[left=2.5in,right=2.5in]{geometry}

\usepackage{tikz-cd} \usetikzlibrary{arrows.meta,decorations.markings} \tikzset{ >={Straight Barb[scale=0.8]}, commutative diagrams/arrow style=tikz }

\usepackage{fontspec} \usepackage{unicode-math} \setmainfont{TeX Gyre Termes}[Scale=1.0] \defaultfontfeatures{Scale=MatchLowercase, Ligatures=TeX} \setmathfont{TeX Gyre Termes Math}

\begin{document}

\large \begin{equation} % eq 1 A \longrightarrow B \rightarrow C \end{equation} % \begin{equation} % eq 2 \begin{tikzcd} A \arrow[r,thick] {$f$} & B \end{tikzcd} \end{equation}

\end{document}

Different barb end angles, TikZ and TeX Gyre Termes Math

Related: How make TikZ arrow tips match tips of newtxmath font's arrows?

murray
  • 7,944
  • Please check TikZ & PGF manual, section Reference: Arrow Tips to see which arrows heads are available. If no one march your wish, ask some one (the best the author of arrows.meta library ) to design new arrows head. – Zarko Oct 03 '20 at 05:56
  • @Zarko: I had already looked in the manual section you cite to see if this kind of arrow tip was available, but I did not see it there. Is the author of arrows.meta somebody other than TillTantau? Contact info? (I don't see any in pgfmanual.pdf or pgfllibraryarrows.meta.code.tex) – murray Oct 04 '20 at 15:45
  • It seems that the author is Till Tantau. – Zarko Oct 04 '20 at 16:20
  • 1
    Maybe the math font option of tikz-cd is what you are looking for? – Symbol 1 Oct 16 '20 at 21:21
  • @Symbol1: Yes, that seems to do exactly what I want. (I know from the tikzcd manual that there can be issues with math font tips fitting onto arrow shanks, but I haven't found any so far with TeX Gyre Termes Math.) – murray Oct 17 '20 at 16:08
  • @Symbol1: Please make our comment an answer, so I can accept it! – murray Oct 20 '20 at 16:42

2 Answers2

6

The official solution is the math font option of tikz-cd.

\documentclass{article}

\usepackage{unicode-math} \setmathfont{texgyrepagella-math.otf}

\usepackage{tikz,tikz-cd} \tikzcdset{arrow style={math font}} \pgfmathdeclarefunction{axis_height}{0}{\begingroup\pgfmathreturn.25em\endgroup} \pgfmathdeclarefunction{rule_thickness}{0}{\begingroup\pgfmathreturn.06em\endgroup} % credit to https://tex.stackexchange.com/questions/420034/tikzcdsetarrow-style-math-font-breaks-the-rendering-of-arrows

\begin{document}

\large \begin{equation} % eq 1 A \longrightarrow B \rightarrow C \end{equation} % \begin{equation} % eq 2 \begin{tikzcd} A \arrow[r] {$f$} & B \end{tikzcd} \end{equation}

\end{document}

Symbol 1
  • 36,855
3

Try this:

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{arrows.meta,decorations.markings}

\makeatletter % based on the definition of arrow tip "Straight Barb" \pgfdeclarearrow{ name = TeX Gyre Termes Math, defaults = { %%% <<< begin of change length = +3.5pt 2, %%% <<< end of change width' = +0pt 2, line width = +0pt 1 1, }, setup code = { % Compute front miter length: \pgfmathdivide@{\pgf@sys@tonumber\pgfarrowlength}{\pgf@sys@tonumber\pgfarrowwidth}% \let\pgf@temp@quot\pgfmathresult% \pgf@x\pgfmathresult pt% \pgf@x\pgfmathresult\pgf@x% \pgf@x4\pgf@x% \advance\pgf@x by1pt% \pgfmathsqrt@{\pgf@sys@tonumber\pgf@x}% \pgf@xc\pgfmathresult\pgfarrowlinewidth% xc is front miter \pgf@xc.5\pgf@xc \pgf@xa\pgf@temp@quot\pgfarrowlinewidth% xa is extra harpoon miter % Set ends \ifpgfarrowroundjoin \pgfarrowssettipend{\pgfarrowlength\advance\pgf@x by.5\pgfarrowlinewidth} \else \pgfarrowssettipend{\pgfarrowlength\advance\pgf@x by\pgf@xc\ifpgfarrowharpoon\advance\pgf@x by\pgf@xa\fi} \fi \pgfarrowssetvisualbackend{\pgfarrowlength\advance\pgf@x by.5\pgfarrowlinewidth} \pgfarrowssetbackend{-.5\pgfarrowlinewidth} % harpoon miter correction \ifpgfarrowreversed \pgfarrowssetlineend{\pgfarrowlength\ifpgfarrowharpoon\advance\pgf@x by.5\pgfarrowlinewidth\fi} \else \pgfarrowssetlineend{\pgfarrowlength\advance\pgf@x by-.5\pgfarrowlinewidth} \fi % The hull: \ifpgfarrowroundjoin \pgfarrowshullpoint{\pgfarrowlength\advance\pgf@x by.5\pgfarrowlinewidth}{\ifpgfarrowharpoon-.5\pgfarrowlinewidth\else0pt\fi}% \else% \ifpgfarrowharpoon \pgfarrowshullpoint{\pgfarrowlength\advance\pgf@x by\pgf@xc\advance\pgf@x by\pgf@xa}{-.5\pgfarrowlinewidth}% \else \pgfarrowshullpoint{\pgfarrowlength\advance\pgf@x by\pgf@xc\advance\pgf@x by\pgf@xa}{0pt}% \fi% \fi \pgfarrowsupperhullpoint{.5\pgfarrowlinewidth}{.5\pgfarrowwidth\advance\pgf@y by.5\pgfarrowlinewidth}% \pgfarrowsupperhullpoint{-.5\pgfarrowlinewidth}{.5\pgfarrowwidth\advance\pgf@y by.5\pgfarrowlinewidth}% \ifpgfarrowharpoon \pgfarrowshullpoint{-.5\pgfarrowlinewidth}{-.5\pgfarrowlinewidth}% \fi % The following are needed in the code: \pgfarrowssavethe\pgfarrowlinewidth \pgfarrowssavethe\pgfarrowlength \pgfarrowssavethe\pgfarrowwidth }, drawing code = { \pgfsetdash{}{+0pt} \ifpgfarrowroundjoin\pgfsetroundjoin\else\pgfsetmiterjoin\fi \ifpgfarrowroundcap\pgfsetroundcap\else\pgfsetbuttcap\fi \ifdim\pgfarrowlinewidth=\pgflinewidth\else\pgfsetlinewidth{+\pgfarrowlinewidth}\fi \pgfpathmoveto{\pgfqpoint{0pt}{.5\pgfarrowwidth}} \pgfpathlineto{\pgfqpoint{\pgfarrowlength}{0pt}} \ifpgfarrowharpoon \pgfpathlineto{\pgfqpoint{\pgfarrowlength\advance\pgf@x by\ifpgfarrowreversed\else-\fi\pgfarrowlinewidth}{0pt}} \else \pgfpathlineto{\pgfqpoint{0pt}{-.5\pgfarrowwidth}} \fi \pgfusepathqstroke %%% <<< begin of change % draw two white lines \begin{pgfscope} % \pgfsetstrokecolor{red}\pgfsetstrokeopacity{0.5} % just for test \pgfsetstrokecolor{white} \pgfmathsincos{atan2(2\pgfarrowlength,\pgfarrowwidth)} \pgfmathreciprocal{\pgfmathresulty} \pgf@xa=\pgfmathresult\pgflinewidth \pgf@ya=\pgfmathresultx pt \pgf@ya=.5\pgf@ya \pgf@ya=\dimexpr.5\pgfarrowwidth-\pgf@sys@tonumber\pgf@ya\pgflinewidth+.5\pgflinewidth\relax % let w = arrow width, l = arrow length, x = line width, % and tan(.) = w/(2l) % top line = (-sin(.) x/2, w/2 + (1-cos(.)) * x/2) -- +(sin(.) * x/2, 0pt), % where -x/2 < -sin(.) * x/2 < 0 \pgfpathmoveto{\pgfqpoint{-.5\pgfarrowlinewidth}{\pgf@ya}} \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@ya}} \ifpgfarrowharpoon \else \pgfpathmoveto{\pgfqpoint{-.5\pgfarrowlinewidth}{-\pgf@ya}} \pgfpathlineto{\pgfqpoint{\pgf@xa}{-\pgf@ya}} \fi \pgfusepathqstroke \end{pgfscope} %%% <<< end of change }, parameters = { \the\pgfarrowlinewidth,% \the\pgfarrowlength,% \the\pgfarrowwidth,% \ifpgfarrowharpoon h\fi% \ifpgfarrowroundjoin j\fi% \ifpgfarrowroundcap c\fi% }, } \makeatother

\tikzset{ >={TeX Gyre Termes Math[scale=.8]} }

\tikzcdset{ arrow style=tikz, every arrow/.append style={line width=1.2pt} }

\usepackage{fontspec} \usepackage{unicode-math} \setmainfont{TeX Gyre Termes}[Scale=1.0] \defaultfontfeatures{Scale=MatchLowercase, Ligatures=TeX} \setmathfont{TeX Gyre Termes Math}

\begin{document}

\Huge \begin{equation} % eq 1 A \longrightarrow B \rightarrow C \end{equation} % \begin{equation} % eq 2 \begin{tikzcd} A \arrow[r, "f"] & B \end{tikzcd} \end{equation}

\end{document}

enter image description here enter image description here

muzimuzhi Z
  • 26,474
  • 1
    I'm getting much better results by using just \tikzcdset{arrow style=math font}, as suggested in a comment to my original post. In parrticular, your arrow heads appear to me as considerably larger than the ones in ordinary math. – murray Oct 17 '20 at 14:57
  • @murray I think in figure 1, the size of arrow head is ok. – muzimuzhi Z Oct 17 '20 at 16:17
  • You're right, the size is OK. I was still using \documentclass[12pt]{article}, which does make the arrow head too large. Which suggests your solution is not as robust as the one suggested in the comment made to use math font. – murray Oct 17 '20 at 22:29
  • @murray Yes, you are right. – muzimuzhi Z Oct 17 '20 at 23:08