> ## 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.

# LaTeX Mathematics - Getting Started

> Master mathematical typesetting in LaTeX. Learn how to write equations, use math symbols, and create beautiful mathematical documents.

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>;
};

LaTeX is renowned for its superior mathematical typesetting. This guide will take you from basic equations to advanced mathematical expressions.

<Info>
  **Fun fact**: LaTeX's math rendering is so good that even Microsoft Word now uses a LaTeX-like syntax for its equation editor!
</Info>

## Why LaTeX for Math?

Compare these approaches to writing the quadratic formula:

**Plain text**: x = (-b +/- sqrt(b^2 - 4ac)) / 2a

**LaTeX result**: $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$

The difference is clear – LaTeX produces publication-quality mathematics.

## Math Modes

LaTeX has two math modes:

### 1. Inline Math Mode

For math within text, use `$...$` or `\(...\)`:

<LatexSource filename="inline-math.tex" source={"The famous equation $E = mc^2$ was\ndiscovered by Einstein. We can also\nwrite \\(a^2 + b^2 = c^2\\) for the\nPythagorean theorem."} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-03/page-1.svg" alt="Compiled PDF page 1 from inline-math.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>

<Card title="Expected output" icon="eye">
  The famous equation $E = mc^2$ was discovered by Einstein. We can also write $a^2 + b^2 = c^2$ for the Pythagorean theorem.
</Card>

### 2. Display Math Mode

For centered equations on their own line, use `\[...\]` or `equation` environment:

<LatexSource filename="display-math.tex" source={"The quadratic formula is:\n\\[x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}\\]\n\nFor numbered equations, use:\n\\begin{equation}\n\\int_0^\\infty e^{-x^2} dx = \\frac{\\sqrt{\\pi}}{2}\n\\end{equation}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-04/page-1.svg" alt="Compiled PDF page 1 from display-math.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>

<Card title="Expected output" icon="eye">
  The quadratic formula is:

  $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$

  For numbered equations:

  $\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2} \tag{1}$
</Card>

<Tip>
  Use `\[...\]` for important formulas you want to highlight. Use `$...$` for variables and simple expressions within sentences.
</Tip>

## Basic Math Elements

### Superscripts and Subscripts

<LatexSource filename="super-subscripts.tex" source={"% Superscripts with ^\n$x^2$, $x^{10}$, $x^{n+1}$\n\n% Subscripts with _\n$x_1$, $x_{10}$, $x_{i,j}$\n\n% Combined\n$x_1^2$, $a_n^{k+1}$\n\n% Chemical formulas\n$\\text{H}_2\\text{O}$, $\\text{CO}_2$"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-05/page-1.svg" alt="Compiled PDF page 1 from super-subscripts.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>

<Card title="Expected output" icon="eye">
  **Superscripts:** $x^2$, $x^{10}$, $x^{n+1}$

  **Subscripts:** $x_1$, $x_{10}$, $x_{i,j}$

  **Combined:** $x_1^2$, $a_n^{k+1}$

  **Chemical formulas:** $\text{H}_2\text{O}$, $\text{CO}_2$
</Card>

### Fractions

<LatexSource filename="fractions.tex" source={"% Simple fractions\n$\\frac{1}{2}$, $\\frac{a}{b}$\n\n% Nested fractions\n$\\frac{1}{1 + \\frac{1}{2}}$\n\n% Display style in inline math\n$\\displaystyle\\frac{a+b}{c+d}$\n\n% Alternative notation\n$a/b$ or $^a/_b$"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-06/page-1.svg" alt="Compiled PDF page 1 from fractions.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>

<Card title="Expected output" icon="eye">
  **Simple fractions:** $\frac{1}{2}$, $\frac{a}{b}$

  **Nested fractions:** $\frac{1}{1 + \frac{1}{2}}$

  **Display style:** $\displaystyle\frac{a+b}{c+d}$

  **Alternative notation:** $a/b$ or $^a/_b$
</Card>

### Roots

<LatexSource filename="roots.tex" source={"% Square root\n$\\sqrt{2}$, $\\sqrt{x^2 + y^2}$\n\n% nth root\n$\\sqrt[3]{8}$, $\\sqrt[n]{x}$\n\n% Nested roots\n$\\sqrt{2 + \\sqrt{3}}$"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-07/page-1.svg" alt="Compiled PDF page 1 from roots.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>

<Card title="Expected output" icon="eye">
  **Square root:** $\sqrt{2}$, $\sqrt{x^2 + y^2}$

  **nth root:** $\sqrt[3]{8}$, $\sqrt[n]{x}$

  **Nested roots:** $\sqrt{2 + \sqrt{3}}$
</Card>

## Common Math Symbols

### Greek Letters

<LatexSource filename="greek-letters.tex" source={"% Lowercase\n$\\alpha, \\beta, \\gamma, \\delta, \\epsilon$\n$\\theta, \\lambda, \\mu, \\pi, \\sigma, \\phi$\n\n% Uppercase\n$\\Gamma, \\Delta, \\Theta, \\Lambda, \\Sigma, \\Phi$\n\n% Variants\n$\\epsilon$ vs $\\varepsilon$\n$\\phi$ vs $\\varphi$"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-08/page-1.svg" alt="Compiled PDF page 1 from greek-letters.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>

<Card title="Expected output" icon="eye">
  **Lowercase:** $\alpha, \beta, \gamma, \delta, \epsilon$ and $\theta, \lambda, \mu, \pi, \sigma, \phi$

  **Uppercase:** $\Gamma, \Delta, \Theta, \Lambda, \Sigma, \Phi$

  **Variants:** $\epsilon$ vs $\varepsilon$ and $\phi$ vs $\varphi$
</Card>

### Operators and Relations

<LatexSource filename="operators.tex" source={"% Basic operators\n$a + b - c \\times d \\div e$\n\n% Comparison\n$a < b \\leq c = d \\geq e > f$\n$a \\neq b \\approx c \\equiv d$\n\n% Set operations\n$A \\cup B \\cap C \\subset D$\n$x \\in A, y \\notin B$\n\n% Logic\n$p \\land q \\lor r \\implies s$\n$\\forall x \\exists y$"} />

<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>

<Card title="Expected output" icon="eye">
  **Basic operators:** $a + b - c \times d \div e$

  **Comparison:** $a < b \leq c = d \geq e > f$ and $a \neq b \approx c \equiv d$

  **Set operations:** $A \cup B \cap C \subset D$ and $x \in A, y \notin B$

  **Logic:** $p \land q \lor r \implies s$ and $\forall x \exists y$
</Card>

### Arrows

<LatexSource filename="arrows.tex" source={"% Basic arrows\n$\\rightarrow, \\leftarrow, \\leftrightarrow$\n$\\Rightarrow, \\Leftarrow, \\Leftrightarrow$\n\n% Long arrows\n$\\longrightarrow, \\longleftarrow$\n\n% Special arrows\n$\\uparrow, \\downarrow, \\updownarrow$\n$\\nearrow, \\searrow, \\swarrow, \\nwarrow$"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-10/page-1.svg" alt="Compiled PDF page 1 from arrows.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>

<Card title="Expected output" icon="eye">
  **Basic arrows:** $\rightarrow, \leftarrow, \leftrightarrow$ and $\Rightarrow, \Leftarrow, \Leftrightarrow$

  **Long arrows:** $\longrightarrow, \longleftarrow$

  **Special arrows:** $\uparrow, \downarrow, \updownarrow$ and $\nearrow, \searrow, \swarrow, \nwarrow$
</Card>

## Functions and Operators

### Standard Functions

<LatexSource filename="functions.tex" source={"% Trigonometric\n$\\sin\\theta, \\cos\\theta, \\tan\\theta$\n\n% Logarithms\n$\\log x, \\ln x, \\log_2 x$\n\n% Limits\n$\\lim_{x \\to 0} \\frac{\\sin x}{x} = 1$\n\n% Min/Max\n$\\min(a,b), \\max(a,b)$"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-11/page-1.svg" alt="Compiled PDF page 1 from functions.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>

<Card title="Expected output" icon="eye">
  **Trigonometric:** $\sin\theta, \cos\theta, \tan\theta$

  **Logarithms:** $\log x, \ln x, \log_2 x$

  **Limits:** $\displaystyle\lim_{x \to 0} \frac{\sin x}{x} = 1$

  **Min/Max:** $\min(a,b), \max(a,b)$
</Card>

### Sums and Products

<LatexSource filename="sums-products.tex" source={"% Summation\n$\\sum_{i=1}^{n} i = \\frac{n(n+1)}{2}$\n\n% Product\n$\\prod_{i=1}^{n} i = n!$\n\n% Multiple lines\n$\\sum_{\\substack{i=1 \\\\ i \\neq j}}^{n} a_i$"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-12/page-1.svg" alt="Compiled PDF page 1 from sums-products.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>

<Card title="Expected output" icon="eye">
  **Summation:** $\displaystyle\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$

  **Product:** $\displaystyle\prod_{i=1}^{n} i = n!$

  **Multiple lines:** $\displaystyle\sum_{\substack{i=1 \\ i \neq j}}^{n} a_i$
</Card>

## Integrals and Derivatives

<LatexSource filename="calculus.tex" source={"% Derivatives\n$f'(x), f''(x), f^{(n)}(x)$\n$\\frac{df}{dx}, \\frac{d^2f}{dx^2}$\n$\\frac{\\partial f}{\\partial x}$\n\n% Integrals\n$\\int f(x)\\,dx$\n$\\int_a^b f(x)\\,dx$\n$\\iint_D f(x,y)\\,dx\\,dy$\n\n% Special notation\n$\\oint_C F \\cdot dr$"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-13/page-1.svg" alt="Compiled PDF page 1 from calculus.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>

<Card title="Expected output" icon="eye">
  **Derivatives:** $f'(x), f''(x), f^{(n)}(x)$ and $\frac{df}{dx}, \frac{d^2f}{dx^2}$ and $\frac{\partial f}{\partial x}$

  **Integrals:** $\displaystyle\int f(x)\,dx$ and $\displaystyle\int_a^b f(x)\,dx$ and $\displaystyle\iint_D f(x,y)\,dx\,dy$

  **Special notation:** $\displaystyle\oint_C F \cdot dr$
</Card>

## Matrices and Arrays

### Basic Matrices

<LatexSource filename="matrices.tex" source={"% Using pmatrix (parentheses)\n$\\begin{pmatrix}\na & b \\\\\nc & d\n\\end{pmatrix}$\n\n% Using bmatrix (brackets)\n$\\begin{bmatrix}\n1 & 2 & 3 \\\\\n4 & 5 & 6 \\\\\n7 & 8 & 9\n\\end{bmatrix}$\n\n% Using vmatrix (determinant)\n$\\begin{vmatrix}\na & b \\\\\nc & d\n\\end{vmatrix} = ad - bc$"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-14/page-1.svg" alt="Compiled PDF page 1 from matrices.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>

<Card title="Expected output" icon="eye">
  **pmatrix (parentheses):** $\begin{pmatrix} a & b \\ c & d \end{pmatrix}$

  **bmatrix (brackets):** $\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}$

  **vmatrix (determinant):** $\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc$
</Card>

### Advanced Arrays

<LatexSource filename="arrays.tex" source={"% Custom arrays\n$\\left[\n\\begin{array}{cc|c}\n1 & 2 & 3 \\\\\n4 & 5 & 6\n\\end{array}\n\\right]$\n\n% Cases (piecewise functions)\n$f(x) = \\begin{cases}\nx^2 & \\text{if } x \\geq 0 \\\\\n-x & \\text{if } x < 0\n\\end{cases}$"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-15/page-1.svg" alt="Compiled PDF page 1 from arrays.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>

<Card title="Expected output" icon="eye">
  **Custom arrays:** $\left[ \begin{array}{cc|c} 1 & 2 & 3 \\ 4 & 5 & 6 \end{array} \right]$

  **Cases (piecewise functions):** $f(x) = \begin{cases} x^2 & \text{if } x \geq 0 \\ -x & \text{if } x < 0 \end{cases}$
</Card>

## Spacing in Math Mode

<LatexSource filename="math-spacing.tex" source={"% Default spacing\n$a b$ vs $ab$\n\n% Manual spacing\n$a\\,b$     % thin space\n$a\\:b$     % medium space\n$a\\;b$     % thick space\n$a\\quad b$ % quad space\n$a\\qquad b$ % double quad\n\n% Negative space\n$a\\!b$     % negative thin space"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-16/page-1.svg" alt="Compiled PDF page 1 from math-spacing.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>

<Card title="Expected output" icon="eye">
  **Default:** $a b$ vs $ab$

  **Thin space:** $a\,b$ | **Medium space:** $a\:b$ | **Thick space:** $a\;b$

  **Quad space:** $a\quad b$ | **Double quad:** $a\qquad b$

  **Negative space:** $a\!b$
</Card>

<Tip>
  Use `\,` before differentials in integrals: `\int f(x)\,dx` looks better than `\int f(x)dx`.
</Tip>

## Advanced Features

### Theorem Environments

<LatexSource filename="theorems.tex" source={"\\documentclass{article}\n\\usepackage{amsthm}\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{lemma}{Lemma}\n\n\\begin{document}\n\\begin{theorem}[Pythagoras]\nFor a right triangle with legs $a$ and $b$ \nand hypotenuse $c$, we have $a^2 + b^2 = c^2$.\n\\end{theorem}\n\n\\begin{proof}\nConsider a square with side length $a + b$...\n\\end{proof}\n\\end{document}"} />

<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_mathematics_basics">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-01/page-1.svg" alt="Compiled PDF page 1 from theorems.tex" caption="Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

### Aligning Equations

<LatexSource filename="align.tex" source={"\\begin{align}\n2x + 3y &= 7 \\\\\nx - y &= 1\n\\end{align}\n\n% Multi-line derivation\n\\begin{align}\n(x + y)^2 &= (x + y)(x + y) \\\\\n&= x^2 + xy + yx + y^2 \\\\\n&= x^2 + 2xy + y^2\n\\end{align}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-mathematics-basics-02/page-1.svg" alt="Compiled PDF page 1 from align.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>

## Common Mistakes to Avoid

<Warning>
  **1. Forgetting braces for multi-character super/subscripts**

  * Wrong: `$x^10$` → x¹0
  * Right: `$x^{10}$` → x¹⁰

  **2. Using text in math mode**

  * Wrong: `$x = speed * time$`
  * Right: `$x = \text{speed} \times \text{time}$`

  **3. Incorrect fraction syntax**

  * Wrong: `$\frac{1/2}$`
  * Right: `$\frac{1}{2}$`
</Warning>

## Math Packages

Essential packages for advanced mathematics:

<LatexSource filename="example.tex" source={"\\usepackage{amsmath}   % Advanced math environments\n\\usepackage{amssymb}   % Additional symbols\n\\usepackage{mathtools} % Enhanced amsmath\n\\usepackage{physics}   % Physics notation\n\\usepackage{siunitx}   % SI units"} />

<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>

## Practice Exercises

Try typesetting these formulas:

1. **Euler's Identity**: $e^{i\pi} + 1 = 0$
2. **Gaussian Integral**: $\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}$
3. **Binomial Theorem**: $(x+y)^n = \sum_{k=0}^{n} \binom{n}{k} x^{n-k} y^k$
4. **Maxwell's Equation**: $\nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t}$

## Quick Reference

| Feature      | Syntax            | Example          |
| ------------ | ----------------- | ---------------- |
| Inline math  | `$...$`           | `$x^2$`          |
| Display math | `\[...\]`         | `\[x^2\]`        |
| Fraction     | `\frac{num}{den}` | `$\frac{a}{b}$`  |
| Square root  | `\sqrt{x}`        | `$\sqrt{2}$`     |
| Subscript    | `_`               | `$x_1$`          |
| Superscript  | `^`               | `$x^2$`          |
| Greek letter | `\alpha`          | `$\alpha$`       |
| Sum          | `\sum`            | `$\sum_{i=1}^n$` |
| Integral     | `\int`            | `$\int_a^b$`     |

## Next Steps

<CardGroup cols={2}>
  <Card title="Math Symbols Reference" icon="symbols" href="/learn/reference/symbols">
    Complete list of mathematical symbols
  </Card>

  <Card title="Advanced Equations" icon="calculator" href="/learn/latex/mathematics/equations">
    Multi-line equations and advanced layouts
  </Card>

  <Card title="Matrices & Arrays" icon="table-cells" href="/learn/latex/mathematics/matrices">
    Complex matrix operations and layouts
  </Card>

  <Card title="Scientific Notation" icon="atom" href="/learn/latex/mathematics/science">
    Physics, chemistry, and scientific formatting
  </Card>
</CardGroup>

***

Ready to create beautiful mathematical documents? You now have the foundation to typeset any mathematical expression in LaTeX!
