> ## Documentation Index
> Fetch the complete documentation index at: https://resources.latex-cloud-studio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Music Notation

> Master music notation in LaTeX. Learn musical symbols, notes, chord notation, and how to create professional music scores and examples.

export const RenderedOutput = ({title = "Rendered output", ctaHref, ctaLabel = "Open LaTeX Cloud Studio", children}) => {
  const [isExpanded, setIsExpanded] = useState(false);
  const trackEditorCta = () => {
    const target = new URL(ctaHref, window.location.href);
    globalThis.posthog?.capture?.("docs_app_cta_clicked", {
      source_page: window.location.pathname,
      source_section: "rendered_output",
      cta_variant: "first_compiled_example",
      target_url: target.toString(),
      target_utm_source: target.searchParams.get("utm_source"),
      target_utm_medium: target.searchParams.get("utm_medium"),
      target_utm_campaign: target.searchParams.get("utm_campaign"),
      target_utm_content: target.searchParams.get("utm_content")
    }, {
      transport: "sendBeacon",
      send_instantly: true
    });
  };
  return <details className="rendered-output" onToggle={event => setIsExpanded(event.currentTarget.open)}>
      <summary className="rendered-output__summary">
        <span className="rendered-output__title">{title}</span>
        <span className="rendered-output__hint" aria-hidden="true">View compiled result</span>
      </summary>
      {isExpanded && <div className="rendered-output__content">
          {children}
          {ctaHref && <aside className="rendered-output__cta" aria-label="Continue in the LaTeX editor">
              <span>
                <strong>Ready to use this syntax?</strong>
                Continue in the browser editor when you want to adapt the example in a real project.
              </span>
              <a href={ctaHref} onClick={trackEditorCta}>{ctaLabel}<span aria-hidden="true"> →</span></a>
            </aside>}
        </div>}
    </details>;
};

export const LatexSource = ({filename, source}) => {
  const [copyStatus, setCopyStatus] = useState("Copy");
  const copySource = async () => {
    try {
      await navigator.clipboard.writeText(source);
      setCopyStatus("Copied");
    } catch {
      setCopyStatus("Select and copy");
    }
  };
  return <figure className="latex-source">
      <figcaption className="latex-source__header">
        <span className="latex-source__filename">{filename}</span>
        <button type="button" className="latex-source__copy" onClick={copySource} aria-live="polite">
          {copyStatus}
        </button>
      </figcaption>
      <pre className="latex-source__pre" aria-label={`LaTeX source: ${filename}`} tabIndex="0">
        <code className="language-latex">{source}</code>
      </pre>
    </figure>;
};

