[Tex/LaTex] Vertically centering symbols and graphics inside math formulas

fontspecmath-modeunicode-mathvertical alignment

I want to use some symbols from dingbat font Dingosaurs and graphics inside math formulas. However, they are aligned to the bottom, while I want them to be vertically centered.

enter image description here

How can I do it inside both inline and centered equations?

MWE

\documentclass{article}

\usepackage{mathtools}

\usepackage{unicode-math}

\usepackage{fontspec}

\setmainfont{Dingosaurs.ttf}

\usepackage[demo]{graphicx}

\setmathfont{STIX Two Math}

\begin{document}

    $1+\text{A}=2$

    $\displaystyle1+\text{A}=2$

    \[
        1+\includegraphics[width=2cm,height=2cm]{a.png}
    \]

\end{document}

enter image description here

Best Answer

In math-mode, you can easily vertically center a picture using \vcenter{\hbox{..}}.

\documentclass{article}
\usepackage{mathtools}
\usepackage{unicode-math}
\usepackage{fontspec}
%\setmainfont{Dingosaurs.ttf}
\usepackage[demo]{graphicx}
\setmathfont{STIX Two Math}

\begin{document}

    $1+\text{A}=2$

    $\displaystyle1+\text{A}=2$
    \[
        1+\vcenter{\hbox{\includegraphics[width=2cm]{a.png}}} + 1+\text{A}=2
    \]

\end{document}

enter image description here

Related Question