# How get \Diamond and \square with TeX Gyre Termes (or Pagella)?

How do I produce the equivalent of the symbols \square and \Diamond from amsfonts if I'm using TeX Gyre Termes or TeX Gyre Pagella?

For example, XeLaTeXing the following gives Undefined control sequence at \square (and similarly for \Diamond if the line with \square is commented out).

From http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/unicode-math/unimath-symbols.pdf, I am aware of the unicode-math symbols \enclosequare and \enclosediamond, but the former is larger than the amsfonts \square and the latter is just a rotated square rather than the slimmer amsfonts \Diamond; also, the ams symbols have leading space that the corresponding unicode-math symbols do not. (To see the differences, uncomment the line % \RequirePackage{amsfonts}.)

\documentclass{article}

\RequirePackage{fontspec}
\setmainfont[Ligatures=TeX]{TeX Gyre Termes}
\RequirePackage{unicode-math}
% Need amsmath first to avoid conflict for \dddot, etc.
\RequirePackage{amsmath}
\setmathfont{TeX Gyre Termes Math}
% Won't following overwrite def's of TeX Gyre Math symbols?
% \RequirePackage{amsfonts}

\begin{document}

$x=2$\\
$\enclosesquare$\\
$\enclosediamond$\\
$\square$\\
$\Diamond$

\end{document}


Load amssymb in advance of unicode-math.

\documentclass{article}

\usepackage{amsmath,amssymb}
\usepackage{fontspec}
\usepackage{unicode-math}

\setmainfont{TeX Gyre Termes}
\setmathfont{TeX Gyre Termes Math}

\begin{document}

$x=2 + \square + \Diamond$

\end{document}


Alternatively, use symbols available in the font:

\documentclass{article}

\usepackage{amsmath}
\usepackage{fontspec}
\usepackage{unicode-math}

\setmainfont{TeX Gyre Termes}
\setmathfont{TeX Gyre Termes Math}

\newcommand{\square}{□}    % U+25A1
\renewcommand{\Diamond}{◊} % U+25CA

\begin{document}

$x=2 + \square + \Diamond$

\end{document}


• Does including \RequirePackage{amssymb} change any symbols given by \RequirePackage{unicode-math} (or vice versa)? – murray Jul 26 '19 at 16:44
• @murray I believe that unicode-math will override the possible conflicts. The square is actually available in TeX Gyre Termes Math, but not the diamond. You can try to import them from other fonts. – egreg Jul 26 '19 at 16:46

You can use the unicode characters directly, i.e., ♢ and □ (code points U+2662 and U+25A1), by typing them in your document or by defining a \newcommand (for using the symbols in isolation) or \DeclareMathOperator (for using them as, well, math operators). See for example http://www.gust.org.pl/projects/e-foundry/tg-math/gust_e-foundry-math_fonts-presentation.pdf for the symbols that are available in this font. You can also use the original amssymb commands together with TeX Gyre Termes Math. Note that \enclosesquare and \enclosediamond are combining characters, intended to enclose the previous character in a square or diamond.

Some examples:

\documentclass{article}

\RequirePackage{fontspec}
\setmainfont[Ligatures=TeX]{TeX Gyre Termes}
\RequirePackage{unicode-math}
\RequirePackage{amsmath}
\RequirePackage{amsfonts}
\setmathfont{TeX Gyre Termes Math}

\newcommand\mydiamondsingle{♢}
\newcommand\mysquaresingle{□}
\DeclareMathOperator{\mydiamond}{♢}
\DeclareMathOperator{\mysquare}{□}

\begin{document}

$x=2$\\
$♢,\mydiamond,\Diamond,\quad x\enclosediamond$\\
$□,\mysquare,\square,\quad y\enclosesquare$\\

\end{document}


Result:

• Does including \RequirePackage{amsfonts} change any symbols given by \RequirePackage{unicode-math} (or vice versa)? – murray Jul 26 '19 at 16:44
• How did you type those actual diamond and square symbols in your code? – murray Jul 26 '19 at 16:45
• – Marijn Jul 26 '19 at 16:47
• I hadn't reallized, now that UTF-8 is the default input encoding, one could copy characters like that into .tex source. Very useful! – murray Jul 26 '19 at 19:15

The amsmath \Diamond and \square look more like \mdlgwhtlozenge and \mdlgwhtsquare, respectively. however, TeX Gyre Pagella Math does not contain \mdlgwhtsquare (as of version 1.632).

If a Unicode math font is missing a particular glyph, or you just don’t like how it looks, you can patch in the symbol from another font with the range= option of \setmathfont.

\documentclass{article}
\usepackage{amssymb}
\usepackage{unicode-math}

\defaultfontfeatures{Scale=MatchLowercase}
\setmainfont{TeX Gyre Pagella}[Ligatures=Common, Scale=1.0]
\setmathfont{TeX Gyre Pagella Math}
\setmathfont[Scale=MatchUppercase,
range={\mdlgwhtlozenge, \mdlgwhtsquare}
]{STIX Two Math}

\begin{document}

amssymb: $$x \Diamond y \square$$

Pagella with STIX Two: $$x \mdlgwhtlozenge y \mdlgwhtsquare$$
\end{document}


As of July 2019, range= doesn’t work together with version=. This mainly causes problems if you use bold math.

• I do use bold math, but just for particular letters and symbols. How does version= relate to bold math? – murray Jul 26 '19 at 21:31
• @murray unicode-math implements \boldmath and \boldsymbol by loading \setmathfont[version=bold]. This happens automatically if you load a math font that has a bold version. I think your use case should still work. – Davislor Jul 26 '19 at 21:38