Created
November 16, 2012 15:37
-
-
Save rogerallen/4088284 to your computer and use it in GitHub Desktop.
Using TeX input mode in emacs to create & use music characters (sharp/flat) in Clojure.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(comment | |
Using ♯ and ♭ in clojure code and emacs. | |
1. To enter these glyphs in emacs, use M-x set-input-method which is | |
bound to C-x RET C-\. Enter "TeX" (Note, there are other options you | |
can use. See the docs.) | |
2. Turn this input mode on/off with C-\. | |
3. Type \sharp for ♯ and \flat for ♭. Other options include greek | |
letters, \natural for ♮, etc. | |
4. Now, Clojure/Java needs to know your text file is UTF-8. So, add | |
this to your lein project.clj: | |
:jvm-opts ["-Dfile.encoding=UTF-8"] | |
5. Enjoy using the right characters for the job. | |
This works for me on my Mac. But, one thing I already have an issue | |
with is that some chars do not show up in the italic version of my | |
Monaco font. So, they disappear in comments, which is annoying. | |
I worry that this leads to problems on other platforms. So, the | |
question is--does this work for you on your platform? | |
) | |
(def Ω 60) | |
(def pitches {:c 0 | |
:c♯ 1 :d♭ 1 | |
:d 2 | |
:d♯ 3 :e♭ 3 | |
:e 4 | |
:f 5 | |
:f♯ 6 :g♭ 6 | |
:g 7 | |
:g♯ 8 :a♭ 8 | |
:a 9 | |
:a♯ 10 :b♭ 10 | |
:b 11 | |
}) | |
(println "Check out these strings: C♯ and E♭. Even G♮") | |
(defn ▵ [κ] ;; That's \triangle and \kappa | |
(+ (pitches κ) Ω)) | |
(▵ :g♯) ;; -> 68 | |
(▵ (keyword "c♯")) ;; -> 61 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cute.