summaryrefslogtreecommitdiff
path: root/graphics/gchords/gchords.sty
blob: b19655610b11bfbdcc2e84a827a8dfa4bce9cdc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
%
% GCHORDS, a LaTeX2e package to draw guitar chord diagrams.
%
% $Id: gchords.sty,v 1.20 2009/02/04 20:25:59 peekas Exp $
% 
% Copyright (C) 2001-2009 Kasper Peeters <kasper.peeters@aei.mpg.de>
% Available under the GNU General Public License.
%
%    - minor additions by D. R. Lovell, 05-nov-1998
%    - bug fixes by Yotam Medini <yotam_medini@yahoo.com>, 11-aug-2001
%    - bug fix by Brent Lievers, 23-sep-2002
%    - minor additions by P. Margarita, 14-aug-2003
%    - bug fix with f0 (thumb), thanks to Andreas Griewank, 15-jan-2005
%    - added optional open string marker, 3-feb-2008
%
% See ChangeLog for a list of changes. 
%
% The homepage for this macro package is
%
%     http://www.aei.mpg.de/~peekas/gchords/
% 
%-------------------------------------------------------------------------
% Variable, user definable stuff is below.


\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{gchords}

% Your guitar
\newcommand\strings{6}          % number of strings on your guitar
\newcommand\numfrets{5}         % length (no of frets) of a diagram

% These should be modified if you want chords in a different size
\newcommand\mediumchords{
\def\chordsize{3.0mm}    % distance between two frets (and two strings)
\font\fingerfont=cmr5    % font used for numbering fingers
\font\namefont=cmr10     % font used for labeling of the chord
\font\fretposfont=cmr7   % font used for the fret position marker
\def\dampsymbol{$\scriptstyle\times$}    % symbol of the `damp this % string' marker
\def\opensymbol{$\scriptstyle\circ$}     % symbol of the `open string' marker
}
\newcommand\smallchords{
\def\chordsize{2.0mm}    % distance between two frets (and two strings)
\font\fingerfont=cmr5    % font used for numbering fingers
\font\namefont=cmr10     % font used for labeling of the chord
\font\fretposfont=cmr7   % font used for the fret position marker
\def\dampsymbol{$\scriptstyle\times$}    % symbol of the `damp this string' marker
\def\opensymbol{$\scriptstyle\circ$}     % symbol of the `open string' marker
}

\smallchords

% Dot and line sizes (which scale with the chordsize macro)

\newcommand\fatsiz{1.6}          % size of a fat note
% Changed by Margarita
%\newcommand\lenbar{2.0}         % lenght of sixth part of barré
\newcommand\normalsiz{1.2}       % size of a normal note
\newcommand\fingsiz{1.4}         % size of the circle around a numbered finger
\newcommand\fatfingsiz{1.8}      % size of the circle around a numbered finger
\newcommand\topfretsiz{2.0pt}    % thickness of top fret

% Position of the chord in its bounding box
\newcommand\xoff{2}             % pos(\xoff,\yoff) is left lower corner of diagram
\newcommand\yoff{2}

%-------------------------------------------------------------------------
\def\@forc#1#2#3{\expandafter\f@rc\expandafter#1{#2 K}{#3}}
\def\f@@rc#1#2#3\f@@rc#4{\def#1{#2}#4\f@rc#1{#3}{#4}}

