Neural Sketch

Embed Graphics

Learn how to embed graphics and customize their appearance within Neural Sketch blocks.

Introduction

Embedding graphics in your diagrams enhances visual expressiveness and clarity, allowing you to effortlessly integrate images, illustrations, or external content. Neural Sketch provides two convenient embedding mechanisms: gfx embedding and custom embedding.

Universal Raster Embedding

Neural Sketch offers robust, universal raster embedding features capable of automatically adapting graphics to any block shape. It also supports precise cropping, clipping, and customization to fit your exact diagramming needs.

Quick Usage

Use the embed-gfx key to quickly insert and automatically scale graphics to fit block dimensions:

embed-gfx=<gfx-path>

For advanced control, the embed key allows you to directly inject custom TikZ commands:

embed={
    <custom wrapper>
},

Embedding Graphics

Below are examples showcasing how to use embedding effectively.

Simple Graphic Embed

Embed and scale graphics directly using a straightforward, one-line syntax:

Comparison of Embed Types

Here's a comprehensive example illustrating both raw and gfx embeddings:

\nskBlock[
  embed-gfx={../assets/in.png},
]
Embedding Comparison

Embedding in Custom Shapes

Neural Sketch automatically adapts embedded graphics to various block shapes. Here’s how graphics seamlessly fit into different geometrical primitives:

\nskContainer[
  text-north={Custom Shapes Block Embedding},
  text-north-loc=west,
  border-type=dashed,
  fill=nskMainAccent!30,
  border-color=nskMainAccent,
]{
  \foreach \shape in {rectangle, circle, diamond, trapezium, semicircle}{
    \nskBlock[
      type=\shape,
      width=2cm, height=2cm,
      last-pos-s={right=.8cm},
      embed={
        \node[] {
          \includegraphics[width=4cm, height=2cm]{../assets/in.png};
        };
      },
    ]
  }
}
Custom Shapes Embedding

Customizing Padding

Control the spacing between your embedded graphics and block boundaries using embed-padding:

\nskBlock[
  embed-gfx={../assets/in.png},
  embed-padding=<padding-size> 
]

Here's a practical demonstration:

\nskContainer[
  text-north={Variable Embed Padding},
  text-north-loc=west,
  border-type=dashed,
  fill=nskSecondaryAccent!30,
  border-color=nskSecondaryAccent,
]{
  \foreach \p in {0,...,4} {
    \nskBlock[
      type=rectangle,
      last-pos-s={right=1cm},
      width=2cm, height=2cm,
      text-north={\p mm},
      border-type=solid,
      embed-gfx={../assets/in.png},
      embed-padding={\p mm}
    ]
  }
}
Embed Padding Variation

Customizing Border Radius

Adjust the rounding of corners for embedded content using embed-border-radius:

\nskBlock[
  embed-gfx={../assets/in.png},
  embed-border-radius=<radius-size> 
]

A visual example:

\nskContainer[
  text-north={Variable Embed Border Radius},
  text-north-loc=west,
  border-type=dashed,
  fill=nskSecondaryAccent!30,
  border-color=nskSecondaryAccent,
]{
  \foreach \r in {0,...,4} {
    \nskBlock[
      type=rectangle,
      last-pos-s={right=1cm},
      width=2cm, height=2cm,
      text-north={\r mm},
      border-type=solid,
      embed-gfx={../assets/in.png},
      embed-border-radius={\r mm},
      border-radius={\r mm},
    ]
  }
}
Embed Border Radius Variation

Reference

PropTypeDefault
embed-gfx?string{}
embed?TikZ code{}
embed-padding?dimension1mm
embed-border-radius?dimension1.3mm

Best Practices

  • Use gfx embedding for quick, proportional scaling.
  • Choose raw embedding for granular control of dimensions and alignment.
  • Consistently adjust padding and border-radius to achieve visual harmony.

On this page