First commit.

master
Karchnu 2021-10-11 05:57:55 +02:00
commit 88b6e082d0
10 changed files with 1218 additions and 0 deletions

View File

@ -0,0 +1,71 @@
extension "groff"
doctemplate
"
.MT 0
$header
.TL
$title
.AU \"\"
.ND
.SA 0
.DS I
"
".DE
$footer
"
end
nodoctemplate
"
"
"
"
end
bold "\f[CB]$text\fP"
italics "\f[CI]$text\fP"
underline "\f[CI]$text\fP"
fixed "\fC$text\fP"
color "\m[$style]$text\m[]"
anchor "$infilename : $linenum - $text"
reference "$text \(-> $infile:$linenum, page : $infilename:$linenum"
#lineprefix "\fC\(em\fP "
#lineprefix "\fC\n(ln\fP "
lineprefix ""
colormap
"green" "green"
"red" "red"
"darkred" "darkred"
"blue" "blue"
"brown" "brown"
"pink" "pink"
"yellow" "yellow"
"cyan" "cyan"
"purple" "purple"
"orange" "orange"
"brightorange" "brightorange"
"brightgreen" "brightgreen"
"darkgreen" "darkgreen"
"black" "black"
"teal" "teal"
"gray" "gray"
"darkblue" "darkblue"
default "black"
end
translations
"\\" "\\\\"
##"\n" " \\\\\n"
##" " "\\ "
##"\t" "\\ \\ \\ \\ \\ \\ \\ \\ "
"\t" " "
"|" "|"
"---" "\(em"
"--" "\(mi"
end

8
Makefile Normal file
View File

@ -0,0 +1,8 @@
SRC ?= main
ODIR ?= /tmp/
export ODIR SRC
include Makefile.in
upload:
scp $(SRC).pdf tacos:/var/www/htdocs/t.karchnu.fr/doc/

74
Makefile.in Normal file
View File

@ -0,0 +1,74 @@
SRC ?= haskelltut
ODIR ?= .
BIBLIOGRAPHY ?= bibliography
ALLSRC = $(shell find . -name "*.ms")
SOELIM_OPTS ?=
SOELIM = soelim $(SOELIM_OPTS)
SPECHAR = ./bin/utf8-to-ms.sh
PRECONV_OPTS ?= -e utf-8
PRECONV = preconv $(PRECONV_OPTS)
EQN_OPTS ?= -Tpdf
EQN = eqn $(EQN_OPTS)
# source-highlight stuff
# GH_INTRO: instructions before each source code provided by source-highlight
# GH_OUTRO: ------------ after ---- ------ ---- -------- -- ----------------
# GH_INTRO/GH_OUTRO: values are separated by ';'
#
GH_INTRO := .b1;.nr DI 0;.DS I;.fam C
GH_OUTRO := .fam;.DE;.b2
#
export GH_INTRO
export GH_OUTRO
#
# SHOPTS: cmd line parameter given to source-highlight
SHOPTS = --outlang-def=.source-highlight_groff-output-definition
export SHOPTS
# ghighlight brings `source-highlight` to troff
GHIGHLIGHT_OPTS ?=
GHIGHLIGHT = ./bin/ghighlight $(GHIGHLIGHT_OPTS)
GRAP_OPTS ?=
GRAP = grap $(GRAP_OPTS)
PIC_OPTS ?= -Tpdf
PIC = pic $(PIC_OPTS)
# -P => move ponctuation after reference
# -S => label and bracket-label options
# -e => accumulate (use a reference section)
# -p bib => bibliography file
REFER_OPTS ?= -PS -e -p $(BIBLIOGRAPHY)
REFER = refer $(REFER_OPTS)
# -k => iconv conversion (did it ever worked?)
# -ms => ms macro
# -U => unsafe (because of PDF inclusion)
# -Tpdf => output device is PDF
# -mspdf => include PDF (so, images converted in PDF) in the document
GROFF_OPTS ?= -ms -t -Tpdf -U -mspdf -mpdfmark
GROFF = groff $(GROFF_OPTS)
$(SRC).pdf:
cat $(SRC).ms |\
$(SOELIM) |\
$(SPECHAR) |\
$(PRECONV) |\
$(EQN) |\
$(GHIGHLIGHT) |\
$(GRAP) |\
$(PIC) |\
$(REFER) |\
$(GROFF) > $(ODIR)/$@
# Keep options in memory for the recursive 'make' call
export SOELIM_OPTS PRECONV_OPTS EQN_OPTS GHIGHLIGHT_OPTS GRAP_OPTS PIC_OPTS REFER_OPTS
serve:
find . -name "*.ms" | entr gmake -B $(SRC).pdf

