\documentclass[a4paper,final]{article}

\usepackage{listings}
\usepackage{courier}
\lstset{
	literate={≡}{{$\equiv$}}1
	, basicstyle=\ttfamily\small
	, columns=fullflexible
}
\usepackage[
    hidelinks,
    pdftitle={The mousik package},
    pdfauthor={Celia Rubio Madrigal},
    pdfsubject={Manual music notation with TikZ}
]{hyperref}
\usepackage{multicol}
\usepackage{parskip}

\usepackage{mousik}

\title{The \textsf{mousik} package\footnote{This
		document corresponds to \textsf{mousik} v0.1, dated 2026/08/24.}}
\author{Celia Rubio Madrigal\footnote{Email: \href{mailto:rubiomadrigalcelia@gmail.com}{\texttt{rubiomadrigalcelia@gmail.com}}}}
\date{August 24, 2026}

\newcommand{\TTT}[2][0]{\Text[yshift=#1]{\texttt{\textbackslash #2}}}

\usetikzlibrary{decorations.fractals,lindenmayersystems}

\begin{document}
	
	\maketitle
	
	\begin{abstract}
        \texttt{mousik} is a package for writing music in \LaTeX. It is based on TikZ and includes staves, clefs, key and time signatures, notes and chords, rests, beams and tuplets, accidentals, articulations, slurs and ties, dynamics and hairpins, and piano notation. It uses short commands and allows the user to control the position and shape of the musical elements. Everything is written directly in \LaTeX{} without an external music preprocessor.\footnote{The code is also hosted at \href{https://github.com/celrm/mousik}{https://github.com/celrm/mousik}.}
        
        \begin{center}
            \textbf{Keywords}
        \end{center}
        
        \textit{mousik, music, music theory, music notation, music writing, score, sheet, tikz diagram, bar, clef, time signature, note, symbol, rest, dot, chord, accidental, sharp, flat, natural, key}
    \end{abstract}

	\vfill
	\begin{multicols}{2}
		\tableofcontents
	\end{multicols}
	\vfill
	
	\section{Introduction}\label{intro}

    The \textsf{mousik} package renders music scores with \LaTeX{}. It is based on the \textsf{tikz} package, and the scores are treated as drawings. The package does not try to understand the music, and it does not decide how to lay out the musical elements. It provides short commands for notes, rests, beams, slurs, accidentals, articulations, etc., and lets the user change the position and shape of these elements directly. This makes it most useful for small examples.

    There are several other ways to write music with \LaTeX{}, but they generally require different programs, notations, or processing steps. \textsf{LilyPond} has its own language and program, and you may need extra tools such as \textsf{lilypond-book} or \textsf{LyLuaTeX} to include it in \LaTeX{}. As for the \textsf{abc} package, the music is written in ABC notation and converted by an external program. \textsf{MusiXTeX} works directly with TeX, but it requires very detailed score descriptions, and it also uses a second pass to calculate spacing. \textsf{PMX} makes MusiXTeX easier to write, but it uses its own notation and a conversion step.

    In comparison, \textsf{mousik} is meant to be simple, and is designed to avoid an external notation or preprocessing step.

    \section{The \texttt{mousik} environment}
	A score is drawn by means of the \texttt{mousik} environment.
	
	\begin{center}
\begin{mousik}[piano, piano-sep=2]
	\UpperStaff \Clef[octave=8] \TimeSig{4}{4}
	\Dotted{*/1,,*/3,} \Note{|-,=|,|-,=|}{1,2,3,4}
	\Note{4}{2}
	\Artic{^}{0} \Note{8}{0,1} \Tie[eshift=2]{1}
	\Barline
	\Note{1}{1}
	\Barline[t=|.]

	\LowerStaff	 \Clef[t=4]  \TimeSig{4}{4}
	\Note{2}{13/10/8} \Space[1.5]
	\Dotted{13} \Dotted{9} \Dotted{7}
	\Note{4}{13/9/7} \Space[0.5]
	\Note{8}{12/10/<9/7}
	\Tie[eshift=2]{12} 
	\Tie[bshift=0.25,eshift=1.75]{10}
	\Tie[swap,bshift=0.25,eshift=1.75]{9} 
	\Tie[swap,eshift=2]{7}
	\Barline
	\Note{1}{12/10/<9/7}
\end{mousik}
	\end{center}
	
	\begin{lstlisting}[basicstyle=\ttfamily\small]
\begin{mousik}[piano, piano-sep=2]
	\UpperStaff \Clef[octave=8] \TimeSig{4}{4}
	\Dotted{*/1,,*/3,} \Note{|-,=|,|-,=|}{1,2,3,4}
	\Note{4}{2}
	\Artic{^}{0} \Note{8}{0,1} \Tie[eshift=2]{1}
	\Barline
	\Note{1}{1}
	\Barline[t=|.]

	\LowerStaff	 \Clef[t=4]  \TimeSig{4}{4}
	\Note{2}{13/10/8} \Space[1.5]
	\Dotted{13} \Dotted{9} \Dotted{7}
	\Note{4}{13/9/7} \Space[0.5]
	\Note{8}{12/10/<9/7}
	\Tie[eshift=2]{12} 
	\Tie[bshift=0.25,eshift=1.75]{10}
	\Tie[swap,bshift=0.25,eshift=1.75]{9} 
	\Tie[swap,eshift=2]{7}
	\Barline
	\Note{1}{12/10/<9/7}
\end{mousik}
	\end{lstlisting}

	You may find longer examples in the \href{https://github.com/celrm/mousik}{GitHub repository for this package}.

It has some options:
	\begin{itemize}
		\item \textsl{indent} indents the first line. Default is 0, in cm.
		\item \textsl{length} changes the maximum width of the score. It uses the package's internal length units. One unit corresponds to 0.12\,cm (unscaled).
		\item \textsl{hsep} changes the base horizontal separation. Default is 8. It does not change \textsl{indent}, or the spacing of clefs, key signatures and time signatures.
		\item \textsl{accsep} changes the space for accidentals represented by \texttt{!}, in units of \textsl{hsep}. Default is 0.5.
		\item \textsl{barsep} changes the horizontal space around barlines, in units of \textsl{hsep}. Default is 2, which centers a barline between two gaps. 
		\item \textsl{scale} uniformly rescales the score, including symbols, text, line widths and spacing. Default is 1.
		\item \textsl{vsep} changes the vertical separation in case of an overflow. Default is 2, in cm.
		\item \textsl{single} draws a one-line staff, useful for percussion examples. Notes keep the usual absolute height system; height 6 lies on the line.
		\item \textsl{piano} draws an upper and a lower five-line staff. Use \verb|\UpperStaff| and \verb|\LowerStaff| to choose which one receives the following commands. Each staff keeps its own cursor, clef, and key.
		\item \textsl{piano-sep} changes the distance between the two piano staves. Default is 1.6, in cm.
		\item \textsl{piano-bars} chooses whether barlines in piano mode are \texttt{joined} across both staves or \texttt{separate}. Default is \texttt{joined}. The command advances only the active staff.
		\item \textsl{color} changes the background color. Default is white.
		\item \textsl{tikz} allows extra options for the outside \texttt{tikz} environment.
	\end{itemize}
	
	The package exports its commands globally with a \verb|\mousik| prefix, for example \verb|\mousikNote| and \verb|\mousikText|. Inside the \texttt{mousik} environment, the shorter forms \verb|\Note|, \verb|\Text|, etc. are local aliases.
	
	\section{Available commands}
	
	\subsection{\texttt{\textbackslash Barline}}
	The \verb|\Barline| command prints a bar on the score. It has some options:
	
	\begin{itemize}
		\item \textsl{t} (type) is the type of bar. Default is \texttt{|}, the single bar.
		\item \textsl{xshift} moves the element horizontally (x axis). Default is 0, in cm.
		\item \textsl{yshift} moves the element vertically (y axis). Default is 0, in cm.
	\end{itemize}
	
	\begin{center}
		\begin{mousik}
			\TTT{Barline}
			\Barline
			\Space[0.5]
			\Text{\ttfamily t=||}
			\Barline[t= ||]
			\Space[0.5]
			\Text{\ttfamily t=|.}
			\Barline[t= |.]
			\Space[0.5]
			\Text{\ttfamily t=|:}
			\Barline[t= |:]
			\Space[0.5]
			\Text{\ttfamily t=:|:}
			\Barline[t= :|:]
			\Space[0.5]
			\Text{\ttfamily t=:|}
			\Barline[t= :|]
			\Space[0.5]
			\Text{\ttfamily t=:}
			\Barline[t= :]
		\end{mousik}
	\end{center}
	
	Automatic overflow is the safest option after a bar or a space. Otherwise, visual errors may appear (see subsection \ref{overflow}). To start a new line explicitly, use \verb|\BreakLine|.
	
	\subsection{\texttt{\textbackslash Space}}
	The \verb|\Space| command may be used when no bar is needed, or to add extra space between symbols. Its optional argument changes the amount of space. Default is 1. One \verb|\Space| unit is two \textsl{hsep} units, i.e. the cursor advance between events. Negative values move the cursor backwards, which can also be useful to superimpose voices or place symbols manually (see subsection \ref{space}).

For finer control, there are two related commands. \verb|\NoteSpace| is measured in note units (one \textsl{hsep}). \verb|\AccSpace| is measured in accidental-gap units (one \texttt{!}).
	
	\begin{center}
		\begin{mousik}
			\Barline
			\Text{\hspace*{-55pt}\ttfamily[-0.5]}
			\Space[-0.5]
			\Barline
			\Text{\hspace*{-25pt}\ttfamily[0]}
			\Space[0]
			\Barline
			\Text{\hspace*{-14pt}\ttfamily[0.5]}
			\Space[0.5]
			\Barline
			\Text{\hspace*{-0.5pt}\ttfamily[1]}
			\Space[1]
			\Barline
			\Text{\hspace*{13pt}\ttfamily[1.5]}
			\Space[1.5]
			\Barline[t=|.]
		\end{mousik}
	\end{center}
	
	\subsubsection{\texttt{\textbackslash BreakLine}}
	The \verb|\BreakLine| command starts a new score line. It resets the horizontal cursor to the beginning of the next line. Unlike an automatic overflow, it does not print a clef or key. When \verb|\BreakLine| is used on the first line, it also determines the staff length of the following lines.
	
	
	\subsection{\texttt{\textbackslash Clef}}
	The \verb|\Clef| command may be used at any moment on the score. A clef is also printed automatically after an overflow (see subsection \ref{overflow}). It has some options:
	\begin{itemize}
		\item \textsl{octave} prints an octave eight on the clef. If it is 8, the eight is printed above the clef; if it is -8, it is printed below the clef. Default is 0.
		\item \textsl{t} (type) is the type of clef. Default is 2 (the Treble Clef).
		\item \textsl{xshift} moves the element horizontally (x axis). Default is 0, in cm.
		\item \textsl{yshift} moves the element vertically (y axis). Default is 0, in cm.
	\end{itemize}
	\begin{center}
		\begin{mousik}
			\Text{\quad\ttfamily t=1}
			\Clef[t=1]
			\Text{\quad\ttfamily t=2}
			\Clef[t=2]
			\Text{\quad\ttfamily t=3}
			\Clef[t=3]
			\Text{\quad\ttfamily t=4}
			\Clef[t=4]
			\Text{\quad\ttfamily t=11}
			\Clef[t=11]
			\Text{\quad\ttfamily t=12}
			\Clef[t=12]
			\Text{\quad\ttfamily t=13}
			\Clef[t=13]
			\Text{\quad\ttfamily t=14}
			\Clef[t=14]
			\Text{\quad\ttfamily t=15}
			\Clef[t=15]
			\Text{\quad\ttfamily t=0}
			\Clef[t=0]
			\Barline[t=|.]
		\end{mousik}
	\end{center}

	\subsection{\texttt{\textbackslash TimeSig}}
	The \verb|\TimeSig| command prints a time signature. The first argument is the upper part and the second argument is the lower part. Any number or symbol can be written in them. \texttt{C} produces a \textit{common time} symbol, and \texttt{C|} produces an \textit{alla breve} symbol.
	
	It has some options:
	\begin{itemize}
	\item \textsl{xshift} moves the element horizontally (x axis). Default is 0, in cm.
	\item \textsl{yshift} moves the element vertically (y axis). Default is 0, in cm.
	\end{itemize}
	
	\begin{center}
		\begin{mousik}
			\Clef
			\Text[xshift=-0.1]{\ttfamily\{2\}\{4\}}
			\TimeSig{2}{4}
			\Space[0.5]
			\Text[xshift=-0.1]{\ttfamily\{12\}\{8\}}
			\TimeSig{12}{8}
			\Space
			\Text[xshift=-0.1]{\ttfamily\{2+3\}\{8\}}
			\TimeSig{2+3}{8}
			\Space
			\Text[xshift=-0.3]{\ttfamily\{C\}\{\}}
			\TimeSig{C}{}
			\Space[0.5]
			\Text[xshift=-0.3]{\ttfamily\{C|\}\{\}}
			\TimeSig{C|}{}
			\Barline[t=|.]
		\end{mousik}
	\end{center}

	\subsection{Notes and rests}
	\subsubsection{\texttt{\textbackslash Note}}
The \verb|\Note| command prints notes and chords. It has two compulsory arguments: the duration and the height. The duration may be 1, 2, 4, 8, 16 or 32, and the height is absolute and in millimeters, starting from the middle C as 0. 
	\begin{center}
		\begin{mousik}\ttfamily
			\Clef
			\foreach \i in {1,2,4,8,16,32} {
				\Text[yshift=-0.5]{\i}
				\Note{\i}{5}
				\Space[-1]
				\Note[swap]{\i}{2}
			}
			\Barline[t=|.]
		\end{mousik}
	\end{center}
	
	\begin{center}
		\begin{mousik}\ttfamily
			\Clef
			\foreach \n in {0,...,9} {
				\Text{\n}
				\Note{4}{\n}
			}
			\Barline[t=|.]
		\end{mousik}
	\end{center}

The second argument may also contain heights separated by \texttt{/} to form a chord, or positions separated by commas to form a group of notes. Each position in a group may itself be a chord. To move the head of an item in a chord to the left, use \texttt{<}.

It has some options:
\begin{itemize}
\item \textsl{beam} chooses the beam width. Default is 1, in mm. 
\item \textsl{sloped} makes a beam of three or more notes follow a slope from the first note to the last instead of being horizontal.  Two-note beams are always oblique.
\item \textsl{head} chooses the type of head. Default is \texttt{.} (round), but \texttt{x} (cross) and \texttt{o} (hollow) are also possible.
\item \textsl{stem} chooses the stem height. Default is 5, in mm. By default, stems point up below height 6 and down otherwise.
\item \textsl{swap} reverses the automatic stem direction. Default is false.
\item \textsl{tuplet} prints the number of a tuplet. The number is calculated by default, but it may also be assigned. \textsl{tuplet-bracket} adds a bracket, and \textsl{tuplet-xshift} and \textsl{tuplet-yshift} move the tuplet marking.
\item \textsl{xshift} and \textsl{yshift} move the element horizontally and vertically. Default is 0, in cm.
\end{itemize}


\begin{center}
\begin{mousik}
\Clef

\Text[yshift=0]{\ttfamily \textbackslash Note\{1\}\{12/10/<9/7\}}
\Note{1}{12/10/<9/7}
\Space[1.5]
\Text[yshift=-0.5,xshift=0.5]{\ttfamily \textbackslash Note[sloped,tuplet,swap,stem=6]}
\Text[yshift=-1,xshift=0.5]{\ttfamily\{8\}\{0/4,1/5,2/6\}}
\Note[sloped,tuplet,swap,stem=6]{8}{0/4,1/5,2/6}
\Space[1.5]
\Text[yshift=0]{\ttfamily \textbackslash Note[head=x]\{16\}\{5\}}
\Note[head=x]{16}{5}
\Barline[t=|.]
\end{mousik}
\end{center}

Notes with different durations may also be joined in the same beam group. In this case the first argument is a list. \texttt{-} means an eighth note, \texttt{=} a sixteenth note and $\equiv$ a thirty-second note. A \texttt{|} may be added before or after a symbol to mark where that beam level begins or ends. The forms \texttt{//} and \texttt{///} are equivalent to \texttt{=} and $\equiv$. 

Inside a beam group, \texttt{!} inserts extra space for accidentals or dots. The extra amount is \textsl{accsep} note units, where one note unit is one \textsl{hsep}; by default \textsl{accsep}=0.5. An empty item leaves a whole \textsl{hsep} unit (usually for rests).
	\begin{center}
		\begin{mousik}
			\Clef
			
			\Space[2]
			\TTT{Note\{|$\equiv$,|=,|$\equiv$,$\equiv$|,-,$\equiv$|\}\{0,1,2,3,2,1\}}
			\Space[-2]
			\Note{|≡,|=,|≡,≡|,-,≡|}{0,1,2,3,2,1}
			
			\Barline[t=|.]
		\end{mousik}
	\end{center}

\subsubsection{\texttt{\textbackslash Rest}}\label{rest}
	The \verb|\Rest| command prints a rest. It accepts its duration as an argument: 1, 2, 4, 8, 16 or 32.
	
	It has some options:
	\begin{itemize}
		\item \textsl{multi} transforms the rest into a multimeasure rest, where the rest lasts an arbitrary amount of bars.
		\item \textsl{xshift} moves the element horizontally (x axis). Default is 0, in cm.
		\item \textsl{yshift} moves the element vertically (y axis). Default is 0, in cm.
	\end{itemize}
	
	\begin{center}
		\begin{mousik}
			\Clef
			\Text[yshift=-0.5,xshift=0.4]{\ttfamily \textbackslash Rest[multi]\{17\}}
			\Rest[multi]{17}

			\foreach \i in {1,2,4,8,16,32} {
				\Text{\ttfamily\i}
				\Rest{\i}
			}
			\Text[yshift=-0.5]{\ttfamily \textbackslash Note\{|-,,-,-|\}\{3,,3\}}
			\Text[yshift=-1]{\ttfamily \textbackslash Space[-1.5]}
			\Text[yshift=-1.5]{\ttfamily \textbackslash Rest[yshift=-0.2]\{8\}}
			\Text[yshift=-2]{\ttfamily \textbackslash Space[0.5]}
			\Note{|-,,-,-|}{3,,3}
			\Space[-1.5]
			\Rest[yshift=-0.2]{8}
			\Space[0.5]
			\Barline[t=|.]
		\end{mousik}
	\end{center}

	\subsection{Keys and accidentals}
	
	\subsubsection{\texttt{\textbackslash Acc}}\label{acc}
	The \verb|\Acc| command prints an accidental before a note. It accepts 2 arguments. The first argument is the type of accidental, from double flat to double sharp: (-2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2). The flat $\flat$ symbol can also be called with a \texttt{b} and the sharp $\sharp$ symbol can be called with \texttt{\textbackslash\#}. The second argument is the height of the symbol, which corresponds to those of the notes.
	
	It also has some options:
	\begin{itemize}
		\item \textsl{xshift} moves the element horizontally (x axis). Default is 0, in cm.
		\item \textsl{yshift} moves the element vertically (y axis). Default is 0, in cm.
	\end{itemize}
	
	\begin{center}
		\begin{mousik}
			\Clef
			\foreach \a in {-2,-1.5,...,2} {
				\Text{\texttt{\a}}
				\ifthenelse{\equal{\a}{-1}}{\Text[yshift=-0.5]{\texttt{b}}}{}
				\ifthenelse{\equal{\a}{1}}{\Text[yshift=-0.5]{\texttt{\textbackslash\#}}}{}
				\Acc{\a}{5}
				\Note{4}{5}
			}
			\Barline[t=|.]
		\end{mousik}
	\end{center}
	
	When there are several notes, the \verb|\Accs| command may be useful. It accepts as an argument a list of pairs: type/height. Where there is no accidental, the spot can be left empty. It also accepts the \textsl{xshift} and \textsl{yshift} options.
	
\begin{center}
	\begin{mousik}
		\Clef
		
		\Space[1]
		\TTT{Accs\{-2/5, ,-1/1\}}
		\TTT[-0.5]{Note\{8\}\{5,3,1\}}
		\Space[-0.5]
		\Accs{-2/5, ,-1/1}
		\Note{8}{5,3,1}

		\Space[2.5]

		\Space[0.5]
		\TTT{Accs\{,!,-2/3,\}}
		\TTT[-0.5]{Note\{|-,!,=,=|\}\{3,!,3,3\}}
		\Space[-0.5]
		\Accs{,!,-2/3,}
		\Note{|-,!,=,=|}{3,!,3,3}
		
		\Barline[t=|.]
	\end{mousik}
\end{center}

	\subsubsection{\texttt{\textbackslash Key}}
	The \verb|\Key| command prints the key at any moment on the score, although it is automatically printed with line overflows (see subsection \ref{overflow}).
	It accepts an argument: a positive whole number from 1 to 7 for sharps $\sharp$, and a negative whole number from -1 to -7 for flats $\flat$.
	
	\begin{center}
		\begin{mousik}
			\Clef
			\Text[xshift=-0.25]{\ttfamily\{-4\}}
			\Key{-4}\Barline
			\Text[xshift=-0.25]{\ttfamily\{-2\}}
			\Key{-2}\Barline
			\Text[xshift=-0.25]{\ttfamily\{2\}}
			\Key{2}\Barline
			\Text[xshift=-0.25]{\ttfamily\{4\}}
			\Key{4}\Barline[t=|.]
		\end{mousik}
	\end{center}
	
	\subsubsection{\texttt{\textbackslash NoKey}}
	The \verb|\NoKey| command cancels a key signature by printing naturals $\natural$ in the positions indicated by its argument. Positive values cancel sharps and negative values cancel flats. After \verb|\NoKey|, the key signature is zero.
	
	\begin{center}
		\begin{mousik}
			\Clef
			\Text[xshift=-0.25]{\ttfamily\{-4\}}
			\NoKey{-4}\Barline
			\Text[xshift=-0.25]{\ttfamily\{-2\}}
			\NoKey{-2}\Barline
			\Text[xshift=-0.25]{\ttfamily\{2\}}
			\NoKey{2}\Barline
			\Text[xshift=-0.25]{\ttfamily\{4\}}
			\NoKey{4}\Barline[t=|.]
		\end{mousik}
	\end{center}
	
	\subsubsection{\texttt{\textbackslash MixedKey}}
	The \verb|\MixedKey| command prints a change of key signature. It accepts two arguments: the old key signature and the new one. 
	Cancellation naturals are printed when needed. 
	
	\begin{center}
		\begin{mousik}
			\Clef
			\Key{5}
			\Note{4}{0}
			\Barline
			\Text{\ttfamily\{5\}\{2\}}
			\MixedKey{5}{2}
			\Note{4}{0}
			\Barline
			\Text{\ttfamily\{2\}\{-3\}}
			\MixedKey{2}{-3}
			\Note{4}{0}
			\Barline[t=|.]
		\end{mousik}
	\end{center}
	
	Be careful: the \verb|\Key|, \verb|\NoKey| and \verb|\MixedKey| commands are affected by the current clef. Other commands such as \verb|\Note| or \verb|\Acc| are not affected and need absolute height values.
	
	\begin{multicols}{2}
		\begin{center}
			\begin{mousik}
				\Clef[t=4]
				\Key{1}
				\TimeSig{C|}{}
				
				\Acc{0}{8}
				\Note{1}{8}
				\Barline[t=|.]
			\end{mousik}
		\end{center}
		\columnbreak
		
	\begin{lstlisting}[basicstyle=\ttfamily]
  \begin{mousik}
	\Clef[t=4]
	\Key{1}
	\TimeSig{C|}{}
	
	\Acc{0}{8}
	\Note{1}{8}
	\Barline[t=|.]
  \end{mousik}
\end{lstlisting}
	\end{multicols}
	
	\subsection{Other symbols}
	
	\subsubsection{\texttt{\textbackslash Dotted}}\label{dot}
	The \verb|\Dotted| command adds one or two dots to the following note or rest. With one note, its compulsory argument is the height of the dot, which corresponds to those of the notes. With several notes, the argument may be a list of pairs: symbols/height, where symbols can be $*$ or $**$. Where there are no dots, the spot can be left empty.
	
	It has some options:
	\begin{itemize}
		\item \textsl{t} (type) accepts $**$ or $..$ to produce 2 dots when a single height is given. The default is $*$.
		\item \textsl{xshift} moves the element horizontally (x axis). Default is 0, in cm.
		\item \textsl{yshift} moves the element vertically (y axis). Default is 0, in cm.
	\end{itemize}

	\begin{center}
		\begin{mousik}		
			\Clef
			
			\TTT{Dotted\{5\}}
			\TTT[-0.5]{Note\{4\}\{5\}}
			\Dotted{5}
			\Note{4}{5}
			
			\Space[1.75]
			
			\TTT{Dotted[t=**]\{7\}}
			\TTT[-0.5]{Rest\{8\}}
			\Dotted[t= **]{7}
			\Rest{8}
			
			\Space[3]
			
			\TTT{Dotted\{,**/3,!,\}}
			\TTT[-0.5]{Note\{|-,-,!,$\equiv$|\}\{5,2,!,3\}}
			
			\Space[-0.5]
			
			\Dotted{,**/3,!,}
			\Note{|-,-,!,≡|}{5,2,!,3}
			
			\Space[0.5]
			
			\Barline[t=|.]
		\end{mousik}
	\end{center}
	
	\subsubsection{\texttt{\textbackslash Tie}}
	
	The \verb|\Tie| command draws a tie between two notes. It has a compulsory argument, the height of both notes, and some options:
	
	\begin{itemize}
		\item \textsl{angle} changes the angle in which it is drawn. Default is 20, in degrees.
		\item \textsl{bshift} changes the starting point. Default is 0, in cm.
		\item \textsl{eshift} changes the ending point. Default is 1, in cm.
		\item \textsl{swap} prints the element upside down. Default is false, which means like a \textit{u} if the height is less than 6, and like an \textit{n} otherwise.
		\item \textsl{width} changes the line width. Default is 0.15, in mm.
		\item \textsl{xshift} moves the element horizontally (x axis). Default is 0, in cm.
		\item \textsl{yshift} moves the element vertically (y axis). Default is 0, in cm.
	\end{itemize}
	
	\begin{center}
		\begin{mousik}
			\Clef
			\TimeSig{3}{4}
			\Rest{4}
			\Space[0.5]
			\TTT{Tie[eshift=2]\{6\}}
			\Space[-0.5]
			\Note{2}{6}
			\Tie[eshift=2]{6}
			\Barline
			\Note{4}{6}
			\Rest{8}
			\Space[0.5]
			\TTT{Tie[angle=45]\{4\}}
			\Space[-0.5]
			\Note{8}{4}
			\Tie[angle=45]{4}
			\Dotted{5}
			\Note{4}{4}
			\Barline[t=|.]
		\end{mousik}
	\end{center}

	\subsubsection{\texttt{\textbackslash Slur}}
	The \verb|\Slur| command draws a slur between two consecutive notes. It accepts two compulsory arguments: the absolute heights of its beginning and end. It accepts the same options as \verb|\Tie|: \textsl{angle}, \textsl{bshift}, \textsl{eshift}, \textsl{swap}, \textsl{width}, \textsl{xshift} and \textsl{yshift}.
	
	\begin{center}
		\begin{mousik}
			\Clef
			\Space[0.5]
			\TTT{Slur\{4\}\{7\}}
			\Space[-0.5]
			\Note{4}{4}
			\Slur{4}{7}
			\Note{4}{7}
			\Barline[t=|.]
		\end{mousik}
	\end{center}
	
	\subsubsection{The \texttt{Slurred} environment}
	
	The \verb|Slurred| environment draws a slur between the notes placed inside. It has two mandatory arguments: the heights of both beginning and end notes. It accepts the same options as \verb|\Slur|: \textsl{angle}, \textsl{bshift}, \textsl{eshift}, \textsl{swap}, \textsl{width}, \textsl{xshift} and \textsl{yshift}. 
	
	
	\begin{center}
		\begin{mousik}
			\Clef
			\Note{4}{6}
			\Space[2]
			\TTT{begin \{Slurred\}\{7\}\{11\}}
			\TTT[-0.5]{foreach\textbackslash i in \{7,...,11\}\{\textbackslash Note\{4\}\{\textbackslash i\}\}}
			\TTT[-1]{end \{Slurred\}}
			\Space[-2]
			\begin{Slurred}{7}{11}
				\foreach\i in {7,...,11}{\Note{4}{\i}}
			\end{Slurred}

			\Barline[t=|.]
		\end{mousik}
	\end{center}

	\subsubsection{The \texttt{Crescendo} and \texttt{Decrescendo} environments}
	
	The \verb|Crescendo| and \verb|Decrescendo| environments draw hairpins between the notes placed inside. Their options are:
	\begin{itemize}
		\item \textsl{bopen} and \textsl{eopen} set the full opening of the hairpin at its beginning and end, in cm. A crescendo defaults to \texttt{bopen=0,eopen=0.4}. A decrescendo defaults to \texttt{bopen=0.4,eopen=0}.
		\item \textsl{bshift} and \textsl{eshift} move the beginning and ending points horizontally from the first and last heads. Defaults are 0.1 and -0.1, in cm.
		\item \textsl{width} changes the line width. Default is 0.15, in mm.
		\item \textsl{xshift} moves the hairpin horizontally. Default is 0, in cm.
		\item \textsl{yshift} moves the hairpin vertically. Default is 0, in cm.
	\end{itemize}
	
	A hairpin that continues after a line break should be written as two independent pieces. Give the first piece a chosen \textsl{eopen} and use the same value as \textsl{bopen} on the next line.
	\begin{center}
		\begin{mousik}
			\Clef \TimeSig{4}{4}
			\begin{Crescendo}[eopen=0.24]
				\Note{4}{2}\Note{4}{3}\Note{4}{4}\Note{4}{5}
			\end{Crescendo}
			\Barline

			\BreakLine
			\Clef
			\begin{Crescendo}[bopen=0.24]
				\Note{4}{5}\Note{4}{6}
			\end{Crescendo}
			\begin{Decrescendo}
				\Note{4}{5}\Note{4}{4}
			\end{Decrescendo}
			\Barline[t=|.]
		\end{mousik}
	\end{center}
	
	\newcommand{\ARTC}[2][]{
		\Text[yshift=-0.15]{\texttt{\{\ifx&#1&#2\else#1\fi\}}}
		\Artic{#2}{3}
		\Note{4}{3}
	}
	\newcommand{\ARTIC}[2][]{
		\Text[yshift=2.25]{\texttt{\{\ifx&#1&#2\else#1\fi\}}}
		\Artic{#2}{9}
		\Note{4}{9}
	}

	\subsubsection{\texttt{\textbackslash Artic} and \texttt{\textbackslash Symbol}}	
	The \verb|\Artic| command prints an articulation symbol on a successive note. It accepts two arguments. The first one is the type of articulation. The second one is the height of the symbol, which corresponds to those of the notes \textemdash but it need not be the height of the corresponding note.

	\begin{center}
	\begin{mousik}
		\Clef
		
		\Text[yshift=-0.65]{Staccato}\ARTC{.}
		\Text[yshift=2.75]{Staccatissimo}\ARTIC{'}
		\Text[yshift=-0.65]{Accent}\ARTC{>}
		\Text[yshift=2.75]{Marcato}\ARTIC[\textasciicircum]{^}
		\Text[yshift=-0.65]{Tenuto}\ARTC{-}
		\Text[yshift=2.75]{Fermata}\ARTIC{(.)}
		\Text[yshift=-0.65]{Trill}\ARTC{+}
		\Text[yshift=2.75]{Mordent}\ARTIC[$\sim$]{~}
		\Text[yshift=-0.65]{Lower mordent}\ARTC[$\sim\!|$]{~|}
		\Text[yshift=2.75]{Turn}\ARTIC{?}
		
		\Barline[t=|.]
	\end{mousik}
	
	\begin{mousik}
		\Clef
		
		\Text[yshift=2.75]{Harmonic}\ARTIC{o}
		\Space
		\Text[yshift=2.75]{Up bow}\ARTIC{v}
		\Space
		\Text[yshift=2.75]{Down bow}\ARTIC{n}
		
		\Barline[t=|.]
	\end{mousik}
\end{center}

It has some options:
\begin{itemize}
	\item \textsl{xshift} moves the element horizontally (x axis). Default is 0, in cm.
	\item \textsl{yshift} moves the element vertically (y axis). Default is 0, in cm.
	\item \textsl{swap} places the articulation on the opposite side of the note.
\end{itemize}

When there are several notes, the \verb|\Artics| command may be useful. It accepts as an argument a list of pairs: symbols/height. Where there are no symbols, the spot can be left empty. It accepts the same \textsl{xshift}, \textsl{yshift} and \textsl{swap} options.

\begin{center}
	\begin{mousik}
		\Clef
		\Space[0.5]
		\TTT{Artics\{./3, ,>/3\}}
		\TTT[-0.5]{Note\{8\}\{3,4,5\}}
		\Space[-0.5]
		\Artics{./3, ,>/3}
		\Note{8}{3,4,5}
		\Barline[t=|.]
	\end{mousik}
\end{center}

The \verb|\Symbol| command is similar to the \verb|\Artic| command, but it only accepts the type of symbol and not the height. These are symbols that have a fixed position on the score. It also accepts the \textsl{xshift} and \textsl{yshift} options.

\begin{center}
	\begin{mousik}
		\Clef
		
		\Text[yshift=-0.65]{Breath}
		\Text[yshift=-0.15]{\texttt{\{,\}}}
		\Symbol{,}\Space[1.5]
		
		\Text[yshift=-0.65]{Caesura}
		\Text[yshift=-0.15]{\texttt{\{/\}}}
		\Symbol{/}\Space[1.5]
		
		\Text[yshift=-0.65]{Segno}
		\Text[yshift=-0.15]{\texttt{\{s\textbackslash\%\}}}
		\Symbol{s\%}\Space[1.5]
		
		\Text[yshift=-0.65]{Simile}
		\Text[yshift=-0.15]{\texttt{\{\textbackslash\%\}}}
		\Symbol{\%}\Space[1.5]
		
		\Text[yshift=-0.65]{Coda}
		\Text[yshift=-0.15]{\texttt{\{o+\}}}
		\Symbol{o+}\Space[1.5]
		
		\Text[yshift=2.75]{Pedal}
		\Text[yshift=2.25]{\texttt{\{Ped\}}}
		\Symbol{Ped}\Space[1.5]
		
		\Text[yshift=2.75]{Lift Pedal}
		\Text[yshift=2.25]{\texttt{\{*\}}}
		\Symbol{*}\Space
		
		\Barline[t=|.]
	\end{mousik}
	\end{center}

	
	\subsubsection{\texttt{\textbackslash Appog}}
	The \verb|\Appog| command prints an appoggiatura before the next note. Its two arguments are its duration (4, 8, 16 or 32) and its height. 
	\verb|\Appogs| admits a list of \texttt{duration/height} pairs. Both commands accept these options:
	\begin{itemize}
	\item \textsl{scale} changes the size of the appoggiatura. Default is 1.
	\item \textsl{swap} reverses the stem direction.
	\item \textsl{before} chooses how far before the main-note it is drawn, in cm. Default is 0.5. 
	\item \textsl{xshift} and \textsl{yshift} work as expected.
	\item \textsl{slur} draws the optional appoggiatura slur and gives its angle in degrees.
	\item \textsl{to} gives the height of the main note to which the slur should attach.
	\item The slur is placed on the free side of the heads automatically. \textsl{slur-swap} reverses that choice.
	\item \textsl{slur-width} changes the slur line width; default is 0.12 mm. \textsl{slur-xshift} and \textsl{slur-yshift} move its target end, in cm.
	\end{itemize}

	\begin{center}
	\begin{mousik}
		\Clef
		\Key{-2}
		\TimeSig{3}{4}
		\Space
		\TTT{Appogs[swap,slur=30,to=9,scale=0.75]\{,,,,,8/10\}}
		\TTT[-0.5]{Note[swap,stem=6]\{16\}\{7,3,4,8,,9,8\}}
		\Space[-1]
		\Appogs[swap,slur=30,to=9,scale=0.75]{,,,,,8/10}
		\Note[swap,stem=6]{16}{7,3,4,8,,9,8}
		\Barline[t=|.]
	\end{mousik}
	\end{center}


	\subsubsection{\texttt{\textbackslash Text} and \texttt{\textbackslash Dynamics}}
	The \verb|\Text| command allows the printing of any text string. It has a compulsory argument: the text to be shown.
	The \verb|\Dynamics| command works in the same way, but uses the usual font of dynamics. Both commands accept the \textsl{xshift} and \textsl{yshift} options.
	
	\begin{center}
		\begin{mousik}
			\Clef
			\Text{C}
			{\TTT[-0.5]{Text\{C\}}}
			\Note{4}{0}
			\Space[2.5]
			\Text[yshift=2.2]{\itshape rit.}
			{\TTT{Text\{\textbackslash itshape rit.\}}}
			\Note{4}{3}
			\Space[2.5]
			{\TTT[-1.15]{Dynamics[yshift=-0.5]\{pp\}}}
			\Dynamics[yshift=-0.5]{pp}
			\Note{4}{-3}
			\Barline[t=|.]
		\end{mousik}
	\end{center}

	\subsubsection{\texttt{\textbackslash Tempo}}
The \verb|\Tempo| command prints a metronome tempo indicator. It has two arguments: the duration of the note and the numerical tempo which will be printed. It has the same options as the \verb|\Text| command. Its default position is above the staff.
\begin{center}
\begin{mousik}
	\Clef
	\Tempo{8}{120}
	{\TTT{Tempo\{8\}\{120\}}}
	\Note{4}{2}
	\Space[3]
	\Tempo{2}{60}
	{\TTT{Tempo\{2\}\{60\}}}
	\Note{4}{4}
	\Barline[t=|.]
\end{mousik}
\end{center}
	
	\section{Tips and observations} \label{errors}
	\newcommand{\sbs}[1]{\refstepcounter{subsection}\phantomsection\label{#1}\thesubsection\quad}
	\subsection*{\sbs{overflow}Overflow of lines}
	The environment has a maximum width, which may be changed with the \textsl{length} option. When the cursor reaches that width, the next element triggers an automatic overflow. This starts a new staff line and repeats the current clef and key signature. For a more predictable layout you may use \verb|\BreakLine|, add indents, change the length of spaces, or add or remove spaces for a more controlled positioning.
	
	\begin{mousik}
		\Clef
		\Key{-3}
		\TimeSig{2}{4}
		\Note{4}{2}\Note{4}{3}
		\Barline
		\Note{4}{4}\Note{4}{5}
		\Barline
		\Note{4}{6}\Note{4}{7}
		\Barline
		\Note{4}{8}\Note{4}{9}
\Barline[t=|.]
	\end{mousik}

	
	\subsection*{\sbs{space}How do spaces work?}
	
	Spaces advance an invisible cursor while the score is rendered.
	
	A negative argument moves the cursor backwards. For example, \verb|\Space[-1]| moves it back by one normal separation. A \verb|\Space| with 0 as the argument does nothing. Negative spaces can be used to superimpose voices for polyphony or to place symbols manually.
	
	The \verb|\Space| command is very relevant in this package. Because most layout logic is not implemented internally, the user may adjust each element as needed.
	
	\subsection*{\sbs{command}Using your own commands}
	\begin{multicols}{2}
		If a particular rhythm is used repeatedly in a music piece, but the commands become increasingly long and tedious, the user may want to summarize it by creating their own vocabulary.
		
		\newcommand{\ttc}[2][]{\Note[#1]{|-,|=,=|}{#2}}
		\newcommand{\tct}[2][]{\Note[#1]{|=,=|,-|}{#2}}
		\begin{mousik}
			\Clef
			\ttc{7,8,9}
			\tct{10,9,8}
			\Barline[t= |.]
		\end{mousik}
	\end{multicols}
	
	
	\begin{lstlisting}
	\newcommand{\ttc}[2][]{\Note[#1]{|-,|=,=|}{#2}}
	\newcommand{\tct}[2][]{\Note[#1]{|=,=|,-|}{#2}}
	
	\begin{mousik}
		\Clef
		\ttc{7,8,9}
		\tct{10,9,8}
		\Barline[t= |.]
	\end{mousik}
	\end{lstlisting}
	
	\subsection*{\sbs{tikz}Working with the \textsf{tikz} package}
	The \textsf{mousik} package is based on the \textsf{tikz} package. In fact, the \texttt{mousik} environment is a disguised version of a \texttt{tikzpicture} environment, but with some initialized variables and a printed staff.
	
	This implies two separate things:
	\begin{enumerate}
		\item Other commands may also be used inside the mousik environment, not just the commands explained in this text. For example, one may draw nodes, lines, or even a fractal behind my score:
	
	\begin{mousik}
		\Clef
		\Key{-3}
		\TimeSig[xshift=0.25]{C}{}
		
		\Rest{8}
		\Accs{,0/6}
		\Note{16}{7,6}
		\Note{8}{7,4}
		\Note{-,|=,=|}{5,7,6}
		\Note{8}{7,8}
		\Barline
		
		\begin{scope}[xshift=9cm,rotate=180]
			\draw [l-system={rule set={F -> F-F++F-F}, step=2pt, angle=60,
				axiom=F, order=4}] lindenmayer system;
		\end{scope}
	\end{mousik}
	

	\item The commands explained here may be used in a \texttt{tikzpicture} environment, and will appear with no staff. However, the command \verb|\mousikInit| should be used at the beginning to avoid initialization errors.
	
	\begin{tikzpicture}
		\mousikInit
		\Clef
		\Key{-3}
		\TimeSig[xshift=0.25]{C}{}
		
		\Rest{8}
		\Accs{,0/6}
		\Note{16}{7,6}
		\Note{8}{7,4}
		\Note{-,|=,=|}{5,7,6}
		\Note{8}{7,8}
		\Barline
		
	\end{tikzpicture}
	\end{enumerate}


	\section{Notes from the author}
	This package was developed almost entirely in the summer of 2020. It succeeds a smaller music notation package that I had developed in 2019 for twelve-tone music notation (\href{https://github.com/celrm/ddphonism}{ddphonism}). 
	
	Back then, the hand-made computational geometry became very cumbersome, and some important features had display errors that were difficult to fix by hand (for instance, the placement of slurs, de/crescendos, and mixed keys). In 2026, generative AI tools were advanced enough to work through the remaining list of to-dos under my supervision.

	The code relies on the \textsf{tikz} package for rendering, and the \textsf{musixtex} and \textsf{harmony} packages for musical symbols. The package is still in early development, so behavior may change in the future. I welcome any suggestions for improvement.
	
\end{document}
	
	
