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.
diagram.texand then use\input{diagram.tex}in your books can be an option? – karlkoeller Dec 22 '13 at 18:45