% Chords above lyrics, macro by Yotam Medini.
\newlength{\cwidth}%
\newcommand{\upchord}[1]{% 
    \settowidth{\cwidth}{#1}%
    \raisebox{\baselineskip}{#1}\hspace{-\cwidth}}

% The chord typesetting macros.
\makeatletter
\newcommand\basenote{\circle*{\fatsiz}}
% Changed by Margarita
% \newcommand\basenote{\line(1,0){\lenbar}}
\newcommand\stdnote{\circle*{\normalsiz}}
\newcommand\fingnote{\circle{\fingsiz}}
\newcommand\fatfingnote{\circle{\fatfingsiz}}
\newcommand\cvline{\line(0,1)}
\newcommand\chline{\line(1,0)}

\newcommand\chords[1]{$$\hbox{#1}$$}
\newcommand\chtext[1]{\vbox{\settowidth{\hsize}{#1 xxxx} {#1
  \ascale=\chordsize\vskip8\ascale}}}

% #1 modifiers (like num, or fretbar0)
% #2 positions
% #3 chordname

\newcount\truewidth                     % the true width of the diagram, computed from strings
\newcount\topline
\newcount\myvpos
\newcount\mylength
\def\fnum{ }                % current f{...} symbol (number of finger)
\newcount\fpos              % current p{...} value
\newcount\ghor              % string number currently being drawn
\newcount\prevpos           % previous value of p{...}, zero if no previous dot on string
\newcount\dlen              % length of the vertical line to draw between dots
\newcount\cpos              % scratch variable to hold vertical position of dot
\newcount\stpos
\newdimen\needsize
\newdimen\ascale

\newcommand\chord[3]{\vbox{\hbox{\ascale=\chordsize
\truewidth=\strings\advance\truewidth by -1
\advance\truewidth by \xoff
\topline=\numfrets
\advance\topline by \yoff
\advance\topline by 2

%%% The Diagram itself %%%%%%%%%
\unitlength\ascale
\begin{picture}(\truewidth,\topline)
\advance\topline by -1
\advance\truewidth by -\xoff
\myvpos=\yoff\advance\myvpos by \numfrets
%%% Parse the modifier string %%
\newcommand\topbar{n}
\@tfor\modstr:=#1\do 
   { \def\ttest{t}%
     \ifx\modstr\ttest{\linethickness{\topfretsiz}\put(\xoff,\myvpos){\chline{\truewidth}}\thinlines}%
     \else {\advance\topline by -1%
            \put(\xoff,\topline){\hbox to 0pt{\hss\fretposfont\modstr~}}%
           }%
     \fi%
   }
% \@tfor\modstr:=#1\do 
%    { \if\modstr t{\thicklines\put(\xoff,\myvpos){\chline{\truewidth}}\thinlines}%
%      \else {\advance\topline by -2%
%             \put(\xoff,\topline){\hbox to 0pt{\hss\fretposfont\modstr\ }}%
%            }%
%      \fi%
%    }

%%% Horizontal lines (frets)%%%%
\mylength=0
\myvpos=\yoff
\advance\myvpos by 1  % first fret starts a bit higher
\@whilenum \mylength<\numfrets \do {  
  \put(\xoff,\myvpos){\chline{\truewidth}}
  \advance\mylength by 1
  \advance\myvpos   by 1}

%%% The Dots %%%%%%%%%%%%%%%%%%%
\newcommand\fnow{n}
\newcommand\pnow{n}
\newcommand\snow{n}
\newcommand\Lnow{n}

\edef\notelabel{}

\putdots{#2}{\chordsize}
\put(\xoff,0){\hbox to \truewidth\ascale{\hss\namefont #3\hss}}
\end{picture}
}}}


\long\def\ReturnAfterFi#1\fi{\fi#1}
    \def\f@rc#1#2#3{%
      \def\temp@ty{#2}%
      \ifx\@empty\temp@ty
      \else
        \ReturnAfterFi{%
          \f@@rc#1#2\f@@rc{#3}%
        }%
      \fi
    }%

\newcommand{\putdots}[2]{
  \prevpos=0
  \fpos=0
  \ghor=\xoff
  \let\curnote\stdnote
  \let\curfing\fingnote
  \def\Ktest{K}\def\cotest{,}\def\btest{b}\def\ftest{f}
  \def\stest{s}\def\ptest{p}\def\xtest{x}\def\otest{o}\def\etest{e}\def\ntest{n}\def\Ltest{t}
  \def\attest{ }
  \@forc\thisel{#1}{
      \ifx\thisel\Ktest{}
      \else\ifx\thisel\cotest\cpos=-\fpos\advance\cpos by \numfrets\advance\cpos by \yoff
         \dlen=\cpos
         \advance\dlen by -\yoff
         \put(\ghor,\yoff){\cvline{\dlen}}
         \prevpos=0
         \fpos=0
         \def\fnum{ }
         \renewcommand\pnow{n}
         \renewcommand\fnow{n}
         \renewcommand\snow{n}
			\renewcommand\Lnow{n}
         \advance\ghor by 1
      \else\if\fnow y \edef\fnum{\thisel}\renewcommand\fnow{n}
      \else\ifx\thisel\btest\let\curnote\basenote\let\curfing\fatfingnote
      \else\ifx\thisel\ftest\renewcommand\snow{n}\renewcommand\pnow{n}\renewcommand\fnow{y}\renewcommand\Lnow{n}
      \else\ifx\thisel\stest\renewcommand\snow{y}\renewcommand\pnow{n}\renewcommand\fnow{n}\renewcommand\Lnow{n}
      \else\ifx\thisel\ptest\renewcommand\snow{n}\renewcommand\pnow{y}\renewcommand\fnow{n}\renewcommand\Lnow{n}
      \else\ifx\thisel\Ltest\renewcommand\snow{n}\renewcommand\pnow{n}\renewcommand\fnow{n}\renewcommand\Lnow{y}
      \else\ifx\thisel\xtest{\put(\ghor,\yoff){\cvline{\numfrets}}
          \needsize=\ascale
          \divide\needsize by 2
          \unitlength\needsize
          \multiply\ghor by 2
          \multiply\topline by 2
          \advance\topline by -1
          \put(\ghor,\topline){\hbox to 0pt{\hss{\dampsymbol}\hss}}}
      \else\ifx\thisel\otest{\put(\ghor,\yoff){\cvline{\numfrets}}
          \needsize=\ascale
          \divide\needsize by 2
          \unitlength\needsize
          \multiply\ghor by 2
          \multiply\topline by 2
          \advance\topline by -1
          \put(\ghor,\topline){\hbox to 0pt{\hss{\opensymbol}\hss}}}
      \else\ifx\thisel\ntest\put(\ghor,\yoff){\cvline{\numfrets}}
				 {\needsize=\ascale
				  \divide\needsize by 2
              \unitlength\needsize
              \multiply\ghor by 2
              \multiply\topline by 2
              \advance\topline by -1
              \put(\ghor,\topline){\hbox to 0pt{\hss{\notelabel}\hss}}}
              \edef\notelabel{}
      \else\if\snow y \ghor=\thisel\advance\ghor by \xoff \advance\ghor by -1
		\else\if\Lnow y \edef\notelabel{\thisel}\renewcommand\Lnow{n}
      \else\prevpos=\fpos\advance\prevpos by -1
          \fpos=\thisel
          \ifx\fnum\attest
              \put(\ghor,\yoff){\cvline{\numfrets}}
          \else
              \cpos=\fpos\advance\cpos by -1
              \ifnum\cpos > \prevpos
                   \dlen=\fpos\advance\dlen by -\prevpos
                   \advance\dlen by -2
                   \stpos=\topline \advance\stpos by -\fpos
                   \put(\ghor,\stpos){\cvline{\dlen}}
              \fi
          \fi
          \cpos=-\fpos\advance\cpos by \numfrets\advance\cpos by \yoff
             {\needsize=\ascale
              \divide\needsize by 2
              \unitlength\needsize
              \multiply\ghor by 2
              \multiply\cpos by 2
              \advance\cpos by 1
              \ifx\fnum\attest
              % Line added by Margarita
%                 \linethickness{2.0pt}
              	  \put(\ghor,\cpos){\curnote}
              \else
              	  \put(\ghor,\cpos){\curfing}
              	  \put(\ghor,\cpos){$\vcenter{\vskip 0.5em\vbox{\hbox to 0pt{\hss{\fingerfont\fnum}\hss}}}$}
              \fi}
				 {\needsize=\ascale
				  \divide\needsize by 2
              \unitlength\needsize
              \multiply\ghor by 2
              \multiply\topline by 2
              \advance\topline by -1
              \put(\ghor,\topline){\hbox to 0pt{\hss{\notelabel}\hss}}}
             \let\curnote\stdnote
             \let\curfing\fingnote
             \edef\notelabel{}
      \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi % one for each in the 'select' loop
  } % end forc loop
  \ifnum\cpos > \yoff  % draw the last bit of vertical line
     \dlen=\cpos
     \advance\dlen by -\yoff
     \put(\ghor,\yoff){\cvline{\dlen}}
  \fi
}

\makeatother

% That's all folks!
%-------------------------------------------------------------------------