[Tex/LaTex] Generating ukulele chord diagrams

diagramsmusic

I'd like to generate a chord cheatsheet for my ukulele songbook. (make this in latex : sample chords)

But all I can find are packages made for guitar chords. They are too complex and not suitable for me.

Do you have any ideas how it could be done?

Best Answer

Edit: Here is a better \drawukulelechord macro using TikZ.

  • The \drawukulelechord macro draws a ukulele chord. Its mandatory argument is a list of four numbers (for four strings) : -1 (string is not played), 0 (opened string), 1 and above (finger position for this string). The optional argument may be used to change scale (default: x=2ex and y=2ex).

  • The \defineukulelechord macro allows to associate a name (first argument) and a list to use with \drawukulelechord (second argument).

  • The \ukulelechord macro draws a named ukulele chord (predefined by \defineukulelechord).

You may uncomment or comment the line with % opened string to explicitly draw or not an opened string.

enter image description here

\documentclass{standalone}
\usepackage{etoolbox}
\usepackage{tikz}
\newcommand\drawukulelechord[2][]{%
  \edef\chord{#2}%
  \begin{tikzpicture}[x=2ex,y=2ex,line cap=round,line width=.4pt,
    baseline=(current bounding box.center),#1]
    \draw[line width=.6pt] (1,0) -- (4,0);
    \foreach \d in {1,...,4}{\draw (1,-\d) -- (4,-\d);}
    \foreach \d[count=\p] in \chord {
      \draw (\p,0) -- (\p,-4.5);
      \ifdefstring{\d}{-1}{
        \draw (\p,.25) +(-.125,-.125) -- +(.125,.125)
        +(-.125,.125) -- +(.125,-.125);
      }{
        \ifdefstring{\d}{0}{
          \draw (\p,.25) circle(.125); % opened string
        }{
          \fill (\p,.5-1*\d) circle(.25);
        }
      }
    }
    \path[use as bounding box] (0.5,.5) rectangle (4.5,-5);
  \end{tikzpicture}%
}
\makeatletter
\newcommand\defineukulelechord[2]{%
  \csdef{@ukulelechord@#1}{\drawukulelechord{#2}}%
}
\newcommand\ukulelechord[1]{%
  \ifcsdef{@ukulelechord@#1}{%
    \csuse{@ukulelechord@#1}%
  }{%
    \GenericError{}{Undefined ukulele chord '#1'}{}{}% 
  }%
}
\makeatother

\defineukulelechord{A maj}{2,1,0,0}
\defineukulelechord{A 6}{2,1,2,0}
\defineukulelechord{G sharp maj}{5,3,4,3}
\defineukulelechord{A flat maj}{5,3,4,3}
\defineukulelechord{G sharp 6}{1,3,1,3}

\begin{document}
\begin{tabular}{rcc}
                     & maj                         & 6                        \\
  A                  & \ukulelechord{A maj}        & \ukulelechord{A 6}     \\
  G$\sharp$/A$\flat$ & \ukulelechord{G sharp maj}  & \ukulelechord{G sharp 6} \\
  Test               & \drawukulelechord{-1,0,1,2} & \drawukulelechord{2,-1,-1,-1}
\end{tabular}
\end{document}