-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabs.tex
127 lines (112 loc) · 3.28 KB
/
tabs.tex
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
\newcounter{row}
\def\changelettercatcodes{%
\catcode`C=13
\catcode`D=13
\catcode`E=13
\catcode`F=13
\catcode`G=13
\catcode`A=13
\catcode`H=13
}
\def\changelettercatcodesback{%
\catcode`C=11
\catcode`D=11
\catcode`E=11
\catcode`F=11
\catcode`G=11
\catcode`A=11
\catcode`H=11
}
\def\changecatcodes{%
% Tunes, start of a string line
\changelettercatcodes%
%
\catcode`X=13 % to show chords above
%
\catcode`\|=11
\catcode`\~=11
\catcode`\^^M=13 % newline
\catcode`-=12
}
\def\charwidth{.65em} % width of each character in the tab
% print string tune letter
\gdef\tune#1{\raisebox{1pt}{\hbox to 10pt{\scriptsize#1\hss}}}
\gdef\notune#1{\raisebox{1pt}{\hbox to 10pt{}}}
\begingroup
\catcode`\|=11%
\catcode`\^^M=13% newline
\catcode`-=12%
\catcode`\ =12% change catcode of space to "other" to process them as characters. There can't be spaces in the following code.
\gdef\starttabchords#1^^M{\nopagebreak[4]\parindent=0pt%
\tokencycle%
{\addcytoks{\ifx-##1\phantom{\rule[.8ex]\charwidth{.5pt}}%
\else{\ifx##1|\makebar%
\else{\ifx ##1\makebox[\charwidth]{}% process space
%TODO: count characters and spaces, make letters (chords) large and before next non-space character fill the space with one box of a fitting size.
%TODO: don't require to start the chords with X
\else\makebox[\charwidth]{##1}\fi}%
\fi}\fi}}%
{\processtoks{##1}}%
{\addcytoks{##1}}%
{}% ignore spaces, space char now has catcode 12
#1\endtokencycle%
\catcode`\ =10\changelettercatcodes%
\newline}
\endgroup
\begingroup
\changecatcodes
\tracingmacros=1
\gdef\startstring#1^^M{\nopagebreak[4]\parindent=0pt%
\tokencycle%
{\addcytoks{\ifx-##1\rule[.8ex]\charwidth{.5pt}\else{%
\ifx |##1\makebar\else{%
\ifx ~##1{\raisebox{1.5pt}{\makebox[\charwidth]{\resizebox{.5em}{!}{$\sim$}\hfil}}}%
\else\makebox[\charwidth]{##1}%
\fi}\fi}\fi}}% apply above logic for char tokens (and those we declared char)
{\processtoks{##1}}% group content processing directive
{\addcytoks{##1}}% macro processing directive
{}% space processing directive
#1\endtokencycle%
\stepcounter{row}\newline}
\gdefC{\tune{\string C}\startstring}
\gdefD{\tune{\string D}\startstring}
\gdefE{\tune{\string E}\startstring}
\gdefF{\tune{\string F}\startstring}
\gdefG{\tune{\string G}\startstring}
\gdefA{\tune{\string A}\startstring}
\gdefH{\tune{\string H}\startstring}
\gdefX{\catcode`\ =12\changelettercatcodesback\notune{\string X}\starttabchords}
\endgroup
% write bar
\gdef\makebar{%
\ifnum\value{row}=0%
\rule[.8ex]{.8pt}{0ex}%
\else%
\rule[.8ex]{.8pt}{12.5pt}%
\fi}
% have to change catcodes before definition to avoid global redefinition
% of ~, | and -, and define them locally inside.
% (tune letters G, D, A, E etc. can be defined globally without possible clash)
\begingroup
\changecatcodes
\gdef\tabs#1{\pagebreak[1]%
\sbox0{$a$}% to load amsfonts/umsa.fd prior to changing catcodes to active
\begingroup%
\changecatcodes%
%
\leftskip=#1%
%
\setcounter{row}{0}%
%
\leavevmode%
%
\parindent=0pt%
\baselineskip=10pt%
\lineskiplimit=-100pt%
\lineskip=0pt%
\noindent%
\normalsize%
%\def\par{\setcounter{row}{0}}%
}
\endgroup
\gdef\endtabs{\par\pagebreak[1]\endgroup\vskip-10pt}