summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/musicography/musicography.sty
blob: 0e36b46a89f837d4ae4f1e8fed77ab6c89d4fe1c (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
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{musicography}[2020/01/29
  Symbols for music writing with pdflatex]

% Copyright 2020 Andrew A. Cashner, andrewacashner@gmail.com

% This work may be distributed and/or modified under the 
% conditions of the LaTeX Project Public License, either
% version 1.3 of this license or (at your option) any 
% later version.
% The latest version of this license is in 
%    http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% The Current Maintainer of this work is Andrew A. Cashner.
% This work consists of the package file musicography.sty
% and the documentation file musicography.tex.

% CHANGE LOG
% 2020-01-29 - Reduced stack gap for \musFig
% 2019-11-24 - Fix problem with \MeterCThreeTwo where numerals were being
%               printed next to each other instead of stacked.
% 2019-05-28 - Fix issue #1:
%               + Correct notehead symbol for values < quarter note
%                 (was hollow, should be filled)
%               + Add 32nd and 64th notes regular and dotted
%               + \musSymbol now inside an \mbox to fix alignment problems
%            - New features (some requested in issue #1)
%               + Add medieval perfect meter
%               + Add aliases for fusa (= corchea = eighth note)
%               + Replace musStack implementation with stackengine:
%                 Now takes any number of space-separated arguments to stack
%                 numerals, allowing for full figured-bass notation
% 2018-05-21 Override semantic-markup's \fl, \sh, \na commands if it is loaded
% 2017-10-31 Corrected glyph for \musHalf and documented
%              \musMeter and \musFigures
% 2017-08-29 First version on CTAN
% 2017-04-12 Created

\newif\ifLargeFont
\LargeFontfalse
\DeclareOption{bigger}{\LargeFonttrue}
\ProcessOptions\relax

\RequirePackage{xparse}

\ifLargeFont
    \newfont{\musFont}{musix13}
    \newfont{\musFontBig}{musix16}
    \newfont{\musFontLarge}{musix20}
\else
    \newfont{\musFont}{musix11}
    \newfont{\musFontBig}{musix13}
    \newfont{\musFontLarge}{musix16}
\fi

% Font for numbers in \musStack
% Could redefine to use lining figures, math mode, sans-serif, etc.
% Example for ebgaramond: \renewcommand{\musNumFont}[1]{\liningnums{#1}}
\NewDocumentCommand{\musNumFont}{}{}

% Print a music symbol from the \musFont, specifying space before, after, and
% baseline adjustment
%  #1 optional font command (default: \musFont)
%  #2 kern before    
%  #3 raisebox value 
%  #4 kern after     
%  #5 symbol code (e.g., \symbol{4}) 
\NewDocumentCommand{\musSymbol}{ O{\musFont} m m m m }{%
    \mbox{#1\kern#2\raisebox{#3}{#5}\kern#4}%
}

% Accidentals
%  #1 symbol command for accidental
\NewDocumentCommand{\musAccidental}{ m }{%
    \musSymbol[\musFontLarge]{0.1em}{0.5ex}{-0.1pt}{#1}%
}
\NewDocumentCommand{\musFlat}       {}{\musAccidental{\symbol{90}}}
\NewDocumentCommand{\musDoubleFlat} {}{\musAccidental{\symbol{91}}}
\NewDocumentCommand{\musSharp}      {}{\musAccidental{\symbol{92}}}
\NewDocumentCommand{\musDoubleSharp}{}{\musAccidental{\symbol{93}}}
\NewDocumentCommand{\musNatural}    {}{\musAccidental{\symbol{94}}}

% Shorthand accidental commands
% These commands are defined differently in the semantic-markup package,
% so LaTeX will use musicography commands instead
\@ifpackageloaded{semantic-markup}{%
    \RenewDocumentCommand{\fl}{}{\musFlat}
    \RenewDocumentCommand{\sh}{}{\musSharp}
    \RenewDocumentCommand{\na}{}{\musNatural}
}{%
    \NewDocumentCommand{\fl}{}{\musFlat}
    \NewDocumentCommand{\sh}{}{\musSharp}
    \NewDocumentCommand{\na}{}{\musNatural}
}
% Print a composite music symbol of a notehead plus stem
%  #1 Symbol musSymbol command for notehead
\NewDocumentCommand{\musStemmedNote}{ m }{%
    \musSymbol{0.05em}{0.5ex}{0.2em}{#1\musStem}%
}

% Stemmed note plus flag
%  #1 symbol command for base note
%  #2 symbol command for flag
\NewDocumentCommand{\musFlaggedNote}{ m m }{%
    \musSymbol{0.05em}{0.5ex}{0pt}{#1\musStem}%
    \musSymbol{0pt}{0pt}{0.9em}{#2}%
}

% Note plus dot
%  #1 \musSymbol command for note to be dotted
\NewDocumentCommand{\musDottedNote}{ m }{#1\musDot}

\NewDocumentCommand{\musStem}{}{%
    \musSymbol{0.955em}{0.55ex}{0pt}{\symbol{16}}%
}
\NewDocumentCommand{\musSegno}{}{%
    \musSymbol{0.55em}{-0.4ex}{1.5em}{\symbol{86}}%
}
\NewDocumentCommand{\musDot}{}{%
    \musSymbol{-0.2em}{-0.5ex}{0.7em}{\symbol{24}}%
}

\NewDocumentCommand{\musWhole}{}{%
    \musSymbol{0.05em}{0.5ex}{1.35em}{\symbol{9}}%
}
\NewDocumentCommand{\musHalf}{}{%
    \musStemmedNote{\symbol{8}}%
}
\NewDocumentCommand{\musQuarter}{}{%
    \musStemmedNote{\symbol{7}}%
}
\NewDocumentCommand{\musEighth}{}{%
    \musFlaggedNote{\symbol{7}}{\symbol{40}}%
}
\NewDocumentCommand{\musSixteenth}{}{%
    \musFlaggedNote{\symbol{7}}{\symbol{41}}%
}
\NewDocumentCommand{\musThirtySecond}{}{%
    \musFlaggedNote{\symbol{7}}{\symbol{42}}%
}
\NewDocumentCommand{\musSixtyFourth}{}{%
    \musFlaggedNote{\symbol{7}}{\symbol{43}}%
}

\NewDocumentCommand{\musWholeDotted}{}{%
    \musDottedNote{\musWhole}%
}
\NewDocumentCommand{\musHalfDotted}{}{%
    \musDottedNote{\musHalf}%
}
\NewDocumentCommand{\musQuarterDotted}{}{%
    \musDottedNote{\musQuarter}%
}
\NewDocumentCommand{\musEighthDotted}{}{%
    \musDottedNote{\musEighth}%
}
\NewDocumentCommand{\musSixteenthDotted}{}{%
    \musDottedNote{\musSixteenth}%
}
\NewDocumentCommand{\musThirtySecondDotted}{}{%
    \musDottedNote{\musThirtySecond}%
}
\NewDocumentCommand{\musSixtyFourthDotted}{}{%
    \musDottedNote{\musSixtyFourth}%
}


% Command to stack numerals for metrical symbols or figured bass
% Takes any number of space-separated arguments and stacks them vertically
\RequirePackage{stackengine}
\NewDocumentCommand{\musStack}{ O{\musNumFont} m }{%
    {#1\Shortstack[l]{#2}}%
}

% Meter symbols
%  #1 symbol code for meter sign
\NewDocumentCommand{\musSymbolMeter}{ m }{%
    \raisebox{0.58ex}[8pt][2pt]{%
        {\kern-1pt\musFontBig\raisebox{0.3ex}{#1}\kern0.3em}%
    }%
}
% Meter that combines \meterC with numerals (e.g., C3 C3/2)
\NewDocumentCommand{\meterCplus}{ m }{\meterC{}\kern-0.7pt#1}

% Numeric meter signatures (e.g., 3/4)
%  #1 number on top
%  #2 number on bottom
\NewDocumentCommand{\musMeter}{ m m }{%
    \musStack{#1 #2}\kern0.05em
}
% Same command used for figured bass
\NewDocumentCommand{\musFigFont}{}{%
    \scriptsize
    \let\musFontLarge\musFontBig
}
\NewDocumentCommand{\musFig}{ m }{%
    \setstackgap{S}{1pt}%
    \musStack[\musFigFont]{#1}%
}
\NewDocumentCommand{\noFig}{ O{5} }{%
    \hphantom{#1}%
}

\NewDocumentCommand{\meterC}{}{%
    \musSymbolMeter{\symbol{83}}%
}
\NewDocumentCommand{\meterCutC}{}{%
    \musSymbolMeter{\symbol{82}}%
}
% Ternary meters used in 16th--18th c. music
\NewDocumentCommand{\meterCThree}{}{%
    \meterCplus{\musNumFont{3}}%
}
\NewDocumentCommand{\meterCThreeTwo}{}{%
    \meterCplus{{\footnotesize\stackanchor[1pt]{3}{2}}}%
}
% Ternary meter used in 17th-century Spanish music
\NewDocumentCommand{\meterCZ}{}{%
    \meterCplus{Z}%
}
% Perfect meter in medieval music
\NewDocumentCommand{\meterO}{}{%
    $\bigcirc$
}


% Aliases for older note names
\NewDocumentCommand{\musSemibreve}         {}{\musWhole}
\NewDocumentCommand{\musMinim}             {}{\musHalf}
\NewDocumentCommand{\musSemiminim}         {}{\musQuarter}
\NewDocumentCommand{\musCorchea}           {}{\musEighth}
\NewDocumentCommand{\musFusa}              {}{\musEighth}
\NewDocumentCommand{\musSemibreveDotted}   {}{\musWholeDotted}
\NewDocumentCommand{\musMinimDotted}       {}{\musHalfDotted}
\NewDocumentCommand{\musSeminiminimDotted} {}{\musQuarterDotted}
\NewDocumentCommand{\musCorcheaDotted}     {}{\musEighthDotted}
\NewDocumentCommand{\musFusaDotted}        {}{\musEighthDotted}

\endinput