Hello,
I have to include code snippets from F#. I am using listing but apparently it does not support F#. Anyone did that before, has some experience ? I cannot find anything.
Text Formatting ⇒ F# source code
F# source code
Hi,
the listings package offers you a machanism to define a new language; see section 3.2 Language definitions (p. 20ff) and section 4.18 Language definitions (p. 41ff) of the package documentation.
the listings package offers you a machanism to define a new language; see section 3.2 Language definitions (p. 20ff) and section 4.18 Language definitions (p. 41ff) of the package documentation.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
F# source code
I started defining F# for listing package. Just basic keywords and coloring. Font and signs looks not like f#. Anyone has some suggestions ?
Code: Select all
\documentclass[a4paper,11pt]{article}
\usepackage{listings}
\usepackage{color}
\definecolor{bluekeywords}{rgb}{0.13,0.13,1}
\definecolor{greencomments}{rgb}{0,0.5,0}
\definecolor{turqusnumbers}{rgb}{0.17,0.57,0.69}
\definecolor{redstrings}{rgb}{0.5,0,0}
\lstdefinelanguage{FSharp}
{morekeywords={let, new, match, with, rec, open, module, namespace, type, of, member, and, for, in, do, begin, end, fun, function, try, mutable, if, then, else},
keywordstyle=\color{bluekeywords},
sensitive=false,
morecomment=[l][\color{greencomments}]{///},
morecomment=[l][\color{greencomments}]{//},
morecomment=[s][\color{greencomments}]{{(*}{*)}},
morestring=[b]",
stringstyle=\color{redstrings}
}
\begin{document}
\lstset{language=FSharp}
\begin{lstlisting}
(* Fibonacci Number formula *)
let rec fib n =
match n with
| 0 | 1 -> n
| _ -> fib (n - 1) + fib (n - 2)
(* An alternative approach - a lazy recursive sequence of Fibonacci numbers *)
let rec fibs = seq {
yield! [1; 1];
for (x, y) in Seq.zip fibs (Seq.skip 1 fibs) -> x + y }
(* Print even fibs *)
[1 .. 10]
|> List.map fib
|> List.filter (fun n -> (n % 2) = 0)
|> printlist
(* Same thing, using Comprehension syntax *)
[ for i in 1..10 do
let r = fib i
if r % 2 = 0 then yield r ]
|> printlist
\end{lstlisting}
\end{document}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
F# source code
Please describe how F# code should look like in your opinion. For the present you can start with some supplements for the settings.krislodz wrote:[…] Font and signs looks not like f#. […]
Code: Select all
\lstset{
language=FSharp,
basicstyle=\ttfamily,
breaklines=true,
columns=fullflexible
}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: F# source code
localghost, code looks much neater with these options. I wanted to obtain Visual Studio look but with the current state i am very much satisfied. Thanks.