CircuiTikZ American voltage signs not vertically aligned with unicode-math

circuitikzformattingtikz-pgfunicode-math

I am creating a circuit diagram, and noticed that the voltage signs are not aligned vertically.

I have manually added the red overlay to highlight the issue.
XeLaTeX code output

I used XeLaTeX through LaTeXmk, and here is the code:

\documentclass{standalone}

\usepackage{unicode-math}
\setmathfont{Latin Modern Math}

\usepackage{circuitikz}

\begin{document}
\begin{circuitikz}[american]
    \ctikzset{voltage=raised}
    \draw (0, 0) to[R=$R_1$, *-*, v=$v_1$] ++ (-2, 0);
\end{circuitikz}
\end{document} 

If I remove the unicode-math package and Latin Modern Math font, then the issue is fixed.
Code output without unicode-math
Is it possible to fix this issue within unicode-math?

Thanks for the help!

Best Answer

I found the problem: in the standard LaTeX math font, the minus sign has a box that is the same size of the plus sign, and centered. In the Latin Modern Math, the minus has a box which is asymmetric. Look at this example and test with or without unicode-math and Latin Modern Math...

% TeX program = lualatex
\documentclass{standalone}

\usepackage{unicode-math}
\setmathfont{Latin Modern Math}

\usepackage{circuitikz}

\begin{document}
\begin{tikzpicture}
    \ctikzset{voltage=raised}
    \draw (0.5,1) node[draw,red,thin,inner sep=1pt]{$-$}
            (1,1) node[draw,red,thin,inner sep=1pt]{$+$};
    \draw (0, 0) to[R=$R_1$, *-*, v=$v_1$, name=A] ++ (2, 0);
    \draw[red, opacity=0.5]  (A-Vfrom) -- (A-Vto);
    \ctikzset{voltage/american plus=$+$}
    \ctikzset{voltage/american minus=$\vphantom{+}-$}
    \draw (0, -2) to[R=$R_1$, *-*, v=$v_1$, name=B] ++ (2, 0);
    \draw[red, opacity=0.5]  (B-Vfrom) -- (B-Vto);
\end{tikzpicture}
\end{document}

With unicode-math and the Latin Modern Math:

enter image description here

Without unicode-math (look at the boxes!)

enter image description here

So the problem is that the minus sign is not centered in its box in unicode-math. I do not know if this is a feature or not, but given that circuitikz position the nodes one by one, it confounds it.

The workaround, as you see, is using:

\ctikzset{voltage/american minus=$\vphantom{+}-$}

that fixes the position of the minus sign.