17

For my thesis in musicology (somebody create that tag!) that is due this monday I need help figuring out how to achive notation of complex musical chords in Latex. I have tried every googable solution for stacking symbols in math mode and i have looked for packages that does this the right way, but alas... Lilypond is of no use either, as the chord notation there is ugly beyond belief (that being said, i love it for typesetting everything else).

Examples of my two attempts are pitiful.

\documentclass{article}

\begin{document}
C\(^{7}\dbinom{\sharp7}{\sharp5}\)

\end{document}

The first one does not format correctly at all, the second one is sort of right, but is HUMONGOUS and ugly.

What i need is what my notation program does, as seen in the bottom example.

I'm using Tufts class and lilyglyphs for musical symbols, compiling in LuaLatex.

Example

Temporary solution

\documentclass{article}
%-----------------------------------------------------------------------------
% Packages
%-----------------------------------------------------------------------------
\usepackage{fontspec}
\usepackage{lilyglyphs}
\usepackage{mathtools}
%-----------------------------------------------------------------------------
% Commands
%-----------------------------------------------------------------------------
\newcommand{\tinysharpx}[1][0.10ex]{\hspace*{#1}\sharp[scale=.7]\hspace*{#1}} % Makes some room around the symbol and scales it down to better fit stacking
\newcommand{\tinyflatx}[1][0.10ex]{\hspace*{#1}\flat[scale=.7]\hspace*{#1}}
\newcommand\bigchord[4]{\(\text{#1}^{#2}\mkern-3mu\relax(\mathop{}\limits\mkern-3mu\relax{}^{#3}_{#4})\)} % makes a four argument operator 
%-----------------------------------------------------------------------------
% Document
%-----------------------------------------------------------------------------
\begin{document}

\bigchord{C}{7}{\tinysharpx 9}{\tinysharpx 5}

\end{document}

Output

Output

Still needs fixing

1) Adjusting the lilypond symbol to become as tall as the number (as in the Sibelius example).

2) Adjusting the distance between the two stacked numbers. Needs to be a little bit tighter.

  • There, I created the "musicology" tag and added it to your posting. :-) – Mico May 29 '15 at 19:15
  • 1
    @Mico musicology? Why? – Sean Allred May 29 '15 at 19:18
  • @SeanAllred - To accommodate the OP. :-) The existing "music" tag seems too narrow to capture the posting's topic. – Mico May 29 '15 at 19:19
  • @Mico Much obliged. Musicologists need a place to geek out as well! – Buschmann May 29 '15 at 19:20
  • 1
    @Buschmann oh naturally – I wasn't saying your question wasn't welcome :) but I don't think there are a lot of typography-related distinctions between music and musicology. At the end of the day, all you're doing is engraving the notation. – Sean Allred May 29 '15 at 19:30
8

Does the following come close to what you need?

\documentclass{article}
\usepackage{fontspec}
\usepackage{lilyglyphs}
\usepackage{mathtools}

\begin{document}

C\(^{7}\hspace*{-.5ex}\binom{\sharp[scale=.6]7}{\sharp[scale=.6]5}\)

\end{document}

enter image description here

Of course the actual size of the sharps and the space between the key and the parens may depend on the actual text font.

I think it would be a good idea to create a proper parametrization and think about making proper commands for chord symbols. The question is whether this should be integrated in lilyglyphs or if we should create a new package chordsymbols.

  • I think this looks quite good, but if we are going to make a package there is quite a bit more to do. Chords have different layers of complexity and need different operators depending on said complexity. See here: i.imgur.com/crR5239.png The most complex chord needed (at least that i can think of right now) is a "supercomplex" chord with "different root". I think you would need 6 operators to handle this. \chord{Dm}{7}{#9}{#9#5}{#11b9#5}{/C}. To make it super friendly one would have to program it so that when {/C} it is the last operator regardless. It could be part of Lilyglyphs! – Buschmann May 30 '15 at 0:23
  • @Buschmann Personally I think it would be best to make a new package that detects lilyglyphs usage. If someone will provide me a real basis for syntax, I'll try my hand at the coding. There is a chatroom for this question for back/forth ideas. – Sean Allred May 30 '15 at 1:46
13

(Changed the code to work with clones of Palatino text and math fonts.)

The example below defines to helper macros named \mraise and \mtop -- short for "musicology-raise" and "musicology-atop", I suppose. The former uses two TeX "primitives" (\raise and \hbox) to raise its argument a bit less than \textsuperscript does. The latter uses still another TeX "primitive", \atop, to typeset its arguments quite compactly.

enter image description here

\documentclass{article}
\usepackage{newpxtext,newpxmath}  % set the text and math fonts
\usepackage{mleftright}  \mleftright

%% Two handy macros: \mraise and \mtop

\newcommand\mraise[1]{\raise0.6ex\hbox{\scriptsize#1}}
\newcommand\mtop[2]{$\left(\mkern-1.5mu{{#1}\atop#2}\mkern-1.5mu\right)$}

\begin{document}
C\mraise{7}\mtop{\sharp9}{\sharp5}
\end{document}

Addendum: Here's the result of the preceding clone, with the mathpazo package loaded instead of newpxtext and newpxmath, and with \left and \right in the \mtop macro replaced with \bigl and \bigr:

enter image description here


A further update, which uses LuaLaTeX, the fontspec package, the lilyglyphs font package, and three text font candidates (Computer Modern, a Times Roman clone, and a Palatino clone):

enter image description here

% !TEX TS-program = lualatex
\documentclass[preview,border=1pt]{standalone}%{article}
\usepackage{fontspec}
\usepackage{lilyglyphs}

%% Two helper macros: \mraise and \mtop
\newcommand\mraise[1]{\raise0.6ex\hbox{\scriptsize#1}}
\newcommand\mtop[2]{$\bigl(\mkern-1.5mu {{\scriptsize#1}\atop{\scriptsize#2}} \mkern-1.5mu\bigr)$}

\begin{document}

C\mraise{7}\mtop{\sharp9}{\sharp5} 

\setmainfont{XITS}
C\mraise{7}\mtop{\sharp9}{\sharp5} 

\setmainfont{TeX Gyre Pagella}
C\mraise{7}\mtop{\sharp9}{\sharp5}

\end{document}
  • Try this with \large or similar -- I think you'll find \mraise fails. Also, mtpro2 doesn't seem to come with TeX Live, at least. – Sean Allred May 29 '15 at 19:46
  • I will try this too. I use palatino -I think...- as parts of the Tufts class and lilyglyphs for musical symbols. – Buschmann May 29 '15 at 19:46
  • @Buschmann - I've changed the font family to Palatino. – Mico May 29 '15 at 19:55
  • @Mico "reason to believe..." Why not? I guess if it's only to be used in body text, this isn't too bad to manage manually. I do have to say those parens looked nice :) – Sean Allred May 29 '15 at 20:01
  • I could not get \usepackage{newpxtext,newpxmath} to work in my document, im afraid. The result is less then satisfying. i.imgur.com/RHXzA52.png I've emailed the lilyglyph creator to get an opinion on whether its possible to scale just the \sharp and \flats to make it comply. – Buschmann May 29 '15 at 20:04
11

Try this:

\documentclass{article}
\usepackage{amsmath}

\newcommand\thing[4]{$\text{#1}^{#2}\mkern-2mu\relax(\mathop{}\limits\mkern-2mu\relax{}^{#3}_{#4})$}

\begin{document}
\thing{C}{7}{\sharp 9}{\sharp 5}
\end{document}

output

  • Disclaimer: I have no idea what I'm doing with \mathop. – Sean Allred May 29 '15 at 19:24
  • Thank you for trying. The dimesions look right, but i cant get \sharp to work? EDIT: I was a idiot. Will try your new code. – Buschmann May 29 '15 at 19:29
  • @Buschmann if you tell me which package you used for that, I'll try it out. (At least, I think it's from a package. Honestly didn't try it.) – Sean Allred May 29 '15 at 19:32
  • Thank you again for your time. Many musical symbols are part of Latex, in math mode use \sharp or \flat to activate them. If you want to get fancy, i use lilyglyphs to extend the symbols package. EDIT: I see you use "ordinary" sharps. How do i adjust it so that it uses \sharp insted? – Buschmann May 29 '15 at 19:34
  • @Buschmann you should just be able to replace it in the call. – Sean Allred May 29 '15 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.