15

I want to mention musical piece meter directly in the text, like:

This piece is written in 4/4.

Is there a way to get time signature (4/4) in form of fraction with no fraction bar? I tried musixtex package but when I do:

\begin{music}\meterfrac44\end{music}

The fraction is much bigger than the rest of the text. Of course I can try to make it smaller to fit the text but maybe there's a simpler way to do this?

5 Answers5

18

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.

egreg
  • 1,121,712
  • 2
    Many thanks, I used solution2 and it looks very nice (I didn't want the fraction to make lines separator larger). – nuoritoveri Oct 19 '12 at 14:31
12

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!

Manza
  • 152
5

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.

Sebastiano
  • 54,118
  • You can also redefine \musNumFont to change the font in \musMeter. – musarithmia Mar 19 '21 at 16:12
  • @musarithmia Hi, and thank you very much for your feedback and the suggestion...You are authorized to edit my answer. Don't worry with me :-)....My best regards. – Sebastiano Mar 19 '21 at 21:01
  • @musarithmia: how can I use \musNumFont? I'm trying with \musNumFont{musix11} but can't compile... – MrT77 Sep 09 '22 at 17:22
  • The argument to \musNumFont should be a complete LaTeX font command, like \fontfamily{musix11}\selectfont. I haven't tried using musix11 for the numerals and would be curious to know if it works. – musarithmia Sep 12 '22 at 21:25
3

A lightweight solution is ${}^{4}_{4}$ which renders as

4/4 time signature

The initial {} captures that the following exponent and subscript are anchored to a blank.

1

With MusiXTeX, I defined a command to do it (needs to be improved, but works):

\NewDocumentCommand{\textmeter}{m m O{1.0} O{-3.0pt} O{0pt}}{%
    \adjustbox{scale=#3, raise=#4, margin=0pt 0pt 0pt 0pt, frame=#5}{%
    \setbox\toks@box\vbox{\hbox{\twelvebf#1}%
    \hbox{\twelvebf#2}}\vbox\@to15.5pt{\offinterlineskip
    \hbox\@to\wd\toks@box{\hfill\twelvebf#1\hfill}
    \hbox\@to\wd\toks@box{\hfill\twelvebf#2\hfill}}}%
}

You can use it as:

Some text \textmeter{2}{4} more text...

You can also check the \notesintext command in the MusiXTeX documentation.