Use unicode-math character with pdfLaTex compiler

luatexpdftexunicodeunicode-mathxetex

I want to use the \squareulblack symbol (or others) from the unicode-math package, but I have to keep compiling with pdfLaTex (since the document has evolved always using this compiler and it would be a paint to now make it work with XeLaTex).

How can I do this?

Best Answer

The symbol is provided by stix2, but you probably don't want to change your fonts to the Times based STIX2 font.

In stix2.sty we find

\stix@MathSymbol{\squareulblack}{\mathord}{arrows3}{"88}
\stix@MathSymbol{\squarelrblack}{\mathord}{arrows3}{"89}

so we know that we need to find the definition of the math symbol font arrows3

\DeclareSymbolFont{arrows3}{LS2}{stix2tt}{m}{n}

so we need to declare the LS2 encoding

\DeclareFontEncoding{LS2}{}{\noaccents@}
\DeclareFontSubstitution{LS2}{stix2}{m}{n}

The \noaccents@ declaration is irrelevant for our purposes. Now we can import the symbols. However, the first attempt does not really mix with \square.

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}

\DeclareFontEncoding{LS2}{}{}
\DeclareFontSubstitution{LS2}{stix2}{m}{n}

\newcommand{\stixtwottsymbol}[1]{%
  \text{\usefont{LS2}{stix2tt}{m}{n}\symbol{#1}}%
}

\DeclareRobustCommand{\squareulblack}{%
  \mathord{% or \mathrel or \mathbin
    \stixtwottsymbol{"88}%
  }%
}
\DeclareRobustCommand{\squarelrblack}{%
  \mathord{% or \mathrel or \mathbin
    \stixtwottsymbol{"89}%
  }%
}

\begin{document}

\vrule depth 0.1pt height 0.1pt width 3pt $\squareulblack \square \squarelrblack$

\end{document}

enter image description here

The symbols are larger and don't sit on the baseline. Let's fix the issues.

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}

\DeclareFontEncoding{LS2}{}{}
\DeclareFontSubstitution{LS2}{stix2}{m}{n}

\newcommand{\stixtwottsymbol}[1]{%
  \text{%
    \settoheight{\dimen0}{$\square$}%
    \resizebox{!}{\dimen0}{%
      \raisebox{\depth}{\usefont{LS2}{stix2tt}{m}{n}\symbol{#1}}%
    }%
  }%
}

\DeclareRobustCommand{\squareulblack}{%
  \mathord{% or \mathrel or \mathbin
    \stixtwottsymbol{"88}%
  }%
}
\DeclareRobustCommand{\squarelrblack}{%
  \mathord{% or \mathrel or \mathbin
    \stixtwottsymbol{"89}%
  }%
}

\begin{document}

\vrule depth 0.1pt height 0.1pt width 3pt $\squareulblack \square \squarelrblack$

$\scriptstyle \squareulblack \square \squarelrblack$

$\scriptscriptstyle \squareulblack \square \squarelrblack$

\end{document}

The result is much better, isn't it?

enter image description here

Also the previous version scales well in the other math styles.

Related Question