export const LatexPreview = ({src, alt, caption, width, height}) => {
  const minZoom = 1;
  const maxZoom = 3;
  const zoomStep = 0.5;
  const measureSvgContent = async (assetSrc, pageWidth, pageHeight) => {
    const cacheKey = "__latexCloudSvgContentBoxCache";
    const contentBoxCache = globalThis[cacheKey] ?? new Map();
    globalThis[cacheKey] = contentBoxCache;
    if (contentBoxCache.has(assetSrc)) return contentBoxCache.get(assetSrc);
    const measurement = (async () => {
      const assetUrl = new URL(assetSrc, window.location.href);
      if (assetUrl.origin !== window.location.origin) {
        throw new Error("Rendered output must use a same-origin SVG asset.");
      }
      const response = await fetch(assetUrl, {
        credentials: "same-origin"
      });
      if (!response.ok) throw new Error(`Rendered output request failed with ${response.status}.`);
      const source = await response.text();
      const documentNode = new DOMParser().parseFromString(source, "image/svg+xml");
      if (documentNode.querySelector("parsererror")) throw new Error("Rendered output is not valid SVG.");
      const sourceSvg = documentNode.documentElement;
      sourceSvg.querySelectorAll("script, foreignObject").forEach(node => node.remove());
      [sourceSvg, ...sourceSvg.querySelectorAll("*")].forEach(node => {
        [...node.attributes].forEach(attribute => {
          if ((/^on/i).test(attribute.name)) node.removeAttribute(attribute.name);
          if ((attribute.name === "href" || attribute.name === "xlink:href") && !attribute.value.startsWith("#")) {
            node.removeAttribute(attribute.name);
          }
        });
      });
      const measurementHost = document.createElement("div");
      measurementHost.className = "latex-preview__measurement-host";
      const measuredSvg = document.importNode(sourceSvg, true);
      measuredSvg.setAttribute("aria-hidden", "true");
      measurementHost.appendChild(measuredSvg);
      document.body.appendChild(measurementHost);
      try {
        const measuredElements = [...measuredSvg.children].filter(node => !["defs", "desc", "metadata", "style", "title"].includes(node.tagName.toLowerCase()));
        const elementBounds = measuredElements.map(node => node.getBBox()).filter(box => [box.x, box.y, box.width, box.height].every(Number.isFinite) && box.width > 0 && box.height > 0);
        if (elementBounds.length === 0) {
          throw new Error("Rendered output has no measurable visible content.");
        }
        const sortedBounds = [...elementBounds].sort((left, right) => left.y - right.y);
        const clusterGap = pageHeight * 0.045;
        const clusters = [];
        sortedBounds.forEach(box => {
          const current = clusters[clusters.length - 1];
          if (!current || box.y - current.bottom > clusterGap) {
            clusters.push({
              boxes: [box],
              bottom: box.y + box.height
            });
            return;
          }
          current.boxes.push(box);
          current.bottom = Math.max(current.bottom, box.y + box.height);
        });
        const contentClusters = clusters.filter(cluster => {
          const clusterBox = cluster.boxes.reduce((combined, box) => {
            const right = Math.max(combined.x + combined.width, box.x + box.width);
            const bottom = Math.max(combined.y + combined.height, box.y + box.height);
            const x = Math.min(combined.x, box.x);
            const y = Math.min(combined.y, box.y);
            return {
              x,
              y,
              width: right - x,
              height: bottom - y
            };
          });
          const centerY = clusterBox.y + clusterBox.height / 2;
          const isMarginFurniture = cluster.boxes.length <= 2 && clusterBox.width < pageWidth * 0.2 && clusterBox.height < pageHeight * 0.04 && (centerY < pageHeight * 0.08 || centerY > pageHeight * 0.8);
          return !isMarginFurniture;
        });
        const visibleBounds = (contentClusters.length > 0 ? contentClusters : clusters).flatMap(cluster => cluster.boxes);
        const bounds = visibleBounds.reduce((combined, box) => {
          const right = Math.max(combined.x + combined.width, box.x + box.width);
          const bottom = Math.max(combined.y + combined.height, box.y + box.height);
          const x = Math.min(combined.x, box.x);
          const y = Math.min(combined.y, box.y);
          return {
            x,
            y,
            width: right - x,
            height: bottom - y
          };
        });
        const clampValue = (value, minimum, maximum) => Math.min(maximum, Math.max(minimum, value));
        const padding = Math.max(8, Math.min(pageWidth, pageHeight) * 0.025);
        const x = clampValue(bounds.x - padding, 0, pageWidth);
        const y = clampValue(bounds.y - padding, 0, pageHeight);
        const right = clampValue(bounds.x + bounds.width + padding, 0, pageWidth);
        const bottom = clampValue(bounds.y + bounds.height + padding, 0, pageHeight);
        return {
          x,
          y,
          width: right - x,
          height: bottom - y
        };
      } finally {
        measurementHost.remove();
      }
    })();
    contentBoxCache.set(assetSrc, measurement);
    measurement.catch(() => contentBoxCache.delete(assetSrc));
    return measurement;
  };
  const renderPreviewAsset = ({contentBox: assetContentBox, loading}) => {
    if (!assetContentBox) {
      return <img className="latex-preview__asset" src={src} alt={alt} width={width} height={height} loading={loading} draggable="false" />;
    }
    return <svg className="latex-preview__asset" viewBox={`${assetContentBox.x} ${assetContentBox.y} ${assetContentBox.width} ${assetContentBox.height}`} preserveAspectRatio="xMidYMid meet" role="img" aria-label={alt}>
        <image href={src} x="0" y="0" width={width} height={height} />
      </svg>;
  };
  const [isOpen, setIsOpen] = useState(false);
  const [frameMode, setFrameMode] = useState("content");
  const [viewMode, setViewMode] = useState("fit");
  const [zoom, setZoom] = useState(minZoom);
  const [contentBox, setContentBox] = useState(null);
  const [measurementStatus, setMeasurementStatus] = useState("loading");
  const dialogRef = useRef(null);
  const closeButtonRef = useRef(null);
  const viewportRef = useRef(null);
  const previousFocusRef = useRef(null);
  const dragRef = useRef(null);
  useEffect(() => {
    let isCurrent = true;
    setMeasurementStatus("loading");
    measureSvgContent(src, width, height).then(box => {
      if (!isCurrent) return;
      setContentBox(box);
      setMeasurementStatus("ready");
    }).catch(() => {
      if (!isCurrent) return;
      setContentBox(null);
      setFrameMode("page");
      setMeasurementStatus("error");
    });
    return () => {
      isCurrent = false;
    };
  }, [height, src, width]);
  const closeViewer = useCallback(() => {
    setIsOpen(false);
  }, []);
  const openViewer = () => {
    previousFocusRef.current = document.activeElement;
    setFrameMode(contentBox ? "content" : "page");
    setViewMode("fit");
    setZoom(minZoom);
    setIsOpen(true);
  };
  const applyZoom = useCallback(nextZoom => {
    const boundedZoom = Math.min(maxZoom, Math.max(minZoom, nextZoom));
    setViewMode("custom");
    setZoom(boundedZoom);
  }, []);
  const zoomIn = useCallback(() => {
    applyZoom(viewMode === "fit" ? minZoom + zoomStep : zoom + zoomStep);
  }, [applyZoom, viewMode, zoom]);
  const zoomOut = useCallback(() => {
    applyZoom(viewMode === "fit" ? minZoom : zoom - zoomStep);
  }, [applyZoom, viewMode, zoom]);
  useEffect(() => {
    if (!isOpen) return undefined;
    const previousOverflow = document.body.style.overflow;
    document.body.style.overflow = "hidden";
    closeButtonRef.current?.focus();
    return () => {
      document.body.style.overflow = previousOverflow;
      previousFocusRef.current?.focus?.();
    };
  }, [isOpen]);
  useEffect(() => {
    if (!isOpen) return undefined;
    const handleKeyDown = event => {
      if (event.key === "Escape") {
        event.preventDefault();
        closeViewer();
        return;
      }
      if ((event.key === "+" || event.key === "=") && !event.metaKey && !event.ctrlKey) {
        event.preventDefault();
        zoomIn();
        return;
      }
      if (event.key === "-" && !event.metaKey && !event.ctrlKey) {
        event.preventDefault();
        zoomOut();
        return;
      }
      if (event.key !== "Tab" || !dialogRef.current) return;
      const focusable = [...dialogRef.current.querySelectorAll('button:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')];
      if (focusable.length === 0) return;
      const first = focusable[0];
      const last = focusable[focusable.length - 1];
      if (event.shiftKey && document.activeElement === first) {
        event.preventDefault();
        last.focus();
      } else if (!event.shiftKey && document.activeElement === last) {
        event.preventDefault();
        first.focus();
      }
    };
    window.addEventListener("keydown", handleKeyDown);
    return () => {
      window.removeEventListener("keydown", handleKeyDown);
    };
  }, [closeViewer, isOpen, zoomIn, zoomOut]);
  const startDrag = event => {
    if (event.button !== 0 || !viewportRef.current) return;
    const viewport = viewportRef.current;
    dragRef.current = {
      pointerId: event.pointerId,
      x: event.clientX,
      y: event.clientY,
      scrollLeft: viewport.scrollLeft,
      scrollTop: viewport.scrollTop
    };
    viewport.setPointerCapture(event.pointerId);
    viewport.dataset.dragging = "true";
  };
  const continueDrag = event => {
    const drag = dragRef.current;
    const viewport = viewportRef.current;
    if (!drag || !viewport || drag.pointerId !== event.pointerId) return;
    viewport.scrollLeft = drag.scrollLeft - (event.clientX - drag.x);
    viewport.scrollTop = drag.scrollTop - (event.clientY - drag.y);
  };
  const stopDrag = event => {
    const viewport = viewportRef.current;
    if (viewport?.hasPointerCapture(event.pointerId)) viewport.releasePointerCapture(event.pointerId);
    if (viewport) delete viewport.dataset.dragging;
    dragRef.current = null;
  };
  const activeContentBox = frameMode === "content" ? contentBox : null;
  const activeWidth = activeContentBox?.width ?? width;
  const activeHeight = activeContentBox?.height ?? height;
  const activeRatio = activeWidth / activeHeight;
  const inlineContentBox = measurementStatus === "ready" ? contentBox : null;
  const inlineWidth = inlineContentBox?.width ?? width;
  const inlineHeight = inlineContentBox?.height ?? height;
  const inlineGeometry = {
    aspectRatio: `${inlineWidth} / ${inlineHeight}`,
    maxWidth: `${30 * inlineWidth / inlineHeight}rem`
  };
  const imageStyle = viewMode === "fit" ? {
    aspectRatio: `${activeWidth} / ${activeHeight}`,
    width: "100%",
    maxWidth: `${Math.max(16, activeRatio * 78)}dvh`
  } : {
    aspectRatio: `${activeWidth} / ${activeHeight}`,
    width: `${zoom * 100}%`,
    maxWidth: "none"
  };
  const zoomLabel = viewMode === "fit" ? frameMode === "content" ? "Fit content" : "Full page" : `${Math.round(zoom * 100)}%`;
  return <figure className="latex-preview">
      <button type="button" className="latex-preview__trigger" onClick={openViewer} aria-haspopup="dialog" aria-label={`Open zoomable preview: ${alt}`}>
        <span className="latex-preview__page" style={inlineGeometry}>
          {measurementStatus === "loading" ? <span className="latex-preview__loading" role="status">Preparing compiled output…</span> : renderPreviewAsset({
    src,
    alt,
    width,
    height,
    contentBox: inlineContentBox,
    loading: "lazy"
  })}
        </span>
        <span className="latex-preview__trigger-label" aria-hidden="true">
          <span className="latex-preview__trigger-icon">⌕</span>
          Open viewer
        </span>
      </button>
      <figcaption className="latex-preview__caption">
        <span>
          {caption}
          {measurementStatus === "error" && <span className="latex-preview__status" role="status"> Content fit is unavailable; the complete vector page is shown.</span>}
        </span>
        <a href={src} target="_blank" rel="noreferrer" className="latex-preview__source-link">Open SVG</a>
      </figcaption>

      {isOpen && <div className="latex-preview__backdrop" onMouseDown={event => {
    if (event.target === event.currentTarget) closeViewer();
  }}>
          <section ref={dialogRef} className="latex-preview__dialog" role="dialog" aria-modal="true" aria-label={`Rendered LaTeX viewer: ${alt}`}>
            <header className="latex-preview__toolbar">
              <div className="latex-preview__identity">
                <span className="latex-preview__eyebrow">Compiled LaTeX</span>
                <span className="latex-preview__filename">{alt}</span>
              </div>
              <div className="latex-preview__controls" aria-label="Preview controls">
                <button type="button" className={frameMode === "content" && viewMode === "fit" ? "is-active" : undefined} disabled={!contentBox} onClick={() => {
    setFrameMode("content");
    setViewMode("fit");
    setZoom(minZoom);
  }}>
                  Fit content
                </button>
                <button type="button" className={frameMode === "page" && viewMode === "fit" ? "is-active" : undefined} onClick={() => {
    setFrameMode("page");
    setViewMode("fit");
    setZoom(minZoom);
  }}>
                  Full page
                </button>
                <span className="latex-preview__zoom-group">
                  <button type="button" onClick={zoomOut} disabled={viewMode === "fit" || zoom <= minZoom} aria-label="Zoom out">−</button>
                  <output aria-live="polite" aria-label="Current zoom">{zoomLabel}</output>
                  <button type="button" onClick={zoomIn} disabled={viewMode !== "fit" && zoom >= maxZoom} aria-label="Zoom in">+</button>
                </span>
                <a href={src} target="_blank" rel="noreferrer">Open SVG</a>
                <button ref={closeButtonRef} type="button" className="latex-preview__close" onClick={closeViewer} aria-label="Close rendered LaTeX viewer">
                  Close
                </button>
              </div>
            </header>
            <div ref={viewportRef} className="latex-preview__viewport" data-view-mode={viewMode} onPointerDown={startDrag} onPointerMove={continueDrag} onPointerUp={stopDrag} onPointerCancel={stopDrag}>
              <span className="latex-preview__dialog-page" style={imageStyle}>
                {renderPreviewAsset({
    src,
    alt,
    width,
    height,
    contentBox: activeContentBox
  })}
              </span>
            </div>
            <footer className="latex-preview__viewer-note">
              Compiler-generated vector output · Use +/− to zoom · Drag to pan · Esc to close
            </footer>
          </section>
        </div>}
    </figure>;
};

