Neural Sketch
Commands

nsk@BlockID

Retrieve block identifiers for precise referencing and positioning.

Introduction

In complex diagrams created using Neural Sketch, referencing previously defined blocks accurately is essential. The macro \nskBlockID enables straightforward retrieval of block identifiers, facilitating clear and precise referencing, relative positioning, and annotation.

This capability greatly simplifies maintaining coherence and consistency throughout your diagrams, especially when handling large-scale visualizations.


Usage

Basic Usage

The \nskBlockID macro returns the identifier of the current block (the block most recently defined). It's typically used within custom commands or positioning references.

\nskBlock[id=myBlock]{...}
 
% Reference the current block ID (returns "myBlock")
Current Block ID: \nskBlockID

Automatic IDs

If no explicit ID is provided when creating a block, Neural Sketch automatically generates one using a combination of the shape type and an incremental index:

\nskBlock[type=rectangle]{...}
\nskBlock[type=circle]{...}
 
% Retrieves auto-generated IDs like "rectangle1", "circle1", etc.
Auto-generated ID: \nskBlockID

Recommendation

Always explicitly provide an ID for clarity, especially when creating complex diagrams. This practice ensures readability and maintainability.


Accessing Previous Block IDs

To retrieve identifiers of previously defined blocks, use the related commands:

\nskLastBlockID

Returns the ID of the block immediately preceding the current block:

\nskBlock[id=firstBlock]{...}
\nskBlock[id=secondBlock]{...}
 
Previous Block ID: \nskLastBlockID % returns "firstBlock"

\nskBlockIDLast[n]

Provides access to the nth-last defined block ID, with [1] indicating the most recently created block, [2] the second most recent, and so forth:

\nskBlock[id=blockA]{...}
\nskBlock[id=blockB]{...}
\nskBlock[id=blockC]{...}
 
Second Last Block ID: \nskBlockIDLast[2] % returns "blockB"

Error Handling

Attempting to reference a block index larger than the total number of defined blocks triggers a LaTeX error. Always ensure the requested block exists.


Practical Example

Here's how you might use block IDs for positioning:

\begin{nskFigure}
  \nskBlock[text-north={\nskBlockID}]
  \nskBlock[last-pos={below=1cm}, text-north={\nskBlockID}]
\end{nskFigure}

In this example:

  • The auto-generated IDs of each block is displayed on top of each block.

Use Cases

Leveraging \nskBlockID is especially beneficial for:

  • Dynamic Positioning: Precisely position new diagram components relative to existing ones.
  • Annotation and Labeling: Automatically anchor annotations and labels to relevant blocks.
  • Advanced Automation: Programmatically generate complex diagrams by iterating over block IDs.

On this page