Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
171 lines (111 sloc) 4.11 KB
\documentclass{article}
% Defining colors by names
\usepackage{xcolor}
% Verbatim enviroment
\usepackage{fancyvrb}
% Verbatim enviroment for unformatted source code
\usepackage{listings}
% Better font for backslash
\usepackage[T1]{fontenc}
\usepackage{hyperref}
% Providing more features than usual tabular
\usepackage{longtable}
% NOTE:
% Remember to use big letters for color codes
% Reference at http://tex.stackexchange.com/questions/18008/use-css-style-color-specifications-in-xcolor
% Identifiers
\newcommand{\id}[1]{\textcolor[HTML]{000000}{#1}}
% Strings
\newcommand{\str}[1]{\textcolor[HTML]{A31515}{#1}}
% Keywords
\newcommand{\kwd}[1]{\textcolor[HTML]{0000FF}{#1}}
% Comments
\newcommand{\com}[1]{\textcolor[HTML]{008000}{#1}}
% Operators
\newcommand{\ops}[1]{\textcolor[HTML]{000000}{#1}}
% Numbers
\newcommand{\num}[1]{\textcolor[HTML]{000000}{#1}}
% Line number
\newcommand{\lines}[1]{\textcolor[HTML]{96C2CD}{#1}}
% Types or modules
\newcommand{\ltyp}[1]{\textcolor[HTML]{2B91AF}{#1}}
% Functions
\newcommand{\lfun}[1]{\textcolor[HTML]{0000A0}{#1}}
% Patterns
\newcommand{\lpat}[1]{\textcolor[HTML]{800080}{#1}}
% Mutable vars
\newcommand{\lvar}[1]{\textbf{\textcolor[HTML]{000000}{#1}}}
% Printf
\newcommand{\lprf}[1]{\textcolor[HTML]{2B91AF}{#1}}
% Escaped characters
\newcommand{\lesc}[1]{\textcolor[HTML]{FF0080}{#1}}
% Inactive elements
\newcommand{\inact}[1]{\textcolor[HTML]{808080}{#1}}
% Preprocessors
\newcommand{\prep}[1]{\textcolor[HTML]{0000FF}{#1}}
% fsi output
\newcommand{\fsi}[1]{\textcolor[HTML]{808080}{#1}}
% Omitted parts
\newcommand{\omi}[1]{\textcolor[HTML]{808080}{#1}}
% Overriding color and style of line numbers
\renewcommand{\theFancyVerbLine}{
\lines{\small \arabic{FancyVerbLine}:}}
\lstset{%
backgroundcolor=\color{gray!15},
basicstyle=\ttfamily,
breaklines=true,
columns=fullflexible
}
\title{Literate sample
}
\date{}
\begin{document}
\maketitle
\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{http://fsprojects.github.io/FSharp.Formatting}{F\# Formatting
package}.
In this case, the document itself is a valid Markdown and
you can use standard Markdown features to format the text:
\begin{itemize}
\item Here is an example of unordered list and...
\item Text formatting including \textbf{bold} and \emph{emphasis}
\end{itemize}
For more information, see the \href{http://daringfireball.net/projects/markdown}{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}
\end{Verbatim}
\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}
\end{Verbatim}
\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:
\begin{lstlisting}
Console.WriteLine("Hello world!");
\end{lstlisting}
This snippet is turned into a \texttt{pre} element with the
\texttt{lang} attribute set to \texttt{csharp}.
\end{document}