Learn how to typeset musical notation, symbols, and scores professionally in LaTeX.

## Rendered Previews (prototype)

Below each relevant code block, we show a “Rendered output” image that illustrates the expected result. These SVGs are placeholders for now; after your approval we can hook in a build step to generate them automatically from the LaTeX examples.

## Essential Music Packages

<LatexSource filename="example.tex" source={"\\usepackage{musixtex}       % Complete music typesetting\n\\usepackage{harmony}        % Chord symbols\n\\usepackage{guitar}         % Guitar chord diagrams\n\\usepackage{abc}            % ABC notation support\n\\usepackage{lilyglyphs}     % LilyPond symbols\n\\usepackage{leadsheets}     % Lead sheets and songs"} />

<RenderedOutput title="Expected effect">
  <Info>
    This is setup or structural LaTeX code. It changes available commands or document behavior, but it does not produce meaningful standalone page content by itself.
  </Info>
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Packages are loaded in the preamble and produce no visible output. They enable music notation commands throughout your document.
</Card>

## Musical Symbols

| Symbol | LaTeX              | Description         |
| :----: | :----------------- | :------------------ |
|  **♩** | `\quarternote`     | Quarter note        |
|  **♪** | `\eighthnote`      | Eighth note         |
|  **♫** | `\twonotes`        | Beamed eighth notes |
|  **♭** | `\flat`            | Flat                |
|  **♯** | `\sharp`           | Sharp               |
|  **♮** | `\natural`         | Natural             |
| **𝄞** | `\trebleclef`      | Treble clef         |
| **𝄢** | `\bassclef`        | Bass clef           |
| **𝄐** | `\textmusicalnote` | Generic note        |

