Neural Sketch
Environments

nsk@Switch

Comprehensive documentation on conditional rendering using nskSwitch.

Introduction

The nskSwitch environment in Neural Sketch provides a powerful yet intuitive way to conditionally render content based on a specified operand, closely mirroring the familiar concept of a "switch-case" construct found in many programming languages. This functionality significantly simplifies the process of generating dynamic, multi-state diagrams, ensuring flexibility while maintaining readability and simplicity.

Syntax

The environment accepts an optional argument [<options>] and a mandatory operand argument {<operand>}:

\begin{nskSwitch}[<options>]{<operand>}
  % conditional cases
\end{nskSwitch}

Parameters

  • options [optional]: A set of key-value pairs to configure global rendering behavior.
  • operand {mandatory}: The value to test against case conditions defined within the environment.

Basic Usage

A basic implementation of nskSwitch might look like:

\begin{nskSwitch}{state}
  \nskCase{start}{ % rendered if state == start
    % diagram components for 'start' state
  }
  \nskCase{middle}{ % rendered if state == middle
    % diagram components for 'middle' state
  }
  \nskCase{end}{ % rendered if state == end
    % diagram components for 'end' state
  }
\end{nskSwitch}

Example: Dynamic Diagram

Here's an illustrative example showcasing conditional rendering based on the diagram state:

\begin{nskSwitch}{active}
  \nskCase{active}{
    \nskBlock[fill=nskGreen, text-center={Active State}]
  }
  \nskCase{inactive}{
    \nskBlock[fill=nskRed, text-center={Inactive State}]
  }
\end{nskSwitch}

Comphrensive Guide

For a Comprehensive usage, please check Conditional Rendering

Reference

PropTypeDefault
type?choicestring

On this page