Compare commits

...

10 commits

4 changed files with 255 additions and 55 deletions

View file

@ -8,8 +8,6 @@ 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)
@ -64,9 +62,7 @@ GROFF_OPTS ?= -ms -t -Tpdf -U -mspdf -mpdfmark -M ./bin -P -e
GROFF = groff $(GROFF_OPTS)
$(SRC).pdf:
cat $(SRC).ms |\
$(SOELIM) |\
$(SPECHAR) |\
$(SOELIM) < $(SRC).ms |\
$(PRECONV) |\
$(EQN) |\
$(GHIGHLIGHT) |\

View file

@ -47,3 +47,13 @@ Some macros exist to do it properly, but it still is to include in custom macros
Browser preview is ugly as fuck.
It may have something to do with font embedding, I have to investigate, but right now you just can't have a nice preview on a browser.
# TODO
Besides fixing minor problems (image inclusion, browser view), other tools should be tested:
- [neatroff][neatroff]: roff but with a modern implementation
- [SILE][SILE]: not roff, but allows way more complex layouts while still remaining simple
[neatroff]: https://github.com/aligrudi/neatroff
[SILE]: https://sile-typesetter.org/

View file

@ -4,7 +4,7 @@
.so macros.ms \" First, let's import some macros.
.so header.ms
.TWO_COLUMNS
.NH \" new section
.SH \" new section, without number
Before we start
.PP
.QUESTION "Why a PDF instead of a website?"
@ -55,7 +55,7 @@ T}
Books can be written using a lot of different tools, including \fILaTeX\f[] or WYSIWYG editors such as \fILibreoffice\f[].
None are simpler or withstood the test of time better than troff.
Troff still works almost as its debuts in 1972, and as of today, it produces high quality documents with little effort or complexity.
Troff still works almost as its debuts in 1970, and as of today, it produces high quality documents with little effort or complexity.
.NH \" new section
Sections and paragraphs
@ -152,11 +152,10 @@ Seriously, these macros are awesome guys.
.HORIZONTALLINE
(Temporary name for the following macro)
.ft CW
.FRAC 5.5 20
.ft
.br
Produces:
.FRAC 5.5 20
@ -263,9 +262,144 @@ This is written in the code this way:
.PE
.METAINFO2
.SECTION_NO_NUMBER Read the source code for the next figures.
Both figures have very few lines of code.
The source code can be read without prior knowledge of
.B pic ,
it's almost plain English!
.PS
reset
.\" Radius for different circles.
rad_large_circle = 0.6
rad_empty_space = 0.5
rad_light_source = 0.3
rad_aperture = 0.1
.\" Light intensity.
fill_large_circle = 0.1 # Very bright.
fill_empty_space = 0.6 # Little bright.
fill_light_source = 0 # Completely bright.
arrow_x_shift = 0.05
txt_y_shift = 0.25 # Allow space for text.
.\" Circles.
HALO: circle rad rad_large_circle fill fill_large_circle
EMPTY: circle with .c at HALO.c rad rad_empty_space fill fill_empty_space
SOURCE: circle with .c at HALO.c rad rad_light_source fill fill_light_source
APERTURE: circle with .c at HALO.c rad rad_aperture fill fill_light_source dashed
.\" Legend.
TAPERTURE: "Aperture, where light can pass through" ljust at HALO.e + (0.3, 0)
TSOURCE: "Main visible light source, very bright" ljust at Here + (0, -txt_y_shift)
TEMPTY: "Empty space, very little light" ljust at Here + (0, -txt_y_shift)
THALO: "Halo, thin light" ljust at Here + (0, -txt_y_shift)
.\" Arrows.
arrow from TAPERTURE + (-arrow_x_shift,0) to APERTURE chop 0 chop rad_aperture
arrow from TSOURCE + (-arrow_x_shift,0) to SOURCE chop 0 chop rad_light_source
arrow from TEMPTY + (-arrow_x_shift,0) to EMPTY chop 0 chop rad_empty_space
arrow from THALO + (-arrow_x_shift,0) to HALO chop 0 chop rad_large_circle
.\" Let's cheat a little: centering the figure.
false_line_x = 2.7
line from SOURCE + (false_line_x,0) to SOURCE + (false_line_x,0)
.ps 14
"Circular diffraction" at HALO.s + (1, -1)
.PE
Seriously, just check the source code.
It's filled with dead simple lines, such as:
.SOURCE C ps=7 vs=9p
circle rad rad_large_circle fill fill_large_circle
.SOURCE
.gcolor black
.PS
.vs 9p
.ps 7
reset
.\" Drawing direction.
down
scale = 1.4
.\""""""""""""""""""""""""""""""
.\" Variables to ajust elements.
.\" Distances x and y between the massive object and magnified ones.
mag_obj_x = 1.4
mag_obj_y = -1
.\" Radius of the different celestial objects.
rad_obs = 0.3
rad_massive_obj = 0.5
rad_mag = 0.4
rad_dist = 0.27
.\" Distance between the light beam of the distant object
.\" reaching the observer and the massive object's center.
dist_beam_massive_obj = 0.32
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.\" Drawing of the celestial corpses (planets, galaxies, etc.).
.\" Observer, massive object and the distant object.
OBSERVER: circle radius rad_obs "Observer"
move
MASSIVE_OBJ: circle radius rad_massive_obj "Massive" "object"
move
TARGET: circle radius rad_dist "Distant" "object"
.\" "radius" can be abreviated in "rad".
.\" Magnified objects.
MAGNIFIED1: circle rad rad_mag "Magnified" "distant" "object" at MASSIVE_OBJ + ( mag_obj_x, mag_obj_y)
MAGNIFIED2: circle rad rad_mag "Magnified" "distant" "object" at MASSIVE_OBJ + (-mag_obj_x, mag_obj_y)
.\" Lines from the magnified objects to the observer.
.\" chop = do not draw within the circles (a radius is given).
line from MAGNIFIED1 to OBSERVER chop rad_mag chop rad_obs dashed
line from MAGNIFIED2 to OBSERVER chop rad_mag chop rad_obs dashed
.\" Arrows, from distant object to the observer.
spline -> from TARGET to MASSIVE_OBJ.e + (dist_beam_massive_obj,0) to OBSERVER chop rad_dist chop rad_obs
spline -> from TARGET to MASSIVE_OBJ.w + (-dist_beam_massive_obj,0) to OBSERVER chop rad_dist chop rad_obs
.vs
.ps 14
"Gravitational lensing" at TARGET + (0,-0.7)
.PE
Both figures came from my summary of the book
.B "A Universe From Nothing" "\*[*]"
from
.I "Lawrence Krauss" .
.FOOTNOTE1
.\" I've no idea why footnotes line length changed.
.\" This is related to figures, but it needs some investigation.
.ll 7.5i
Available at:
.br
.ps 7.8
.ft CW
\*[WEBSITE]/universe-from-nothing.pdf
.ft
.ps
.FOOTNOTE2
.NH
Some graphs with grap.
.LP
.PS
reset
.PE
.G1
GROWTHFACTOR=0.07
grid bot dotted from 0 to 100 by 10
@ -382,15 +516,10 @@ And this can be set off, with "delim off".
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
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
But, you can write UTF-8 characters anyway, thanks to the troff preprocessor
.B preconv .
Examples (all written in UTF-8 in the troff file):
.br
@ -432,7 +561,7 @@ Tables with hdtbl
.\".nr t*cpd 0.1n \" cell padding
.ds t*bc pink2\" border color
.
.TBL cols=3 width='10% 45%'
.TBL cols=3 width='20% 35%'
. CPTN val=b This is a fine table. This is a fine table. This is a fine table. This is a fine table. This is a fine table. This is a fine table.
. TR
. TD fst=I first cell

