Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
171 lines (111 sloc) 4.11 KB
% Defining colors by names
% Verbatim enviroment
% Verbatim enviroment for unformatted source code
% Better font for backslash
% Providing more features than usual tabular
% Remember to use big letters for color codes
% Reference at
% Identifiers
% Strings
% Keywords
% Comments
% Operators
% Numbers
% Line number
% Types or modules
% Functions
% Patterns
% Mutable vars
% Printf
% Escaped characters
% Inactive elements
% Preprocessors
% fsi output
% Omitted parts
% Overriding color and style of line numbers
\lines{\small \arabic{FancyVerbLine}:}}
\title{Literate sample
\section*{Literate sample}
This file demonstrates how to write Markdown document with
embedded F\# snippets that can be transformed into nice HTML
using the \texttt{literate.fsx} script from the \href{}{F\# Formatting
In this case, the document itself is a valid Markdown and
you can use standard Markdown features to format the text:
\item Here is an example of unordered list and...
\item Text formatting including \textbf{bold} and \emph{emphasis}
For more information, see the \href{}{Markdown} reference.
\subsection*{Writing F\# code}
In standard Markdown, you can include code snippets by
writing a block indented by four spaces and the code
snippet will be turned into a \texttt{<pre>} element. If you do
the same using Literate F\# tool, the code is turned into
a nicely formatted F\# snippet:
\begin{Verbatim}[commandchars=\\\{\}, numbers=left]
\com{/// The Hello World of functional languages!}
\kwd{let} \kwd{rec} \lfun{factorial} \id{x} \ops{=}
\kwd{if} \id{x} \ops{=} \num{0} \kwd{then} \num{1}
\kwd{else} \id{x} \ops{*} (\lfun{factorial} (\id{x} \ops{-} \num{1}))
\kwd{let} \id{f10} \ops{=} \lfun{factorial} \num{10}
\subsection*{Hiding code}
If you want to include some code in the source code,
but omit it from the output, you can use the \texttt{hide}
command. You can also use \texttt{module=...} to specify that
the snippet should be placed in a separate module
(e.g. to avoid duplicate definitions).
The value will be deffined in the F\# code that is
processed and so you can use it from other (visible)
code and get correct tool tips:
\begin{Verbatim}[commandchars=\\\{\}, numbers=left]
\kwd{let} \id{answer} \ops{=} \ltyp{Hidden}\ops{.}\id{answer}
\subsection*{Including other snippets}
When writing literate programs as Markdown documents,
you can also include snippets in other languages.
These will not be colorized and processed as F\#
code samples:
Console.WriteLine("Hello world!");
This snippet is turned into a \texttt{pre} element with the
\texttt{lang} attribute set to \texttt{csharp}.