tangledown.org
Examples
Cookies
Mortgage
Syntax
TangleDown Syntax
Back to Page
TangleDown is generally added to a Markdown document by - creating "fenced code" blocks of initial variable values and relationships between variables - creating inline `t[]()` tags for views of variables - creating block header `t[]()` tags for branching constructs based on variables ## Code Blocks The goal of TangleDown is to not feel too much like coding, but we need to know a little more than how you want to view and interact with your data. To make your document reactive, TangleDown needs two types of code: `initialize` and `update`. A variable, used in a view somewhere, needs to appear in either or both code blocks in order to work properly. ### `initialize` Any number of `initialize` fenced code blocks will be read, and the variables mentioned there will be created and available for use when the page loads. ~~~~.initialize #cookies: 1 ~~~~ will get magically munged into. This is probably a huge XSS vulnerability: working on it. ~~~~.javascript this.cookies = 1 ~~~~ Immediately after `initialize` is called, and every time a viewer interacts with a view, all `update` expressions will be reevaluated. ~~~~.update #calories: #cookies * 50 ~~~~ will become: ~~~~.javascript this.calories = this.cookies * 50 ~~~~ Right now, the translation is pretty minimal, so basically you'll have to use JavaScript math notation, except with the `#` notation... hopefully this makes it a little easier to read the "code", without taking away too much power. A lot of useful operators are available out of the box: +, /, %, * while the `Math` object provides many others: _from [javascripters](http://www.javascripter.net/faq/mathfunc.htm)_ Math.abs(a) // the absolute value of a Math.acos(a) // arc cosine of a Math.asin(a) // arc sine of a Math.atan(a) // arc tangent of a Math.atan2(a,b) // arc tangent of a/b Math.ceil(a) // integer closest to a and not less than a Math.cos(a) // cosine of a Math.exp(a) // exponent of a (Math.E to the power a) Math.floor(a) // integer closest to a, not greater than a Math.log(a) // log of a base e Math.max(a,b) // the maximum of a and b Math.min(a,b) // the minimum of a and b Math.pow(a,b) // a to the power b Math.random() // pseudorandom number 0 to 1 (see examples) Math.round(a) // integer closest to a (see rounding examples) Math.sin(a) // sine of a Math.sqrt(a) // square root of a Math.tan(a) // tangent of a ## Basic Number View ~~~~.initialize #answer: 42 #heads: 2 #tenses: 1001 #timessmarter: 30000000000 ~~~~ The basic Tangle number view is a display-only, inline text span which will show a variable, such that typing The answer to life, the universe and everything is t[](answer) will create > The answer to life, the universe and everything is t[](answer) Basic views can optionally be formatted and labeled: Zaphod has t[](heads ' heads') will create > Zaphod has t[](heads ' heads') while I am at a rough estimate t[](timessmarter humanized ' times') more intelligent than you will create > I am at a rough estimate t[](timessmarter humanized ' times') more intelligent than you ## Editable Views The real power of Tangle lies in the intuitive editable views. Several are available from TangleKit. ### Adjustable Number ~~~~.initialize #years: 7 ~~~~ ~~~~.update #days: #years * 365 ~~~~ The adjustable number provides a lot of flexiblity without requiring too much extra definition. The basic form shows a whole number (non-negative integer), which can be clicked on and dragged to the right or the left to change numbers: I am t[number](years ' years old'), so have been alive at least t[](days ' days') yields > I am t[number](years ' years old'), so have been alive at least t[](days ' days'). `number` can be customized with minimum, maxmimum and increment values (as well as formats and labels like the read-only view). All are optional. I am t[number](10<years..10<100 ' years old'), so have been alive at least t[](days ' days') yields > I am t[number](10<years..100 ' years old'), so have been alive at least t[](days ' days'). ### Number Field View Sometimes, just typing a number is more intuitive than hunting for it through clicking and dragging. TangleKit provides for this case: I am t[field](years) old, so have been alive at least t[](days ' days'). yields > I am t[field](years) old, so have been alive at least t[](days ' days'). ## Branching ~~~~.initialize #lights: 0 ~~~~ ~~~~.update #kilowatts: #lights * 100 ~~~~ TangleDown can create several kinds of branching, so that parts of your document show up when certain conditions are met, sort of like "choose your own adventures". The simplest type is an interactive view which changes a variable between _0_ and _1_. The lights are t[toggle](lights)[off][on]. You are using t[](kilowatts ' kW') makes > The lights are t[toggle](lights)[off, and it is very dark in here ][on and it is very bright]. You are using t[](kilowatts ' kW') If you have more to say than you t[switch](lights) | It is dark. You might be eaten by a grue. | In the glaring light, at least you can see the grue. creates > t[switch](lights) > | It is dark. You might be eaten by a grue. > > | In the glaring light, at least you can see the grue. ## Formats Formatting either uses the `sprintf` technique, which feels a lot like coding, but gets the job done. Additionally, some more formatters are available, which return the values as: `cents_as_dollars` : number of pennies as dollars and cents > `1000` to _$10.00_ `humanized` : spelled out in english words > `12007021 to _one million two hundred thousand seven hundred two_ `p3` : decimal with precision to the thousandths > `.0011231` to _.001_ `neg_p3` : negative value with precision to the thousandths > `.0011231` to _-.001_ `p3` : decimal with precision to the hundredths > `.011231` to _.01_ `e6` : floored to the millions > `12007021` to _1_ `abs_e6` : floored to the millions, absolute > `-12007021` to _1_ `freq` : as a frequency > `3000` to _3 KHz_ `dollars` : dollars without cents > `10.01` to _$10_ `free` : like dollars, but free if zero > `0.0` to _free_ `percent` : a percent > `.7121` to _71%_
Navigate
Home
Sympy
Coins
TangleDown Syntax
Mortgage