## Basic Music Notation

### Note Values and Rests

<LatexSource filename="example.tex" source={"% Note values\n\\whole          % Whole note\n\\half           % Half note\n\\quarter        % Quarter note\n\\eighth         % Eighth note\n\\sixteenth      % Sixteenth note\n\n% Rests\n\\wholerest      % Whole rest\n\\halfrest       % Half rest\n\\quarterrest    % Quarter rest\n\\eighthrest     % Eighth rest\n\n% Dotted notes\n\\quarter.       % Dotted quarter\n\\half..         % Double dotted half"} />

<RenderedOutput title="Expected effect">
  <Info>
    This code is a contextual or intentionally partial LaTeX excerpt, not a self-contained compilable document. Its visible result depends on the surrounding document, so the documentation shows the expected role without inventing a standalone preview.
  </Info>
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Displays musical note values: whole note (𝅝), half note (𝅗𝅥), quarter note (♩), eighth note (♪), sixteenth note (𝅘𝅥𝅯). Corresponding rests appear as horizontal bars or symbols. Dotted notes show a small dot after the note head extending the duration by half.
</Card>

### Accidentals and Key Signatures

<LatexSource filename="example.tex" source={"% Accidentals\nC\\sharp         % C sharp\nB\\flat          % B flat\nF\\natural       % F natural\nG\\doublesharp   % G double sharp\nD\\doubleflat    % D double flat\n\n% Key signatures\n\\keysignature{3\\sharp}    % A major / F# minor\n\\keysignature{2\\flat}     % Bb major / G minor\n\\keysignature{0}          % C major / A minor"} />

<RenderedOutput title="Expected effect">
  <Info>
    This code is a contextual or intentionally partial LaTeX excerpt, not a self-contained compilable document. Its visible result depends on the surrounding document, so the documentation shows the expected role without inventing a standalone preview.
  </Info>
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Shows accidental symbols: C♯ (sharp raises pitch), B♭ (flat lowers pitch), F♮ (natural cancels previous accidental), G𝄪 (double sharp), D𝄫 (double flat). Key signatures display appropriate sharps or flats at the beginning of the staff.
</Card>

## Chord Notation

### Chord Symbols with harmony

<LatexSource filename="example.tex" source={"% Basic chords\n\\Cma            % C major\n\\Cmi            % C minor\n\\Cdim           % C diminished\n\\Caug           % C augmented\n\n% Seventh chords\n\\CmaSe          % C major 7\n\\CmiSe          % C minor 7\n\\Cdom           % C7 (dominant)\n\\CmiSeFlat      % C minor 7 flat 5\n\n% Extended chords\n\\Cnine          % C9\n\\Celeven        % C11\n\\Cthirteen      % C13\n\n% Slash chords\nC/G             % C major over G\nAm/F            % A minor over F"} />

<RenderedOutput title="Expected effect">
  <Info>
    This code is a contextual or intentionally partial LaTeX excerpt, not a self-contained compilable document. Its visible result depends on the surrounding document, so the documentation shows the expected role without inventing a standalone preview.
  </Info>
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Displays professionally formatted chord symbols: Cmaj, Cmin, Cdim, Caug for basic triads. Seventh chords appear as Cmaj7, Cmin7, C7, Cm7♭5. Extended chords show C9, C11, C13. Slash chords display as C/G and Am/F with the bass note after the slash.
</Card>

## Guitar Chord Diagrams

### Using the guitar Package

<LatexSource filename="example.tex" source={"% Basic chord diagram\n\\gtab{C}{3:002010}\n\\gtab{G}{3:002220}\n\\gtab{Am}{X02210}\n\\gtab{F}{1:X33211}\n\n% With finger positions\n\\gtab*{D}{XX0232:000132}\n\\gtab*{Em}{022000:012000}\n\n% Barre chords\n\\gtab{Bm}{2:X13321}\n\\gtab{F\\sharp m}{2:133111}"} />

<RenderedOutput title="Expected effect">
  <Info>
    This code is a contextual or intentionally partial LaTeX excerpt, not a self-contained compilable document. Its visible result depends on the surrounding document, so the documentation shows the expected role without inventing a standalone preview.
  </Info>
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Renders guitar chord diagrams as fretboard grids showing finger positions. Each diagram displays 6 vertical strings and horizontal frets with dots indicating where to press. X marks strings not played, O marks open strings. Barre chords show a bar across multiple strings.
</Card>

## Simple Scores with MusiXTeX

### Basic Staff Notation

