# songs package: how to store gtab definitions in an external file?

I'm using the Songs latex package. I'm currently defining the guitar fret diagrams of a chord for each song, but I'd like to define them in an external file to include them in each song (in order to not repeat myself).

How can I do this?

The diagrams and the command \gtab are explained here: http://songs.sourceforge.net/songsdoc/songs.html#sec6

but I couldn't find any useful info.

• Welcome to TeX.SX! Saving that code in a file diagram.tex and then use \input{diagram.tex} in your books can be an option? – karlkoeller Dec 22 '13 at 18:45
• Thanks, but this is not exactly what I'm looking for. I need to be able to specify different definitions inside theexternnal file, while \input just copies the whole content of the file. – fedelibre Dec 22 '13 at 19:09
• How would you decide what definitions to use? Is it feasable to create a lot of diagram.tex-files and include them as needed? – long tom Dec 22 '13 at 19:12
• I don't like this solution. How can I define a variable in Latex? – fedelibre Dec 22 '13 at 19:27

## 1 Answer

I understand that you want to create a "database" of tabs diagrams.

You could create a database with two columns, the first for the names of the chords and the second for the tab description (they will become the first and the second arguments of \gtab command).

\begin{filecontents*}{tabs.txt}
A,X02220:001230
C#sus4,4:XX3341
B&,X13331
\end{filecontents*}

\documentclass{book}
\usepackage{xparse}
\usepackage{songs}
\ExplSyntaxOn
\ior_new:N \g_fedelibre_get_tabs_ior
\prop_new:N \g_fedelibre_tabs_prop

\cs_new_protected:Npn \fedelibre_add_to_prop:w #1,#2!!
{
\prop_gput:Nnn \g_fedelibre_tabs_prop {#1} {#2}
}
\ior_open:Nn \g_fedelibre_get_tabs_ior {tabs.txt}
\ior_str_map_inline:Nn \g_fedelibre_get_tabs_ior
{
\fedelibre_add_to_prop:w #1!!
}
\DeclareDocumentCommand{ \fedetab }{ v }
{
\prop_get:NnNTF \g_fedelibre_tabs_prop {#1} \l_tmpa_tl
{
\fedelibre_gtab:nV {#1} \l_tmpa_tl
}
{
\msg_term:n {Maybe~ you~ have~ mispelled~ your~ tab!}
}
}
\cs_set_eq:NN \fedelibre_gtab:nn \gtab
\cs_generate_variant:Nn \fedelibre_gtab:nn { nV }
\ExplSyntaxOff
\begin{document}
\begin{songs}{}
\beginsong{Song}
\beginverse
\fedetab{A}  \fedetab{C#sus4} \fedetab{B&}
\[C]  \[D]  \[C]
\endverse
\endsong
\end{songs}
\end{document}


This code reads your databased and stores your entries in a property list. With the \fedetab{something} command you print the tab for the something chord. If that chord name does not exist, you receive a message.

Thanks to @egreg for having solved an expansion problem that made the code useless.