2

this is my first post, so thanks in advance for patience with me.

I have been using the "Songs" package to generate song books with chords in them. I often find it useful to use the "gtab" command to generate chord diagrams at the beginning of the song, as instructed in the manual for the package.

With these chord diagrams, I was hoping for a way to automatically insert those of the used chords at the beginning of the song, as opposed to copying and pasting the used chords' gtab definition for every song. For the example below, it would need to recognize that the G,C, and D chord are used, and then use a definition of the chord to output it before the intro and first verse. For example, the G chord being:

\gtab{G}{320033:120034} 

Also, would it be possible to for the diagrams to adjust based on transposition? Using the "\transpose" command, the output chords shown with the lyrics can be different from those in the input "[]". It would be ideal if the diagrams matched the output chords.

Here's my example:

\documentclass[letterpaper]{article}
\usepackage[chorded]{songs}
\usepackage[margin=1.25in]{geometry}

\begin{document}

\begin{songs}{}

\beginsong{I Saw the Light}[
by={Hank Williams},
sr={Isaiah 9:2}]

\gtab{G}{320033:120034} \gtab{C}{X32010:032010} \gtab{D}{X00232:000132}

\ifchorded
\beginverse*
{\nolyrics Intro: \[G] \[D] \[G]}
\endverse
\fi
\beginverse \memorize
\[G]I wandered so aimless life filled with sin
\[C]I wouldn't let my dear savior \[G]in
\[G]Then Jesus came like a stranger in the night
\[(G)]Praise the Lord \[D]I saw the \[G]light
\endverse
\beginchorus
^I saw the light I saw the light
^No more darkness no more ^night
^Now I'm so happy no sorrow in sight
^Praise the Lord ^I saw the ^light
\endchorus
\endsong

\end{songs}
\end{document}
2
  • Welcome, tdstoff! When I authored the Songs package, I wanted to add the features you describe, but there's a problem: Chords can conceivably contain arbitrary LaTeX code, making them very difficult to uniquely identify. For instance, in your document, there are "G" chords and a "(G)" chord. The Songs package has no idea these are the same chord. Similarly, it doesn't know that "G#" and "G\shrp" are equal. In fact, some songs use a different way of playing the same chord in different places. So I think this can't be completely automated. Jul 6, 2018 at 4:36
  • Hi Kevin! This makes sense, thanks for clarifying it to me. Thus far, the best I've been able to do is define my own chord diagrams in a separate input document like this: \def\C{\gtab{C}{X32010:032010}} \def\D{\gtab{D}{X00232:000132}} \def\G{\gtab{G}{320033:210034}} And then include them by putting their commands right before any verses/choruses start (in this case, \G \C \D) I'm fine with doing the little extra work of adding those commands for each individual song. However, it eliminates the possibility of using your handy \transpose command. Do you see any way around that?
    – tdstoff
    Jul 11, 2018 at 21:29

1 Answer 1

3

This cannot be completely automated in general for the following reasons:

  • Chords have many aliases, which you would have to exhaustively enumerate to get LaTeX to identify them as the same chord. For example, "G#", "G\shrp", "(G#)", "G#maj", and "Ab" might all be the same chord.

  • The mapping from chord names to tablature diagrams is not one-to-one in general, since same-named chords can have different tablature diagrams depending on context. For example, a single song can call for an "open" G chord in one place and a "barred" G chord in another place. Both of these would typically be labeled "G" but with different tablature diagrams.

However, if you are willing to manually define a unique macro name for every chord name in your document (including a unique macro for each chord alias), and if you only have one tablature diagram per chord name, then at least the transposition of said chords can be automated. The songs package has a \gtabtrans macro for this purpose, which the following code redefines to find an appropriate tablature diagram from a predefined set:

\makeatletter
\newcommand\chordlist{}
\newcommand\trychord[1]{%
  \expandafter\ifx\csname cname@\string#1\endcsname\thischord
  #1\let\do\@gobble\fi}
\renewcommand\gtabtrans[2]{{%
  \SB@dotranspose{#1}\edef\thischord{\the\SB@toks}\SB@transposefactor0
  \let\do\trychord\chordlist
  \ifx\do\trychord?\GenericError{}{Tab diagram not found for: \the\SB@toks}{}\fi
}}
\newcommand\newchord[1]{\SB@begincname\@newchord#1}
\newcommand\@newchord[3]{\SB@endcname
  \newcommand#1{#3}%
  \g@addto@macro\chordlist{\do#1}%
  \expandafter\def\csname cname@\string#1\endcsname{#2}}
\makeatother

\newchord{\myA}{A}{\gtab{A}{X02220:001230}}
\newchord{\myBb}{B\flt}{\gtab{B&}{X1333X:012340}}

\begin{document}    
\begin{songs}{}

\beginsong{Sample Song}
\beginverse
\[\myA]This should show an A chord.
\endverse
\transpose{1}
\beginverse
\[\myA]This should show a Bb chord.
\endverse
\endsong

\end{songs}
\end{document}

The \newchord macro created above expects three arguments: (1) a macro name that you will use in the document to produce the chord, (2) the name for this chord that is produced by auto-transposition, and (3) the way you want the chord to appear.

Note that argument 2 must be very precise. For example, the sample above defines \myBb using B\flt as the second argument, not B& or A#, since B\flt is the name generated by the songs package when it auto-transposes A up by one half-step. If auto-transposition yields a chord name that does not exactly match any chord you've defined, you will get an error message showing the exact chord name it was seeking.

1
  • Kevin, I was able to define chord diagrams for most of the chords I use, and it worked. This helped a lot, thank you!
    – tdstoff
    Jul 17, 2018 at 23:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .