``ipytangle`` implements most of the`TangleKit <https://github.com/worrydream/Tangle/blob/master/TangleKit/TangleKit.js>`__baseline as markdown links. Because it adds no new notation, unrenderedTangle Markdown should still render in a useful way.

Generally, think of a link as:

.. code:: markdown

[what the user sees](#:tangle types)

In the link text, backticks, **\`\`** are used to represent a JavaScriptexpression that will be updated on user interaction, cascading updates,or other updates from the kernel. In addition to any variables definedwith ``ipytangle``, some `formatting <#Formatting>`__ libraries areprovided. ``window`` globals should also work :wink:.

Only the generated ``code`` blocks will be transformed, the rest of theelements (if any) will be preserved. This means you can use images,inside the label of a control, for example.

mark some text (which may have other fields) to only display based oncondition

.. code:: markdown

What's more foolish? The [`fool_is_more_foolish`](#:if)fool[](#:else)the fool who follows him(#:endif).

you may also have an ``else`` and any number of ``elif``\ s... becausethey are markdown span-level elements, you may use newlines for easierediting

.. code:: markdown

[`feeling == "bad"`](#:if) I have a bad feeling about this. [`feeling == "cautious"`](#:elif) You will never find a more wretched hive of scum and villainy. [](#:else) Search your feelings. [](#:endif)

display a view and update some ``type`` of variable. Additionally,``min``\ imum ``max``\ imum and ``step``-size values can be specified.

``[](#:<variable>:inline)``^^^^^^^^^^^^^^^^^^^^^^^^^^^

Replace the ``variable``, for which a linked widget has been registered(TBD) with the widget itself inline. > Needs research.

Widgets~~~~~~~

At it's core, ``ipytangle`` provides ``Tangle``, an IPython ``Widget``.Because of this, a ``Tangle`` can connect to any other IPython widgetsvia *traitlets* and ``links``. Unlike many widgets, a ``Tangle`` doesn'tdo much with its screen real estate, and might not be very interestingto put inside a layout. Yet.

There are several methods for creating a ``Tangle``.

``ipytangle.tangle``^^^^^^^^^^^^^^^^^^^^

As in the above example, this tries to be the most pythonic approach.

.. code:: python

from ipytangle import tangle

square = tangle(x=1, y=(1, lambda x: x*x))

print("square is", square) square.x = 2 print("y is", square.y)

.. parsed-literal::

square is <IPython.utils.traitlets.DynamicAutoTangle139717235746760 object at 0x7f1274347ef0> y is 4

Linking to other widgets''''''''''''''''''''''''

``tangle`` makes working with other core and custom widgets easy,automatically copying trait information. If a widget implements``value``, as most of the core widgets do, you can reference itdirectly. Alternately, specify a ``tuple`` of ``(widget, "trait_name")``to subscribe to that trait.

.. code:: python

from IPython.html.widgets import IntSlider

x = IntSlider(1) square = tangle(x=x, y=(1, lambda x: x*x))

print("square is", square) x.value = 2 print("y is", square.y)

.. parsed-literal::

square is <IPython.utils.traitlets.DynamicAutoTangle139717235839048 object at 0x7f1274362080> y is 4

``ipytangle.Tangle``^^^^^^^^^^^^^^^^^^^^

If you are already familiar with widgets, subclassing ``Tangle`` mightbe the most convenient: