sfranzen / chordbox

LaTeX package for chord diagrams
2 stars 1 forks source link

Pitch on node doesn't work properly if tuning contains a sharp #3

Open marijnschraagen opened 1 year ago

marijnschraagen commented 1 year ago

The code for @typeset pitch contains an \if conditional to find the position of the relevant element in the pitch list:

\if\stringpitch\pgfmathresult

However, this does not work when the element in the tuning list contains a sharp.

Snippet (see https://tex.stackexchange.com/questions/661722/problem-with-chordbox-and-sharps/661745)

\pgfkeys{%
/chordbox/text on node=pitch,%
/chordbox/numfrets=6,%
/chordbox/text below=pitch,%
/chordbox/text on node=pitch,%
/chordbox/tuning={"F\#","B","F\#","B","D\#","F\#"}%
}%
...
\chordbox{B6sus4}{x,0,2,0,1,0}

This can be solved by using \IfStrEq from xstring instead of a plain \if:

@typeset pitch/.code 2 args={%
    \pgfmathparse{{\cb@tuning}[#1-1]}%
    \ifnum#2=0%
        \pgfkeys{@replace symbols=\pgfmathresult}%
    \else%
        \foreach \p in {0,...,11} {%
            \pgfmathsetmacro{\stringpitch}{{\cb@pitchnames}[\p]}%
            \IfStrEq{\stringpitch}{\pgfmathresult}{%
                \pgfmathparse{{\cb@pitchnames}[mod(\p + #2, 12)]}%
                \pgfkeys{@replace symbols=\pgfmathresult}%
                \breakforeach%
            }{}%
        }%
    \fi%
}

Maybe this can be changed in the package source?