139
macros.ms
View file

@ -17,12 +17,37 @@ accumulate
.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
.defcolor black rgb 0 0 0
.
. \" with semantic
.defcolor citation rgb 0.4 0.4 0.4
.defcolor citationbar rgb 0.3 0.3 0.7
.defcolor explanation rgb 0.7 0.4 0.4
.defcolor explanationbar rgb 0.8 0.3 0.3
.
.defcolor specialcolor_type rgb 0.6 0.3 0.5
.defcolor specialcolor_constructor rgb 0.1 0.5 0.2
.defcolor specialcolor_module rgb 0.1 0.5 0.2
.defcolor specialcolor_function rgb 0.4 0.4 0.7
.defcolor specialcolor_question rgb 0.0 0.0 0.7
.defcolor specialcolor_shine rgb 0.3 0.3 0.7
.
. \" SIZES
.nr specialsize_type 8
.nr specialsize_constructor 8
.nr specialsize_module 8
.nr specialsize_function 8
.nr specialsize_question 10 \" Current point size, no change.
.nr specialsize_shine 11
.
. \" FONTS
.ds specialfont_type CW
.ds specialfont_constructor CW
.ds specialfont_module CW
.ds specialfont_function I
.ds specialfont_question I
.ds specialfont_shine B
.
.
.de BELLOWEXPLANATION1
.sp 0.5
@ -76,17 +101,26 @@ accumulate
.in +1 \" indent a bit
.gcolor citation
..
.ig
The CITATION2 macro closes the quote then draws a line
from current line to the start of the quote.
..
.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
.\" r = move upward
.\" Z D t = drawing thickness
.\" L = draw the line
\r\
\Z'\D't 1p''\
\L'|\\nCu' \" draw line
.gcolor black \" remove previous color
.sp -2 \" get two lines back
\Z'\D't 1'' \" get the previous drawing thickness back
.KE \" end of the keep
..
.
.de NAMECITATION
@ -146,6 +180,28 @@ accumulate
\l'15'
.FOOTNOTE_TO_COLUMN_WIDTH
..
.
. \" Fonts and colors.
.
.de SPECIAL_WORDS
.nr current_size \\n[.s] \" Current point size.
.gcolor specialcolor_\\*[semantictoken]
.
.if !((\\n[current_size] == \\n[specialsize_\\*[semantictoken]]) \
.ps \\n[specialsize_\\*[semantictoken]]
.
.ie '\\$2'' \{\
\f[\\*[specialfont_\\*[semantictoken]]]\\$1\f[]
. ps \\n[current_size]
. gcolor black \" FIXME: should be the previous color
\}
.el \{\
\f[\\*[specialfont_\\*[semantictoken]]]\\$1\f[]\c
. ps \\n[current_size]
. gcolor black \" FIXME: should be the previous color
\\$2
\}
..
.de SMALLFONT
.ps 8
.vs 9p
@ -161,57 +217,43 @@ accumulate
.b2
..
.de COMMANDNAME
.I "\\$1"
..
.de FUNCTION
.I "\\$1" "\\$2"
..
.de TYPE
.gcolor darkgreen
.ps 8
.ft CW
\\$1
.ft R
.de FUNCTION
.gcolor color_function
\f[CW]\\$1\f[]\c
.gcolor
.ps
\\$2
..
.de TYPE
.ds semantictoken type
.SPECIAL_WORDS "\\$1" "\\$2"
..
.de TYPECLASS
.I "\\$1" "\\$2"
..
.de OPERATOR
.I "\\$1" "\\$2"
\f[CW]\\$1\f[]\\$2
..
.de QUESTION
.I "\\$1" "\\$2"
.ds semantictoken question
.SPECIAL_WORDS "\\$1" "\\$2"
\h'5p'
..
.de CONSTRUCTOR
.gcolor darkred
.ps 8
.ft CW
\\$1
.ft R
.gcolor
.ps
.ds semantictoken constructor
.SPECIAL_WORDS "\\$1" "\\$2"
..
.de MODULE
.gcolor darkblue
.ps 8
.ft CW
\\$1
.ft R
.gcolor
.ps
.ds semantictoken module
.SPECIAL_WORDS "\\$1" "\\$2"
..
.de SHINE
.gcolor darkblue
.ft B
\\$1
.ft R
.gcolor
.ds semantictoken shine
.SPECIAL_WORDS "\\$1" "\\$2"
..
.de MODULEX
.MODULE "\\$1,"
.MODULE \\$1 ,
..
.de TBD
.ft B
@ -268,27 +310,50 @@ Compilé pour la dernière fois le
.
.de SECTION
.NH
.ps +3
.fam H \" helvetica family
\\$*
.fam \" back to previous font family
.ps
.PARAGRAPH_INDENTED
..
.de SUBSECTION
.NH 2
.ps +1
.fam H \" helvetica family
\\$*
.fam \" back to previous font family
.ps
.PARAGRAPH_INDENTED
..
.de SUBSUBSECTION
.NH 3
.fam H \" helvetica family
\\$*
.fam \" back to previous font family
.ps
.PARAGRAPH_INDENTED
..
.de SUBSUBSUBSECTION
.NH 4
.fam H \" helvetica family
\\$*
.fam \" back to previous font family
.PARAGRAPH_INDENTED
..
.de SECTION_NO_NUMBER
.SH
.fam H \" helvetica family
\\$*
.fam \" back to previous font family
.PARAGRAPH_INDENTED
..
.de SUBSECTION_NO_NUMBER
.SH 2
.fam H \" helvetica family
\\$*
.fam \" back to previous font family
.PARAGRAPH_INDENTED
..
.de PARAGRAPH_INDENTED
.PP