BIN
are-you.pdf Normal file

Binary file not shown.

13
bibliography Normal file
View File

@ -0,0 +1,13 @@
%K a-universe-from-nothing
%A Lawrence Krauss
%T a Universe from Nothing
%D 2012
%I Simon & Schuster
%K learnhaskell
# \o = following symbols are overlapping in the same space
# \[ah] = caron accent
%A Miran Lipova\o'c\[ah]'a
%T Learn You a Haskell for Great Good!
%D 2011
%I No Starch Press

286
bin/ghighlight Executable file
View File

@ -0,0 +1,286 @@
#! /usr/bin/env perl
# ghighlight - A simple preprocessor for adding code highlighting in a groff file
# Copyright (C) 2014-2018 Free Software Foundation, Inc.
# Written by Bernd Warken <groff-bernd.warken-72@web.de>.
my $version = '0.9.0';
# This file is part of 'ghighlight', which is part of 'groff'.
# 'groff' is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# 'groff' is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# You can find a copy of the GNU General Public License in the internet
# at <http://www.gnu.org/licenses/gpl-2.0.html>.
########################################################################
use strict;
use warnings;
#use diagnostics;
# current working directory
use Cwd;
# $Bin is the directory where this script is located
use FindBin;
# open3 for a bidirectional communication with a child process
use IPC::Open3;
########################################################################
# system variables and exported variables
########################################################################
$\ = "\n"; # final part for print command
########################################################################
# read-only variables with double-@ construct
########################################################################
our $File_split_env_sh;
our $File_version_sh;
our $Groff_Version;
my $before_make; # script before run of 'make'
{
my $at = '@';
$before_make = 1 if '@VERSION@' eq "${at}VERSION${at}";
}
my %at_at;
my $file_perl_test_pl;
my $groffer_libdir;
if ($before_make) {
my $highlight_source_dir = $FindBin::Bin;
$at_at{'BINDIR'} = $highlight_source_dir;
$at_at{'G'} = '';
} else {
$at_at{'BINDIR'} = '@BINDIR@';
$at_at{'G'} = '@g@';
}
########################################################################
# options
########################################################################
foreach (@ARGV) {
if ( /^(-h|--h|--he|--hel|--help)$/ ) {
print q(Usage for the 'ghighlight' program:);
print 'ghighlight [-] [--] [filespec...] normal file name arguments';
print 'ghighlight [-h|--help] gives usage information';
print 'ghighlight [-v|--version] displays the version number';
print q(This program is a 'groff' preprocessor that handles highlighting source code ) .
q(parts in 'roff' files.);
exit;
} elsif ( /^(-v|--v|--ve|--ver|--vers|--versi|--versio|--version)$/ ) {
print q('ghighlight' version ) . $version;
exit;
}
}
my $macros = "groff_mm";
if ( $ENV{'GHLENABLECOLOR'} ) {
$macros = "groff_mm_color";
}
########################################################################
# input
########################################################################
my $source_mode = 0;
my @lines = ();
sub getTroffLine {
my ($opt) = @_;
if ($opt =~ /^ps=([0-9]+)/) {".ps $1"}
elsif ($opt =~ /^vs=(\S+)/) {".vs $1"}
else { print STDERR "didn't recognised '$opt'"; ""}
}
sub getTroffLineOpposite {
my ($opt) = @_;
if ($opt =~ /^ps=/) {".ps"}
elsif ($opt =~ /^vs=/) {".vs"}
else { print STDERR "didn't recognised '$opt'"; ""}
}
# language for codeblocks
my $lang = '';
my @options = ();
foreach (<>) {
chomp;
s/\s+$//;
my $line = $_;
my $is_dot_Source = $line =~ /^[.']\s*(``|SOURCE)(|\s+.*)$/;
unless ( $is_dot_Source ) { # not a '.SOURCE' line
if ( $source_mode ) { # is running in SOURCE mode
push @lines, $line;
} else { # normal line, not SOURCE-related
print $line;
}
next;
}
##########
# now the line is a '.SOURCE' line
my $args = $line;
$args =~ s/\s+$//; # remove final spaces
$args =~ s/^[.']\s*(``|SOURCE)\s*//; # omit .source part, leave the arguments
my @args = split /\s+/, $args;
##########
# start SOURCE mode
$lang = $args[0] if ( @args > 0 && $args[0] ne 'stop' );
if ( @args > 0 && $args[0] ne 'stop' ) {
# For '.``' no args or first arg 'start' means opening 'SOURCE' mode.
# Everything else means an ending command.
shift @args;
@options = @args;
if ( $source_mode ) {
# '.SOURCE' was started twice, ignore
print STDERR q('.``' starter was run several times);
next;
} else { # new SOURCE start
$source_mode = 1;
@lines = ();
next;
}
}
##########
# now the line must be a SOURCE ending line (stop)
unless ( $source_mode ) {
print STDERR 'ghighlight.pl: there was a SOURCE ending without being in ' .
'SOURCE mode:';
print STDERR ' ' . $line;
next;
}
$source_mode = 0; # 'SOURCE' stop calling is correct
my $shopts = $ENV{"SHOPTS"} || "";
##########
# Run source-highlight on lines
# Check if language was specified
my $cmdline = "source-highlight -f $macros $shopts --output STDOUT";
if ($lang ne '') {
$cmdline .= " -s $lang";
}
# Start `source-highlight`
my $pid = open3(my $child_in, my $child_out, my $child_err, $cmdline)
or die "open3() failed $!";
# Provide source code to `source-highlight` in its standard input
print $child_in $_ for @lines;
close $child_in;
if (my $v = $ENV{"GH_INTRO"}) {
print for split /;/, $v;
}
for (@options) {
my $l = getTroffLine $_;
print $l if ($l ne "");
}
# Print `source-highlight` output
while (<$child_out>) {
chomp;
print;
}
close $child_out;
for (reverse @options) {
my $l = getTroffLineOpposite $_;
print $l if ($l ne "");
}
if (my $v = $ENV{"GH_OUTRO"}) {
print for split /;/, $v;
}
my @print_res = (1);
# Start argument processing
# remove 'stop' arg if exists
# shift @args if ( $args[0] eq 'stop' );
# if ( @args == 0 ) {
# # no args for saving, so @print_res doesn't matter
# next;
# }
# my @var_names = ();
# my @mode_names = ();
# my $mode = '.ds';
# for ( @args ) {
# if ( /^\.?ds$/ ) {
# $mode = '.ds';
# next;
# }
# if ( /^\.?nr$/ ) {
# $mode = '.nr';
# next;
# }
# push @mode_names, $mode;
# push @var_names, $_;
# }
# my $n_vars = @var_names;
# if ( $n_vars < $n_res ) {
# print STDERR 'ghighlight: not enough variables for Python part: ' .
# $n_vars . ' variables for ' . $n_res . ' output lines.';
# } elsif ( $n_vars > $n_res ) {
# print STDERR 'ghighlight: too many variablenames for Python part: ' .
# $n_vars . ' variables for ' . $n_res . ' output lines.';
# }
# if ( $n_vars < $n_res ) {
# print STDERR 'ghighlight: not enough variables for Python part: ' .
# $n_vars . ' variables for ' . $n_res . ' output lines.';
# }
# my $n_min = $n_res;
# $n_min = $n_vars if ( $n_vars < $n_res );
# exit unless ( $n_min );
# $n_min -= 1; # for starting with 0
# for my $i ( 0..$n_min ) {
# my $value = $print_res[$i];
# chomp $value;
# print $mode_names[$i] . ' ' . $var_names[$i] . ' ' . $value;
# }
}
1;
# Local Variables:
# mode: CPerl
# End:

147
bin/utf8-to-ms.sh Executable file
View File

@ -0,0 +1,147 @@
#!/bin/sh
# This program isn't by any mean complete.
# Most of text markers, accents and ligatures are handled.
# However, nothing else currently is.
# Please, do provide more translations.
# Convert input into hexadecimal and a single byte per line.
to_hex_one_column() xxd -p -c 1
# Reverse hexadecimal to original value.
from_hex() xxd -p -r
regroup_lines() awk '
BEGIN {
line_start=1
}
{
if (line_start == 1)
line = $1;
else
line = line " " $1;
line_start = 0;
if ($1 == "0a") {
print line;
line_start = 1
}
}
END {
if (line_start == 0)
print line
}
'
accents() sed \
-e "s/c3 81/5c 5b 27 41 5d/g"\
-e "s/c3 89/5c 5b 27 45 5d/g"\
-e "s/c3 8d/5c 5b 27 49 5d/g"\
-e "s/c3 93/5c 5b 27 4f 5d/g"\
-e "s/c3 9a/5c 5b 27 55 5d/g"\
-e "s/c3 9d/5c 5b 27 59 5d/g"\
-e "s/c3 a1/5c 5b 27 61 5d/g"\
-e "s/c3 a9/5c 5b 27 65 5d/g"\
-e "s/c3 ad/5c 5b 27 69 5d/g"\
-e "s/c3 b3/5c 5b 27 6f 5d/g"\
-e "s/c3 ba/5c 5b 27 75 5d/g"\
-e "s/c3 bd/5c 5b 27 79 5d/g"\
-e "s/c3 84/5c 5b 3a 41 5d/g"\
-e "s/c3 8b/5c 5b 3a 45 5d/g"\
-e "s/c3 8f/5c 5b 3a 49 5d/g"\
-e "s/c3 96/5c 5b 3a 4f 5d/g"\
-e "s/c3 9c/5c 5b 3a 55 5d/g"\
-e "s/c3 a4/5c 5b 3a 61 5d/g"\
-e "s/c3 ab/5c 5b 3a 65 5d/g"\
-e "s/c3 af/5c 5b 3a 69 5d/g"\
-e "s/c3 b6/5c 5b 3a 6f 5d/g"\
-e "s/c3 bc/5c 5b 3a 75 5d/g"\
-e "s/c3 bf/5c 5b 3a 79 5d/g"\
-e "s/c3 82/5c 5b 5e 41 5d/g"\
-e "s/c3 8a/5c 5b 5e 45 5d/g"\
-e "s/c3 8e/5c 5b 5e 49 5d/g"\
-e "s/c3 94/5c 5b 5e 4f 5d/g"\
-e "s/c3 9b/5c 5b 5e 55 5d/g"\
-e "s/c3 a2/5c 5b 5e 61 5d/g"\
-e "s/c3 aa/5c 5b 5e 65 5d/g"\
-e "s/c3 ae/5c 5b 5e 69 5d/g"\
-e "s/c3 b4/5c 5b 5e 6f 5d/g"\
-e "s/c3 bb/5c 5b 5e 75 5d/g"\
-e "s/c3 80/5c 5b 60 41 5d/g"\
-e "s/c3 88/5c 5b 60 45 5d/g"\
-e "s/c3 8c/5c 5b 60 49 5d/g"\
-e "s/c3 92/5c 5b 60 4f 5d/g"\
-e "s/c3 99/5c 5b 60 55 5d/g"\
-e "s/c3 a0/5c 5b 60 61 5d/g"\
-e "s/c3 a8/5c 5b 60 65 5d/g"\
-e "s/c3 ac/5c 5b 60 69 5d/g"\
-e "s/c3 b2/5c 5b 60 6f 5d/g"\
-e "s/c3 b9/5c 5b 60 75 5d/g"\
-e "s/c3 83/5c 5b 7e 41 5d/g"\
-e "s/c3 91/5c 5b 7e 4e 5d/g"\
-e "s/c3 95/5c 5b 7e 4f 5d/g"\
-e "s/c3 a3/5c 5b 7e 61 5d/g"\
-e "s/c3 b1/5c 5b 7e 6e 5d/g"\
-e "s/c3 b5/5c 5b 7e 6f 5d/g"\
-e "s/c3 87/5c 5b 2c 43 5d/g"\
-e "s/c3 a7/5c 5b 2c 63 5d/g"\
-e "s/c3 85/5c 5b 6f 41 5d/g"\
-e "s/c3 a5/5c 5b 6f 61 5d/g"\
-e "s/c5 b8/5c 5b 3a 59 5d/g"\
-e "s/c5 a0/5c 5b 76 53 5d/g"\
-e "s/c5 a1/5c 5b 76 73 5d/g"\
-e "s/c5 bd/5c 5b 76 5a 5d/g"\
-e "s/c5 be/5c 5b 76 7a 5d/g"
# Ligatures.
ligatures() sed \
-e "s/ef ac 80/5c 5b 66 66 5d/g"\
-e "s/ef ac 81/5c 5b 66 69 5d/g"\
-e "s/ef ac 82/5c 5b 66 6c 5d/g"\
-e "s/ef ac 83/5c 5b 46 69 5d/g"\
-e "s/ef ac 84/5c 5b 46 6c 5d/g"\
-e "s/c5 81/5c 5b 2f 4c 5d/g"\
-e "s/c5 82/5c 5b 2f 6c 5d/g"\
-e "s/c3 98/5c 5b 2f 4f 5d/g"\
-e "s/c3 b8/5c 5b 2f 6f 5d/g"\
-e "s/c3 86/5c 5b 41 45 5d/g"\
-e "s/c3 a6/5c 5b 61 65 5d/g"\
-e "s/c5 92/5c 5b 4f 45 5d/g"\
-e "s/c5 93/5c 5b 6f 65 5d/g"\
-e "s/c4 b2/5c 5b 49 4a 5d/g"\
-e "s/c4 b3/5c 5b 69 6a 5d/g"\
-e "s/c4 b1/5c 5b 2e 69 5d/g"\
-e "s/c8 b7/5c 5b 2e 6a 5d/g"
# Text markers.
text_markers() sed \
-e "s/e2 97 8b/5c 5b 63 69 5d/g"\
-e "s/e2 80 a2/5c 5b 62 75 5d/g"\
-e "s/e2 80 a1/5c 5b 64 64 5d/g"\
-e "s/e2 80 a0/5c 5b 64 67 5d/g"\
-e "s/e2 97 8a/5c 5b 6c 7a 5d/g"\
-e "s/e2 96 a1/5c 5b 73 71 5d/g"\
-e "s/c2 b6/5c 5b 70 73 5d/g"\
-e "s/c2 a7/5c 5b 73 63 5d/g"\
-e "s/e2 98 9c/5c 5b 6c 68 5d/g"\
-e "s/e2 98 9e/5c 5b 72 68 5d/g"\
-e "s/e2 86 b5/5c 5b 43 52 5d/g"\
-e "s/e2 9c 93/5c 5b 4f 4b 5d/g"
# These markers shouldn't be automatically translated in ms macros.
# @ "s/40/5c 5b 61 74 5d/g"
# # "s/23/5c 5b 73 68 5d/g"
# Legal symbols.
legal_symbols() sed \
-e "s/c2 a9/5c 5b 63 6f 5d/g"\
-e "s/c2 ae/5c 5b 72 67 5d/g"\
-e "s/e2 84 a2/5c 5b 74 6d 5d/g"
hexutf8_to_hexms() {
text_markers | accents | ligatures | legal_symbols
}
to_hex_one_column | regroup_lines | hexutf8_to_hexms | from_hex

21
header.ms Normal file
View File

@ -0,0 +1,21 @@
.TL
Troff template (batteries included)
.AU
Philippe Pittoli
. \" In case you don't want an abstract:
. \" .AB no
.AB
This document provides a few hints on how to start writing documentation with
.B troff .
It represents your first steps with the tool, and the simplest commands are presented along with some personal macros to help you getting started.
.SHINE "Take what you need from this document."
The source code of this document contains many useful comments.
.br
Also, it is customary in old tools such as troff to read the source code and hack your way.
Once you're familiar with the basics, if you need something that isn't in the official troff documentation, don't hesitate to read provided macros (mines, but also ms macros as well, for instance).
You'll quickly learn a lot.
.LP
Lastly compiled the
.SHINE \n(dy/\n(mo/2021 \" is \n(yr broken?
.AE

186
macros.ms Normal file
View File

@ -0,0 +1,186 @@
.\" .RP = report document
.nr PO 0.5i \" page offset default 1i
.nr LL 7.5i \" line length default 6i
.nr FM 0.5i \" page foot margin default 1i
.R1
no-label-in-reference
accumulate
.R2
.nr DI 0
.nr FF 3 \" footnotes' type: numbered, with point, indented
.de BELLOWEXPLANATION1
.sp 0.5
.ps 7 \" point size (~= font size)
.vs 8p \" vertical spacing between lines
..
.de BELLOWEXPLANATION2
.br
.ps 9
.vs 11p
..
.defcolor darkgreen rgb 0.1 0.5 0.2
.defcolor darkblue rgb 0.3 0.3 0.7
.defcolor darkred rgb 0.7 0.3 0.3
.de CONSTRUCTOR
.gcolor darkred
.ps 8
.ft CW
\\$1
.ft R
.gcolor
.ps
..
.de TYPE
.gcolor darkgreen
.ps 8
.ft CW
\\$1
.ft R
.gcolor
.ps
..
.de MODULE
.gcolor darkblue
.ps 8
.ft CW
\\$1
.ft R
.gcolor
.ps
..
.de SHINE
.gcolor darkblue
.ft B
\\$1
.ft R
.gcolor
..
.de MODULEX
.MODULE "\\$1,"
..
.de TBD
.ft B
To be defined or to finish.
.ft R
..
\# Bullet points
.de BULLET
.IP \(bu 2
..
.de ENDBULLET
.in -2 \" indent
..
.
\# Begin code box
.de b1
.B1
.sp 0.2
.ft CW
..
.
\# End code box
.de b2
.sp 0.5
.B2
.ft
..
.de HORIZONTALLINE
\l'15'
..
.de SMALLFONT
.ps 8
.vs 9p
..
.de NORMALFONT
.vs
.ps
..
.de COMMAND1
.b1
..
.de COMMAND2
.b2
..
.de COMMANDNAME
.I "\\$1"
..
.de FUNCTION
.I "\\$1" "\\$2"
..
.de TYPECLASS
.I "\\$1" "\\$2"
..
.de OPERATOR
.I "\\$1" "\\$2"
..
.de QUESTION
.I "\\$1" "\\$2"
\h'5p'
..
.\" MS Accents
.\".AM
.defcolor citation rgb 0.4 0.4 0.4
.defcolor citationbar rgb 0.3 0.3 0.7
.de CITATION1
.KS \" start a keep
.ft I \" citation in italics
.mk C \" set a marker for line drawing
.in +1 \" indent a bit
.gcolor citation
..
.de CITATION2
.mk D \" set second marker to come back here
.ft \" back to previous font
.in -1 \" remove indent
.gcolor \" remove previous color
.gcolor citationbar
\r\L'|\\nCu' \" draw line (\r moves upward, \L draw the line, ...)
.sp '|\\nDu' \" return to the second marker
.gcolor \" remove previous color
.sp -2 \" get two lines back
.KE \" end of the keep
..
.de NAMECITATION
.ps -2
\(em\h'1'\\$*
.ps
..
.defcolor explanation rgb 0.7 0.4 0.4
.defcolor explanationbar rgb 0.8 0.3 0.3
.de EXPLANATION1
.KS \" start a keep
.ft B \" citation in italics
.mk C \" set a marker for line drawing
.in +1 \" indent a bit
.gcolor explanation
..
.de EXPLANATION2
.ft \" back to previous font
.in -1 \" remove indent
.gcolor \" remove previous color
.gcolor explanationbar
\r\L'|\\nCu' \" draw line (\r moves upward, \L draw the line, ...)
.gcolor \" remove previous color
.sp -1 \" get two lines back
.KE \" end of the keep
..
.de METAINFO1
.ft CW \" constant width font
.ps 8 \" small font
.vs 9p \" smaller vertical spacing between lines
..
.de METAINFO2
.vs \" come back to the previous vertical spacing
.ps \" come back to the previous point size
.ft \" come back to the previous font
.sp -1 \" return one line above
..
.de PRETTY_PERCENTAGE
\v'-.7m\s[\\n(.s*6u/10u]+.7m'\\$1\v'-.7m\s0+.7m'\
\(f/\s[\\n(.s*6u/10u]\\$2\s0
..
.de TWO_COLUMNS
.2C
.nr pg@fn-colw \\n[pg@colw] \" footnotes' column width
..

412
main.ms Normal file
View File

@ -0,0 +1,412 @@
. \" comments start with: \"
. \" lines containing only a point: ignored by troff
. \" empty lines = paragraph separator, produce vertical space
.so macros.ms \" First, let's import some macros.
.so header.ms
.TWO_COLUMNS
.NH \" new section
Sections and paragraphs
.PP \" new paragraph (with indentation on first line)
Some indented paragraph.
As you can see, contrary to the first one you encountered in the previous section.
.NH 2 \" new inner section, goes from 1 to 4
Sub-section
.LP
Some unindented paragraph.
Basics of sections and paragraphs in troff (ms macros):
.METAINFO1
.NH
Section
.PP
Some indented paragraph.
.NH 2
Sub-section
.LP
Some unindented paragraph.
.METAINFO2
.NH
Some highlights: the basics
.LP
.I "Combining" \" italics
.UL "several" \" underlined
.B "ways" \" bold
to
.BX highlight \" box
.ft CW \" changing font: constant width
some text.
.ft \" reverting to previous font
.METAINFO1
.I "Combining" \\" italics
.UL "several" \\" underlined
.B "ways" \\" bold
to
.BX highlight \\" box
.ft CW \\" changing font: constant width
some text.
.ft \\" reverting to previous font
.METAINFO2
Avoiding underlining the
.UL "final point" .
.METAINFO1
.UL "final point" . \\" point is a second parameter
.METAINFO2
.I "Again, in italics but surrounded" ) ( \" order: text-in-italics after before
.METAINFO1
.I "Again, in italics but surrounded" ) (
\\" order: text-in-italics after before
.METAINFO2
.NH
Brief overview of custom macros (in macros.ms)
.LP
The file
.ft CW
macros.ms
.ft
includes many small contributions to easily make nice PDF outputs.
For example, the following code and its result:
.METAINFO1
.EXPLANATION1
Very important sentence.
.EXPLANATION2
.METAINFO2
.EXPLANATION1
Very important sentence.
.EXPLANATION2
.HORIZONTALLINE
There is also an helper to make citations.
.METAINFO1
.CITATION1
Seriously, these macros are awesome guys.
.CITATION2
.NAMECITATION "Albert Einstein"
.METAINFO2
.CITATION1
Seriously, these macros are awesome guys.
.CITATION2
.NAMECITATION "Albert Einstein"
.HORIZONTALLINE
(Temporary name for the following macro)
.ft CW
.PRETTY_PERCENTAGE 5.5 20
.ft
.br
Produces:
.PRETTY_PERCENTAGE 5.5 20
.HORIZONTALLINE
Meta informations are in smaller text size and in constant width, with this code:
.METAINFO1
.METAINFO1
Some text.
.METAINFO2
.METAINFO2
Example:
.br
.METAINFO1
This is how I put meta informations in my documents: the text is smaller and in constant width.
.METAINFO2
.HORIZONTALLINE
These horizontal lines are produced by
.METAINFO1
.HORIZONTALLINE
.METAINFO2
.HORIZONTALLINE
Listing stuff
.BULLET
with
.BULLET
bullet
.BULLET
points
.ENDBULLET
.METAINFO1
.BULLET
with
.BULLET
bullet
.BULLET
points
.ENDBULLET
.METAINFO2
.NH
Source code syntax highlighting
.PP
Source code for a number of languages can be colored with the following code\*[*]:
.FS \" footnote starts (\*[*] is its reference)
Under the hood, this involves the
.ft CW
source-highlight
.ft
software and the script
.ft CW
ghighlight
.ft
in the \f(CW./bin/\f[] directory (see the Makefile for more information).
.FE \" footnote ends
.METAINFO1
.SOURCE C
int main(int argc, char **argv) {
return 0;
}
.SOURCE
.METAINFO2
.SOURCE C
int main(int argc, char **argv) {
return 0;
}
.SOURCE
.NH \" new section
Some figures with pic.
.LP \" new paragraph (without indentation on first line)
This is a paragraph before the picture.
.PS \" this starts a 'pic' section, to draw figures
.defcolor lightgreen rgb 0.9 1.0 0.9
box "A box." shaded "lightgreen"
line
circle "A circle." rad 0.4
.PE \" this ends the 'pic' section
This is written in the code this way:
.METAINFO1
.PS
.defcolor lightgreen rgb 0.9 1.0 0.9
box "A box." shaded "lightgreen"
line
circle "A circle." rad 0.4
.PE
.METAINFO2
.NH
Some graphs with grap.
.LP
.G1
GROWTHFACTOR=0.07
grid bot dotted from 0 to 100 by 10
grid left dotted from 0 to 800 by 50
frame ht 2.5 wid 2.8
define expo { $1+$1*GROWTHFACTOR }
value = 1
draw LINEAR solid
for i from 1 to 100 by 1 do {
next LINEAR at i, i
times at i, value
value = expo(value)
}
line from 0,650 to 3,650
" linear curve" ljust at 1,650
" exponential curve" ljust at 1,600
times at 1,600
label top "Exponential curves: growth over time (7%)" up -.2
.G2
.BELLOWEXPLANATION1
Exponentials: always fun and games when talking about economy.
A complete nighmare when talking about mineral extraction costs.
.BELLOWEXPLANATION2
.METAINFO1
.G1
GROWTHFACTOR=0.07
grid bot dotted from 0 to 100 by 10
grid left dotted from 0 to 800 by 50
frame ht 2.5 wid 2.8
define expo { $1+$1*GROWTHFACTOR }
value = 1
draw LINEAR solid
for i from 1 to 100 by 1 do {
next LINEAR at i, i
times at i, value
value = expo(value)
}
line from 0,650 to 3,650
" linear curve" ljust at 1,650
" exponential curve" ljust at 1,600
times at 1,600
label top "Exponential curves: growth over time (7%)" up -.2
.G2
.METAINFO2
.\" Neighbor Discovery, RS... IPv6 stuff
.\" .PS
.\" reset
.\" space_between_machines = 2.0
.\" space_lines = 0.1
.\" space_hdr = 0.8
.\" space_step = 0.3
.\" space_step_small = 0.2
.\"
.\" .ps 16
.\" A: "A" ; move space_between_machines
.\" R: "R" ; move space_between_machines
.\" B: "B"
.\"
.\" .ps 12
.\" move to A + (0, -space_hdr)
.\" "start" rjust; move down space_lines
.\" START: line left ; move right; move right space_between_machines; move down space_step
.\" DAD_SOL: line right ; move to START + (0, -space_step)
.\" RS_A: line left ; move right; move right space_between_machines; move down space_step
.\" RS_B: line right ; move left ; move down space_step_small
.\" RS_C: line right ; move left ; move left space_between_machines; move down space_step
.\" RS_D: line left "New IP @" "" ; move right
.\" move down space_step_small
.\" DAD_SEC_A: line left ; move right; move right space_between_machines; move down space_step
.\" DAD_SEC_B: line right ; move to DAD_SEC_A + (0, -space_step)
.\"
.\"
.\" .ps 8
.\" line -> from START to DAD_SOL "DAD: Neighbor Sollicitation" "" ""
.\" line -> from RS_A to RS_B "Router Sollicitation" "" ""
.\" line -> from RS_C to RS_D "Router Advertisment" "" ""
.\" line -> from DAD_SEC_A to DAD_SEC_B "(second) DAD: Neighbor Sollicitation" "" ""
.\" .PE
.NH
Some equations with eqn
.LP
Let's see a few equations.
.EQ
E = mc sup 2
.EN
.METAINFO1
.EQ
E = mc sup 2
.EN
.METAINFO2
Inline equations, via the "\[Do]" sign:
.METAINFO1
.EQ
delim \[Do]\[Do]
.EN
Inlining equations also is possible: \[Do]a sup b = c\[Do]
.METAINFO2
.EQ
delim $$
.EN
.\" \h'5p' => horizontal space
Inlining equations also is possible:\h'5p' $a sup b = c$
.EQ
delim off
.EN
And this can be set off, with "delim off".
.NH
UTF-8
.PP
UTF-8 is wonderful.
Unfortunately, this wasn't implemented in troff, since it comes from 1972, and neither in the later implementation
.B groff .
So, I wrote the \f[CW]./bin/utf8-to-ms.sh\f[] filter to automatically convert an extensive list of accents, ligatures, and text markers in their equivalent ms macros.
Therefore, one can write in UTF-8 (or at least a good chunk of it) in the input file\*[*].
.FS
All characters cannot be converted so easily.
Some of them are used in troff, such as the arobase, the backslash, etc.
However, my script is a good enough solution for me to write in my mother tongue without any problem.
.FE
Examples (all written in UTF-8 in the troff file):
.br
©®àÀÇçéÉÙÛâÂÔ¡¿œŒæÆ
.NH
Tables with tbl
.PP
.TS
allbox tab(:);
c | c
c | lew(2.5i).
Column1 : Column2
cell : cell content
cell :T{
Hello this is a way longer content, way more than what the cell can hold in a single line.
T}
.TE
.METAINFO1
.TS
allbox tab(:);
c | c
c | lew(2.5i).
Column1 : Column2
cell : cell content
cell :T{
Hello this is a way longer content, way more than what the cell can hold in a single line.
T}
.TE
.METAINFO2
.NH
Some references
.PP
Let's reference a few documents, such as A Universe from Nothing
.[
universe
.]
and a book about the excellent Haskell language.
.[
haskell
.]
.METAINFO1
Let's reference a few documents, such as A Universe from Nothing
.[
universe
.]
and a book about the excellent Haskell language.
.[
haskell
.]
.METAINFO2
.NH
Images
.PP
Only PDF can be included, so images need to be converted beforehand.
.METAINFO1
.PDFPIC -R "./are-you.pdf" 3.5
.METAINFO2
.
.nr figurespace 17
.sp \n[figurespace]
.PDFPIC -R "./are-you.pdf" 3.5
.sp \n[figurespace]
.METAINFO1
Note: for now, on my system, I need a hack.
The included PDF has no length, despite having installed the poppler-utils package.
So, I added spaces by hand.
I'll try to search for a better way, someday.
.METAINFO2
.METAINFO1
.nr figurespace 17
.sp \\n[figurespace]
.PDFPIC -R "./are-you.pdf" 3.5
.sp \\n[figurespace]
.METAINFO2