Latex

ic.Latex compiles and renders LaTeX source as formatted PDF pages, directly in the browser. It uses SwiftLaTeX’s PdfTeX WASM engine, so no server or internet connection is needed. The renderer ships with a set of bundled packages (amsmath, tikz, booktabs, hyperref, and others) and supports images resolved through MATLAB.

Toolbar, rendering, and page gap

ToolbarOnHover controls whether zoom and export controls appear when the mouse enters the viewer (on by default). PageGap sets the vertical spacing between pages in pixels.

Controls
No content

Height

Height accepts a pixel value or any CSS size string. Defaults to "100%".

Controls
No content

Setting content and exporting

Value takes a LaTeX source string. When RenderOnChange is true (the default), changing it triggers compilation automatically. render() forces a manual compile. exportPdf() saves the compiled output as a PDF: without arguments it opens a save dialog, or you can pass a file path.

l = ic.Latex();

% Set LaTeX source
l.Value = [
    "\documentclass{article}"
    "\begin{document}"
    "Hello \textbf{world}!"
    "\end{document}"
].join(newline);

% Manual render (when RenderOnChange is false)
l.RenderOnChange = false;
l.Value = newSource;
l.render();

% Export to PDF
l.exportPdf("output.pdf");

Bundled packages

The renderer ships with a curated set of TeX Live packages. Anything not in this list will cause a “File not found” error.

  • Math: amsmath, amssymb, amsfonts, amsthm, amstext, amscd, amsxtra, euscript, eufrak, mathtools, bm, xfrac
  • Structure: geometry, fancyhdr, enumitem, booktabs, float, setspace, parskip, longtable, multicol, tabularx, caption, subcaption, rotating, lscape, indentfirst, varioref
  • Graphics: tikz (pgf, shapes, positioning, arrows), graphicx, xcolor
  • Listings: listings
  • References: hyperref, nameref, url, backref
  • Utilities: etoolbox, calc, ifthen, xparse, expl3, array, verbatim, xspace, makeidx
  • Document classes: article, report, book, letter, proc, slides

Images

Images referenced with \includegraphics are extracted from the source and resolved through MATLAB before compilation. Local file paths and URLs both work. The resolved images are embedded into the WASM filesystem so the TeX engine can read them.

l = ic.Latex();
l.Value = [
    "\documentclass{article}"
    "\usepackage{graphicx}"
    "\begin{document}"
    "\includegraphics[width=0.5\textwidth]{plot.png}"
    "\end{document}"
].join(newline);

Events

Compiled fires after a successful compilation with the page count. Error fires when compilation fails with the error message.

No content
Events
No events fired yet

Zoom, reset, and render

zoomIn() and zoomOut() step the zoom by 20% (range 25% to 400%). resetView() resets zoom to 100% and scrolls to the top. render() forces a recompile of the current source. exportPdf() exports the compiled PDF.

No content

Custom styling

You can target .ic-latex (the container), .ic-latex__viewport (the scroll area), .ic-latex__page (individual page wrappers), .ic-latex__controls (the hover toolbar), and .ic-latex__btn (the toolbar buttons).

No content
l = ic.Latex();
l.Value = mySource;

% Rounded container with colored border
l.css.style(".ic-latex", ...
    "border_radius", "8px", ...
    "border_color", "#94a3b8");

% Tinted page background for multi-page view
l.css.style(".ic-latex__viewport", ...
    "background_color", "#f1f5f9");

% Subtle page shadow
l.css.style(".ic-latex__page", ...
    "box_shadow", "0 1px 8px rgba(0, 0, 0, 0.1)", ...
    "border_radius", "2px");

% Style the hover toolbar
l.css.style(".ic-latex__controls", ...
    "background_color", "#1e293b", ...
    "border_color", "#334155", ...
    "border_radius", "16px", ...
    "padding", "4px 14px");

l.css.style(".ic-latex__btn", ...
    "color", "#94a3b8", ...
    "border_radius", "10px");

l.css.style(".ic-latex__btn:hover", ...
    "color", "#e2e8f0", ...
    "background_color", "#334155");
Compatibility note. Figures run in different browsers depending on Matlabs version and operating system. CSS features like linear-gradient, backdrop-filter, or newer color functions may not work everywhere. For reference, MATLAB R2024b uses Chromium 104. Always test your custom styles in the MATLAB version you are targeting, and use canIuse to check compatibility of specific CSS features if you know the browser version MATLAB is using. Use the Developer Tools component to inspect the DOM structure of each component and find the right selectors for styling.