<LatexSource filename="example.tex" source={"\\begin{music}\n\\instrumentnumber{1}\n\\setstaffs1{1}\n\\generalmeter{\\meterfrac44}\n\\startpiece\n\n% Simple melody\n\\notes\\qu c\\en    % Quarter note C\n\\notes\\hu d\\en    % Half note D\n\\notes\\qu{ef}\\en  % Quarter notes E and F\n\\notes\\wh g\\en    % Whole note G\n\n\\endpiece\n\\end{music}"} />

<RenderedOutput title="Rendered output" ctaHref="https://app.latex-cloud-studio.com/?utm_source=resources&utm_medium=rendered_output&utm_campaign=docs_open_app&utm_content=learn_latex_specialized_notation_music">
  <LatexPreview src="/images/rendered/learn-latex-specialized-notation-music-06/page-1.svg" alt="Compiled PDF page 1 from example.tex" caption="Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment. The visible fragment is compiled inside the documented minimal article wrapper." width={595.276} height={841.89} />
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Displays a musical staff with treble clef (𝄞) and 4/4 time signature. Notes appear on the five-line staff: C (quarter), D (half), E-F (quarters), G (whole). Note heads are positioned at correct pitch heights with appropriate stems.
</Card>

### Two-Staff System

<LatexSource filename="example.tex" source={"\\begin{music}\n\\instrumentnumber{1}\n\\setstaffs1{2}              % Two staves\n\\setclef1{\\treble\\bass}     % Treble and bass clefs\n\\generalmeter{\\meterfrac44}\n\\startpiece\n\n% Right hand\n\\notes\\qu{ceg}\\en           % C major chord\n\\notes\\qu{ceg}\\en\n% Left hand\n\\Notes\\ql{C}\\en\n\\Notes\\ql{G}\\en\n\n\\endpiece\n\\end{music}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-specialized-notation-music-07/page-1.svg" alt="Compiled PDF page 1 from example.tex" caption="Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment. The visible fragment is compiled inside the documented minimal article wrapper." width={595.276} height={841.89} />
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Shows a grand staff (piano system) with treble clef (𝄞) on top and bass clef (𝄢) on bottom, connected by a brace. The right hand plays C major chord (C-E-G) on the upper staff while the left hand plays bass notes C and G on the lower staff.
</Card>

## Lead Sheets with leadsheets

### Song Structure

<LatexSource filename="example.tex" source={"\\begin{song}{title={My Song},\n             composer={John Doe},\n             key={C major}}\n\n\\begin{verse}\n\\chord{C}This is the \\chord{Am}first line\n\\chord{F}Of my \\chord{G}song \\chord{C}today\n\\end{verse}\n\n\\begin{chorus}\n\\chord{F}Sing a\\chord{C}long\n\\chord{G}Everyone \\chord{C}sing\n\\end{chorus}\n\n\\end{song}"} />

<RenderedOutput title="Expected effect">
  <Info>
    This code is a contextual or intentionally partial LaTeX excerpt, not a self-contained compilable document. Its visible result depends on the surrounding document, so the documentation shows the expected role without inventing a standalone preview.
  </Info>
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Produces a formatted lead sheet with title "My Song" and composer credit. Verse and chorus sections are labeled. Chord symbols (C, Am, F, G) appear above the lyrics at the appropriate syllables, creating a professional songbook layout.
</Card>

## Rhythm Notation

### Time Signatures and Tempo

<LatexSource filename="example.tex" source={"% Time signatures\n\\timesignature{4}{4}        % 4/4 time\n\\timesignature{3}{4}        % 3/4 time\n\\timesignature{6}{8}        % 6/8 time\n\\timesignature{5}{4}        % 5/4 time\n\n% Tempo markings\n\\tempo{Allegro}\n\\tempo{Andante \\quarternote = 72}\n\\tempo{Presto \\halfnote = 140}\n\n% Metronome markings\nMM \\quarternote = 120\nMM \\halfnote. = 60"} />

<RenderedOutput title="Expected effect">
  <Info>
    This code is a contextual or intentionally partial LaTeX excerpt, not a self-contained compilable document. Its visible result depends on the surrounding document, so the documentation shows the expected role without inventing a standalone preview.
  </Info>
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Displays time signatures as stacked numbers (4/4, 3/4, 6/8, 5/4). Tempo markings show Italian terms like "Allegro" or "Andante" with metronome values. Metronome markings appear as "♩ = 120" indicating beats per minute.
</Card>

## Musical Expressions

### Dynamics and Articulation

<LatexSource filename="example.tex" source={"% Dynamics\n\\pp     % Pianissimo\n\\p      % Piano\n\\mp     % Mezzo-piano\n\\mf     % Mezzo-forte\n\\f      % Forte\n\\ff     % Fortissimo\n\n% Crescendo and diminuendo\n\\cresc  % Crescendo\n\\dim    % Diminuendo\n\\<      % Hairpin crescendo\n\\>      % Hairpin diminuendo\n\n% Articulation\n\\staccato       % Staccato dot\n\\accent         % Accent mark\n\\tenuto         % Tenuto line\n\\fermata        % Fermata"} />

<RenderedOutput title="Expected effect">
  <Info>
    This code is a contextual or intentionally partial LaTeX excerpt, not a self-contained compilable document. Its visible result depends on the surrounding document, so the documentation shows the expected role without inventing a standalone preview.
  </Info>
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Shows dynamic markings in italic: pp (very soft), p (soft), mp (medium soft), mf (medium loud), f (loud), ff (very loud). Crescendo and diminuendo appear as hairpin wedges (\< and >). Articulation marks include staccato dots, accent marks (>), tenuto lines, and fermata symbols (𝄐).
</Card>

## ABC Notation Integration

### Using ABC Notation

<LatexSource filename="example.tex" source={"% ABC notation example\n\\begin{abc}[name=melody]\nX:1\nT:Simple Melody\nM:4/4\nL:1/4\nK:C\nC D E F | G2 G2 | F E D C | C4 ||\n\\end{abc}\n\n% Inline ABC\n\\abcinline{C D E F G}"} />

<RenderedOutput title="Expected effect">
  <Info>
    This code is a contextual or intentionally partial LaTeX excerpt, not a self-contained compilable document. Its visible result depends on the surrounding document, so the documentation shows the expected role without inventing a standalone preview.
  </Info>
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Converts ABC notation into standard music notation. The melody "Simple Melody" appears on a staff in C major, 4/4 time. Notes C-D-E-F followed by two half-note Gs, then F-E-D-C, ending with a whole-note C. Bar lines separate measures.
</Card>

## Musical Analysis

### Roman Numeral Analysis

<LatexSource filename="example.tex" source={"% Roman numerals for harmony\n\\newcommand{\\romnum}[1]{\\textsc{#1}}\n\nIn C major: \\romnum{I} - \\romnum{IV} - \\romnum{V} - \\romnum{I}\n\n% With inversions\n\\romnum{I}\\textsuperscript{6} - \\romnum{IV}\\textsuperscript{6/4} - \\romnum{V}\\textsuperscript{7}\n\n% Minor keys (lowercase)\nIn A minor: \\romnum{i} - \\romnum{iv} - \\romnum{V} - \\romnum{i}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-specialized-notation-music-12/page-1.svg" alt="Compiled PDF page 1 from example.tex" caption="Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment. The visible fragment is compiled inside the documented minimal article wrapper." width={595.276} height={841.89} />
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Displays Roman numeral chord analysis in small caps. Major key progression: I - IV - V - I. Inversions shown with figured bass: I6, IV6/4, V7. Minor key uses lowercase: i - iv - V - i. These symbols appear below the staff in harmonic analysis.
</Card>

### Form Analysis

<LatexSource filename="example.tex" source={"% Sections\n\\textbf{A:} mm. 1-8\n\\textbf{B:} mm. 9-16\n\\textbf{A':} mm. 17-24\n\n% Phrases\n\\begin{tikzpicture}\n\\draw[thick] (0,0) -- (4,0);\n\\draw[thick] (0,0) -- (0,0.2);\n\\draw[thick] (4,0) -- (4,0.2);\n\\node at (2,-0.3) {4 measures};\n\\end{tikzpicture}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-specialized-notation-music-13/page-1.svg" alt="Compiled PDF page 1 from example.tex" caption="Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment. The visible fragment is compiled inside the documented minimal article wrapper." width={612} height={792} />
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Shows musical form sections labeled A (mm. 1-8), B (mm. 9-16), A' (mm. 17-24) in bold text. Phrase diagrams display horizontal lines with vertical endpoints marking phrase boundaries, with "4 measures" labeled beneath each phrase bracket.
</Card>

## Lyrics and Text

### Aligning Lyrics to Music

<LatexSource filename="example.tex" source={"\\begin{music}\n\\instrumentnumber{1}\n\\setstaffs1{1}\n\\setlyrics1{1}\n\\startpiece\n\n\\notes\\qu{c}\\en\n\\lyrics{This }\n\\notes\\qu{d}\\en\n\\lyrics{is }\n\\notes\\qu{e}\\en\n\\lyrics{my }\n\\notes\\hu{f}\\en\n\\lyrics{song }\n\n\\endpiece\n\\end{music}"} />

<RenderedOutput title="Expected effect">
  <Info>
    This code is a contextual or intentionally partial LaTeX excerpt, not a self-contained compilable document. Its visible result depends on the surrounding document, so the documentation shows the expected role without inventing a standalone preview.
  </Info>
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Displays a melodic line with lyrics aligned below each note. The words "This is my song" appear with each syllable centered under its corresponding note (C, D, E, F). The half note on "song" shows extended duration.
</Card>

## Musical Tables

### Interval Reference Table

<LatexSource filename="example.tex" source={"\\begin{table}[h]\n\\centering\n\\begin{tabular}{|l|c|c|}\n\\hline\n\\textbf{Interval} & \\textbf{Semitones} & \\textbf{Example} \\\\\n\\hline\nUnison & 0 & C-C \\\\\nMinor 2nd & 1 & C-D♭ \\\\\nMajor 2nd & 2 & C-D \\\\\nMinor 3rd & 3 & C-E♭ \\\\\nMajor 3rd & 4 & C-E \\\\\nPerfect 4th & 5 & C-F \\\\\nTritone & 6 & C-F♯ \\\\\nPerfect 5th & 7 & C-G \\\\\n\\hline\n\\end{tabular}\n\\caption{Common musical intervals}\n\\end{table}"} />

<RenderedOutput title="Expected effect">
  <Info>
    This code is a contextual or intentionally partial LaTeX excerpt, not a self-contained compilable document. Its visible result depends on the surrounding document, so the documentation shows the expected role without inventing a standalone preview.
  </Info>
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Produces a formatted table with columns for Interval, Semitones, and Example. Lists musical intervals from Unison (0 semitones, C-C) through Perfect 5th (7 semitones, C-G), including Minor/Major 2nds, 3rds, Perfect 4th, and Tritone. Includes a caption "Common musical intervals."
</Card>

## Special Music Characters

### Unicode Music Symbols

<LatexSource filename="example.tex" source={"% Requires fontspec and XeLaTeX/LuaLaTeX\n\\usepackage{fontspec}\n\n% Musical symbols\n🎵 🎶 🎼 🎹 🎸 🎺 🎻 🥁\n\n% Note values\n𝅝 𝅗𝅥 𝅘𝅥 𝅘𝅥𝅮 𝅘𝅥𝅯 𝅘𝅥𝅰 𝅘𝅥𝅱 𝅘𝅥𝅲\n\n% Clefs\n𝄞 𝄢 𝄡 𝄟 𝄠"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-specialized-notation-music-16/page-1.svg" alt="Compiled PDF page 1 from example.tex" caption="Generated from the shown source with XeLaTeX in the pinned LaTeXCloud TeX Live 2026 environment. The visible fragment is compiled inside the documented minimal article wrapper." width={595.28} height={841.89} />
</RenderedOutput>

**Expected output:**

<Card title="Expected output" icon="eye">
  Displays Unicode music symbols including emoji instruments: 🎵 🎶 🎼 🎹 🎸 🎺 🎻 🥁. Musical notation symbols show note values from whole to 128th notes. Clef symbols display: 𝄞 (treble), 𝄢 (bass), 𝄡 (alto), and percussion clefs.
</Card>

## Best Practices

<CardGroup cols={2}>
  <Card title="Choose the Right Package" icon="check" color="#FF6037">
    Select packages based on your needs - MusiXTeX for full scores, harmony for chord symbols
  </Card>

  <Card title="Consistent Notation" icon="book" color="#FF6037">
    Use standard music notation conventions throughout
  </Card>

  <Card title="Clear Layout" icon="eye" color="#FF6037">
    Ensure adequate spacing between staves and systems
  </Card>

  <Card title="Compile Multiple Times" icon="arrows-rotate" color="#FF6037">
    Music packages often require multiple compilation passes
  </Card>
</CardGroup>

## Troubleshooting

<Warning>
  **Common issues**:

  * MusiXTeX requires special compilation: Run `musixtex` command
  * Font conflicts: Some music fonts require specific setup
  * Spacing issues: Manual adjustment often needed for complex scores
</Warning>

## Further Reading

<CardGroup cols={2}>
  <Card title="Linguistics Notation" icon="language" href="/learn/latex/specialized-notation/linguistics" color="#FF6037">
    Phonetic symbols and syntax trees
  </Card>

  <Card title="Symbol Reference" icon="book" href="/learn/reference/symbols" color="#FF6037">
    General symbol reference
  </Card>

  <Card title="Creating Diagrams" icon="diagram-project" href="/learn/latex/how-to/tikz-diagrams" color="#FF6037">
    Creating diagrams with TikZ
  </Card>

  <Card title="Advanced Text Formatting" icon="palette" href="/learn/latex/text-formatting" color="#FF6037">
    Text styling, emphasis, and structure
  </Card>
</CardGroup>
