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?

6
  • 1
    You could do something like \newcommand*\meter[2]{\resizebox*{!}{.7\baselineskip}{\meterfrac{#1}{#2}}} and then use \meter{4}{4} in the text. BTW: \begin{music} and \end{music} isn't actually needed here.
    – cgnieder
    Oct 19, 2012 at 13:26
  • Thanks for the tip. (You're right, I checked and environment is not needed - but it was not the reason for meter fraction to be so large.) Oct 19, 2012 at 14:29
  • btw, isn't C used for 4/4 meter? (I understand that you want a general solution, I'm just making sure that I'm not missing some point.)
    – yo'
    Oct 19, 2012 at 15:29
  • @tohecz: In my experience there is free variation between the two, as they are interchangeable.
    – Jon Purdy
    Oct 19, 2012 at 17:54
  • @tohecz C might be used, but it's less popular nowadays (though I think widely understandable) and I have never encountered this in normal text, only in notation (but I don't posses much experience in this field). Oct 19, 2012 at 22:58

5 Answers 5

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.

1
  • 2
    Many thanks, I used solution2 and it looks very nice (I didn't want the fraction to make lines separator larger). Oct 19, 2012 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!

3
  • I give you my sincere compliments.
    – Sebastiano
    Jul 7, 2020 at 11:41
  • 3
    This musical font brings back memories. While all the answers are functional, this one is beautiful. Jul 7, 2020 at 11:43
  • @StevenB.Segletes I approved your comment totally 😄.
    – Sebastiano
    Jul 7, 2020 at 11:49
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.

4
  • You can also redefine \musNumFont to change the font in \musMeter. Mar 19, 2021 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, 2021 at 21:01
  • @musarithmia: how can I use \musNumFont? I'm trying with \musNumFont{musix11} but can't compile...
    – MrT77
    Sep 9, 2022 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. Sep 12, 2022 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.

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .