Neural Sketch

Icons

A guided tour of Neural Sketch's icon pipeline – from declarative SVG inclusion to automatic fetching, recoloring, and cleanup.

Why an Icon System?

In complex, publication‑grade diagrams, a lone arrow or block label is rarely enough. We often need semantic glyphs – check‑marks for valid, exclamation triangles for warning, tiny CPUs for compute node – to compress entire phrases into a few visual atomic components.

Yet: manually hunting SVGs, juggling \includegraphics, tweaking dimensions, and recoloring for dark‑mode is drudgery. Neural‑Sketch treats icons as first‑class primitives, governed by the same declarative key–value philosophy that powers blocks, annotations, and containers.

The Big Idea

\nskIcon is not a passive include command. It is a pipeline – a bridge between your .tex file and an ecosystem of reusable vector assets.

Quick Start

% Load an icon by name – fuss‑free
\nskIcon[name=compute]

On first compilation Neural Sketch will:

  1. Fetch the raw SVG from the Lucide repo (via pyfetch).
  2. Recolor its stroke to match your theme (icon-color, defaults to your block border color).
  3. Cache the processed file in ./icons/ for future compilations.
  4. Inline it with the correct width/height so it sits snugly beside text.
  5. Collect unused icons and purge them from the disk—keeping your repo lean.

No extra packages, no manual downloads, no brittle path juggling.

Anatomy of \nskIcon

% General form – every key other than `name` is optional
\nskIcon[
  name        = check,   % SVG Provider name (slug)
  type        = lucide,  % future‑proof; SVG Provider
  color       = nskRed,  % any color expr or xcolor name
  border-size = 2.5,     % stroke-width / floating point or int
  size        = .5cm,    % overall icon size (dim)
]

Parameter Cheatsheet

KeyPurposeNotes
nameSlug of the SVG fileOmit extension; check resolves to check.svg
typeProvider to pull fromCurrently only supported lucide. More to come...
colorStroke colorApplied at fetch‑time, so the glyph stays vector‑pure across light and dark themes
border-sizeStroke widthApplied at fetch‑time, controls the size of the border
sizeConvenience wrapper for both width and heightAny TeX dimension (1em, 8pt, 3mm). Overrides package defaults
shift-yVertical nudgeDimensional offset added to the icon’s baseline (ideal for inline text centering)
styleRaw PGF/tikz tweaksIcon additional stylings; examples: opacity=.75, rotate=90

Icons as regular text

Icons read like letters—seamless in the line. \nskIcon is a real node, so place it anywhere LaTeX\LaTeX accepts text—mid‑sentence, in captions, or via a `\nskBlock` text-* keys.

Spin it with style={rotate=…} or nudge the baseline with shift-y. Below, a compass‑rose demo shows the idea.

You can use and insert an \nskIcon wherever text is accepeted. The most common way is to embed it in a text-* within an \nskBlock.

examples-doc/icons-t.tex
\nskBlock[
  text-center = {\nskIcon[name=aperture]},
  text-north  = {\nskIcon[name=redo, style={rotate=0}]},
  text-east   = {\nskIcon[name=redo, style={rotate=-90}]},
  text-west   = {\nskIcon[name=redo, style={rotate=90}]},
  text-south  = {\nskIcon[name=redo, style={rotate=180}]},
  % ...
]
 
\nskBlock[
  width=3cm, last-pos={right=},
  text-center={\nskIcon[name=memory-stick]\; Memory},
  % ...
]

Providers

You can easily use an icon from one of the supported providers by just specifying their icon name (slug).

Search icons on Lucide

Search the icon you wish to use e.g., check mark

Copy the icon's name (slug) e.g., check:

Use it by its name!

  \nskBlock[
    text-center = {\nskIcon[name=check, type=lucide]},
  ]

Supported

Provider NameProvider TypeLink
LucidelucideLucide

Alignment

Icons ship baseline‑centred, so they slip into prose without tilting the line. Add breathing room with the usual TeX spacers (\,, \;, \quad, …).

By default icons are vertically aligned, with their baseline aligned with the center of the icon. This allows natural insertion within text. You can easily adjust the horizontal spacing using the usual LaTeX\LaTeX spacing macros.

