# Literate script side-by-side example

  1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91:  (** Literate script =============== This file demonstrates how to write literate F# script files (*.fsx) that can be transformed into nice HTML using the literate.fsx script from the [F# Formatting package](http://fsprojects.github.io/FSharp.Formatting). As you can see, a comment starting with double asterisk is treated as part of the document and is transformed using Markdown, which means that you can use: - Unordered or ordered lists - Text formatting including **bold** and _emphasis_ And numerous other [Markdown][md] features. [md]: http://daringfireball.net/projects/markdown Writing F# code --------------- Code that is not inside comment will be formatted as a sample snippet (which also means that you can run it in Visual Studio or MonoDevelop). *) /// The Hello World of functional languages! let rec factorial x = if x = 0 then 1 else x * (factorial (x - 1)) let f10 = factorial 10 (** Hiding code ----------- If you want to include some code in the source code, but omit it from the output, you can use the hide command. *) (*** hide ***) /// This is a hidden answer let hidden = 42 (** The value will be defined in the F# code and so you can use it from other (visible) code and get correct tool tips: *) let answer = hidden (** Moving code around ------------------ Sometimes, it is useful to first explain some code that has to be located at the end of the snippet (perhaps because it uses some definitions discussed in the middle). This can be done using include and define commands. The following snippet gets correct tool tips, even though it uses laterFunction: *) (*** include:later-bit ***) (** Then we can explain how laterFunction is defined: *) let laterFunction() = "Not very difficult, is it?" (** This example covers pretty much all features that are currently implemented in literate.fsx, but feel free to [fork the project on GitHub][fs] and add more features or report bugs! [fs]: https://github.com/fsprojects/FSharp.Formatting *) (*** define:later-bit ***) let sample = laterFunction() |> printfn "Got: %s" 

# Literate script

This file demonstrates how to write literate F# script files (*.fsx) that can be transformed into nice HTML using the literate.fsx script from the F# Formatting package.

As you can see, a comment starting with double asterisk is treated as part of the document and is transformed using Markdown, which means that you can use:

• Unordered or ordered lists
• Text formatting including bold and emphasis

And numerous other Markdown features.

## Writing F# code

Code that is not inside comment will be formatted as a sample snippet (which also means that you can run it in Visual Studio or MonoDevelop).

 1: 2: 3: 4: 5: 6:  /// The Hello World of functional languages! let rec factorial x = if x = 0 then 1 else x * (factorial (x - 1)) let f10 = factorial 10 

## Hiding code

If you want to include some code in the source code, but omit it from the output, you can use the hide command.

The value will be defined in the F# code and so you can use it from other (visible) code and get correct tool tips:

 1:  let answer = hidden 

## Moving code around

Sometimes, it is useful to first explain some code that has to be located at the end of the snippet (perhaps because it uses some definitions discussed in the middle). This can be done using include and define commands.

The following snippet gets correct tool tips, even though it uses laterFunction:

 1: 2: 3:  let sample = laterFunction() |> printfn "Got: %s" 

Then we can explain how laterFunction is defined:

 1: 2:  let laterFunction() = "Not very difficult, is it?" 

This example covers pretty much all features that are currently implemented in literate.fsx, but feel free to fork the project on GitHub and add more features or report bugs!

val factorial : x:int -> int

Full name: Sidescript.factorial

The Hello World of functional languages!
val x : int
val f10 : int

Full name: Sidescript.f10
val hidden : int

Full name: Sidescript.hidden