Repository navigation
Expand file tree
/
Copy pathdemo-doc.tex
More file actions
170 lines (111 loc) · 4.11 KB
/
Copy pathdemo-doc.tex
File metadata and controls
170 lines (111 loc) · 4.11 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
\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}