MacroWidth (approx.)Typical use
\!−0.166 emNegative thin space – tighten symbol pairs
\,0.166 emThin space – subtle separation
\:0.222 emMedium space
\;0.277 emThick space
\quad1 emQuad – paragraph‑level padding
\qquad2 emDouble quad – generous padding
examples-doc/icons-a.tex
\foreach \cmd/\name [count=\i from 1] in {
    \! / Neg. thin space,
    \, / Thin space,
    \: / Medium space,
    \; / Thick space,
    \quad / Quad,
    \qquad / Double quad
  }{
    \nskBlock[
      last-pos={right=5mm}, width=0cm,
      text-center={\nskIcon[name=arrow-right-to-line]{\cmd}Text},
      text-south={\name},
      fill={nskRed!\pct!nskBg},
    ]
  }

Customization

To ensure pixel-perfect rendering and broad compatibility across icon libraries, we rely on SVG vector graphics. However, LaTeX\LaTeX does not support vector graphics directly, so a preprocessing conversion must take place before you can use them.

This means that you cannot directly change icon properties on-the-fly. Neural Sketch allows you to modify both the color and border-size of the icon by altering the SVG properties before the icon is converted to a format accepted by LaTeX\LaTeX.

Tip

Every time you change one of these properties,Neural Sketch re-runs the conversion preprocessing stage

Icon Color

You can specify the icon color through the color= key:

\nskIcon[name=circle, color=nskRed]
examples-doc/icons-c.tex
  \foreach \i/\c[count=\x] in {
    brain/Red,cpu/Orange,memory-stick/MainAccent,
    brick-wall/Pink,bot/Blue,
    bug/SecondaryAccent,layers-2/Yellow
  } {
      \nskBlock*[
        last-pos-s={right=5mm},
        text-center={\nskIcon[name=\i, color=nsk\c]},
        % ...
      ]
		}

Icon Border size

You can specify the border-size as:

\nskIcon[name=circle, border-size=2.5]
examples-doc/icons-w.tex
\foreach \i[count=\x] in {
  brain, cpu, memory-stick, brick-wall,
  bot, bug, layers-2
} {
  \nskBlock*[
    last-pos-s={right=5mm},
    text-center={\nskIcon[name=\i, border-size=\w]},
    text-south={\w},
    % ...
  ]
}

The border-size accepts only floating point (fp) values, which are in the relative svg system.


Behind the Curtain – the pyfetch CLI

The TeX layer delegates all I/O to the Python helper pyfetch.py, invoked under \write18 (so remember to enable --shell-escape).
Four micro‑services form the backbone:

CLI sub‑commandResponsibility
fetch-lucideHTTP‑download an SVG by slug and drop it in icons/.
update-colorParse the SVG, rewrite every stroke="..." to your chosen hex (only if different).
update-strokeParse the SVG and updates the stroke-width="...
clean-lucideGarbage‑collect icons that are no longer referenced in the current run – keeping your repo diet‑friendly.

Limitation

Currently only one color or border-size per icon-name is supported.

Global Style Hooks

Neural‑Sketch exposes a quartet of package‑level keys so you can shape icon behaviour across all icons:

icon-type        = lucide       % future: fontawesome, tabler, …
icon-color       = nskFg        % default stroke colour
icon-width       = .5cm         % css‑like unit, any dimexpr
icon-height      = .5cm         % usually =width for square glyphs
icon-border-size = 2.0          % default stroke width applied pre‑conversion
icon-shift-y     = 0pt          % default vertical baseline offset
icon-outdir      = icons        % where processed SVGs live
icon-intdir      = out          % sub‑folder for pyfetch scratch files

Tweak them once in the preamble, watch every figure adapt automatically.

Garbage Collection – \nskCleanUnusedIcons

Unused icons are automatically purged and deleted. You can modify this behavior by specifying the icon-clean global options:

\usepackage[
  icon-clean=true,
]{neural-sketch}

If you want to manually clean the unused icons, At the end of each run, issue:

% Usually in \AtEndDocument
\nskCleanUnusedIcons

The macro walks the internal property list g__nsk_used_icons_prop, computes the set difference against files on disk, and delegates removal to pyfetch clean-lucide ….

Reference Table

PropTypeDefault
type?choicelucide
color?colornskFg
size?dimension5mm
width?dimension5mm
height?dimension5mm
border-size?floating point2.0
shift-y?dimension0pt
shift-y?dimension0pt
style?token list{}

On this page