Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
196 lines (127 sloc) 4.75 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 literate F\# script
files (\texttt{*.fsx}) that can be transformed into nice HTML
using the \texttt{literate.fsx} script from the \href{}{F\# 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:
\item Unordered or ordered lists
\item Text formatting including \textbf{bold} and \emph{emphasis}
And numerous other \href{}{Markdown} features.
\subsection*{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).
\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}
The value will be deffined in the F\# code 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{=} \id{hidden}
\subsection*{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 \texttt{include} and \texttt{define} commands.
The following snippet gets correct tool tips, even though
it uses \texttt{laterFunction}:
\begin{Verbatim}[commandchars=\\\{\}, numbers=left]
\kwd{let} \id{sample} \ops{=}
\ops{|>} \lfun{printfn} \str{"Got: }\lprf{\%s}\str{"}
Then we can explain how \texttt{laterFunction} is defined:
\begin{Verbatim}[commandchars=\\\{\}, numbers=left]
\kwd{let} \lfun{laterFunction}() \ops{=}
\str{"Not very difficult, is it?"}
This example covers pretty much all features that are
currently implemented in \texttt{literate.fsx}, but feel free
to \href{}{fork the project on GitHub} and add more
features or report bugs!
\subsection*{Other features}
The tool-tips also work for double-backtick identifiers.
This might be useful to generate nice documents from tests:
\begin{Verbatim}[commandchars=\\\{\}, numbers=left]
\kwd{let} \lfun{``1 + 1 should be equal to 2``}() \ops{=}
\num{1} \ops{+} \num{1} \ops{=} \num{2}
Others examples follow here.