Meter signature in text

I can propose two solutions:

\documentclass{article}

%%% solution 1
\usepackage{amsmath}
\newcommand{\setmetera}[2]{\ensuremath{\genfrac{}{}{0pt}{}{#1}{#2}}}

%%% solution 2
\newcommand{\setmeterb}[2]{\ensuremath{%
  \vcenter{\offinterlineskip
    \halign{\hfil##\hfil\cr
            $\scriptstyle#1$\cr
            \noalign{\vskip1pt}
            $\scriptstyle#2$\cr}
  }}%
}

\begin{document}
This is common time: \setmetera{4}{4}

This is a ternary time: \setmetera{3}{4}

\bigskip

This is common time: \setmeterb{4}{4}

This is a ternary time: \setmeterb{3}{4}
\end{document}

enter image description here

Some comments on the second solution

The definition of \setmeterb uses some low level TeX trickery. I use \ensuremath for being able to use \vcenter that will center the result with respect to the line (the "geometric center" will actually be slightly above the baseline).

In the \vcenter I set an alignment built with the primitive \halign, which avoids all the things LaTeX does with tabular in order to ensure equal spacing between rows, which is exactly what we don't want in this case where the two rows consist only of numbers; in particular the insertion of interline glue is disabled with \offinterlineskip. So the final trick is to set one centered column

\halign{\hfil#\hfil\cr ...}

and then add the two rows, separated by 1pt of white space. The # must actually be ## because we're using it in a definition.


I think the best way of implementing time signatures in the text is with the lilyglyphs package in combination with the fontspec package.

Here is an example:

enter image description here

The code to write this example is

\documentclass{article}

\usepackage{lilyglyphs}
\usepackage{fontspec}

\begin{document}

These are common times: \lilyTimeSignature{4}{4}, \lilyTimeSignature{2}{4}, 
\lilyTimeSignature{6}{8}

\end{document}

Make sure you compile it with XeLaTeX!


Another simple and synthetic solution it to use musicography package: it is possible to compile starting with the engine pdfLaTeX.

\documentclass[a4paper,12pt]{article}
\usepackage{musicography}
\begin{document}
This piece is written in \musMeter{4}{4} or in \textbf{\musMeter{4}{4}}.
\end{document}

enter image description here

Of course you can change the font to a more specific one.

Tags:

Symbols

Music