1

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}

Purpose: I want these symbols to use strictly for end-of-proof and, analogously, end-of-example. I've added a proposed answer giving my solution.

4 Answers 4

5

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}

enter image description here

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}

enter image description here

2
  • Does including \RequirePackage{amssymb} change any symbols given by \RequirePackage{unicode-math} (or vice versa)?
    – murray
    Commented Jul 26, 2019 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
    Commented Jul 26, 2019 at 16:46
1

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:

enter image description here

4
1

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}

Font samples

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

2
  • I do use bold math, but just for particular letters and symbols. How does version= relate to bold math?
    – murray
    Commented Jul 26, 2019 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
    Commented Jul 26, 2019 at 21:38
0

Here is my proposed solution based upon https://tex.stackexchange.com/a/501596/13492, but with some manipulation of the glyphs for the square and diamond so as to make their appearance as end-of-proof and end-of-example, respectively, when using XeLaTeX very close to their appearance when using pdfLaTeX.

\documentclass{article}

\usepackage{amsthm} % load now to avoid openbox clash

\usepackage{iftex}
\ifTUTeX
  \usepackage{fontspec}
  \usepackage{unicode-math}
  \defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX }
  \setmainfont{TeX Gyre Termes}[Scale=1.0]
  \setmathfont{TeX Gyre Termes Math}
  \usepackage{graphicx}
   \newcommand\myDiamond{♢}
   \newcommand\mySquare{\raisebox{0.75pt}{\scalebox{0.93}{$□$}}}
   \mathchardef\timessymbol=\numexpr\times-"2000\relax
\else
  \RequirePackage[theoremfont]{newtxtext}
  \RequirePackage{newtxmath}%
  \DeclareMathAlphabet{\mathbfsf}{\encodingdefault}{\sfdefault}{bx}{n}
  \newcommand{\mySquare}{\square}
  \newcommand{\myDiamond}{\Diamond}
\fi

\renewcommand{\qed}{\quad\hbox{\qedsymbol}}% run-in QED
\renewcommand{\qedsymbol}{$\mySquare$}

\usepackage{thmtools}
%
\declaretheoremstyle[bodyfont=\mdseries\slshape]{thmstyle}
\declaretheorem[style=thmstyle,name=Theorem,numberwithin=section]{theorem}
%
\declaretheoremstyle[bodyfont=\normalfont]{exstyle}
\declaretheorem[
  style=exstyle,numberlike=theorem,
  preheadhook=\renewcommand{\qedsymbol}{$\myDiamond$}\pushQED{\qed},
  postfoothook=\popQED
  ]
{example}

\begin{document}
\section{Triangles}

\begin{theorem}
The square on the hypotenuse equals the sum of the squares on the other two sides.
\end{theorem}

\begin{proof}
Consider the following diagram\dots .
Thus
\[ a^{2} + b^{2} = c^{2}\qedhere\]
\end{proof}

\begin{example}
As a particular case, 
\[
3^{2} + 4^{2} = 5^{2}= c^{2 }\qedhere
\]
\end{example}

\end{document}

Output from pdfLaTeX:

end-of-proof and end-of-example, pdfLaTeX

Output from XeLaTeX:

end-of-proof and end-of-example, XeLaTeX

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .