groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: adjusting font picks for code snippets and math


From: Thomas DUPOND
Subject: Re: adjusting font picks for code snippets and math
Date: Mon, 9 Sep 2024 09:10:02 +0200
User-agent: Mozilla Thunderbird

Le 2024-09-06 à 11:38, Norwid Behrnd a écrit :
Hello,

Hello Norwid,

I would like a different font for the display of snippets of source code in pdf
the default installation of groff in Linux Debian (version 1.23.0) renders with
Courier, and improve the one of mathematics.  Unsure if this a question of
proper font installation, or perhaps using groff in general, I want to address
the question here.

part 1) The conversion of a markdown file into .ms with Pandoc writes a
preamble including the two lines

```
.\" font family: A, BM, H, HN, N, P, T, ZCM
.fam P
```

Following the demonstration of Gavin Freeborn,[1] I fetched font files about
Libertine from CTAN,[2] and successfully installed the data for regular,
italic, and bold characters with Peter Schaffter's script[3] by

```
$ sudo ./install-font.sh -s -d -F Libertine -f +R LinLibertineO.pfb
$ sudo ./install-font.sh -s -d -F Libertine -f +I LinLibertineOI.pfb
$ sudo ./install-font.sh -s -d -F Libertine -f +B LinLibertineOB.pfb
```

This now allows me to use

```
.fam Libertine
```

for the running text. While the documentation[4] states groff's set of R, I,
B, BI fonts can be extended, the large table does not explicitly hint how one
can add a non-proportional font (e.g., Bera Mono[5]) to the effect this one to
be used only for snippets of code.

You can switch to any installed font you want for your snippets of code. It looks like you use this kind of command:

> Code snippet: \f[CR]write(fileunit,"(I3,1x,F5.2)") counter, area\f[R].

Here you switch to Courier (C) Roman (R) font with \f[CR]. You could use anything else like \f[HR] to have your snippet in Helvetica.

If you absolutely want to keep using \f[CR] for your code, you can do this and you would have your snippet in Helvetica:

.fp 5 CR HR
Code snippet: \f[CR]write(fileunit,"(I3,1x,F5.2)") counter, area\f[R].

I mounted the font here at position 5 since the first 4 font positions are usually taken by the Roman (1), Italic (2), Bold (3) and Special (4) font.

Also, I think at the end of your snippet \fP is better suited than \f[R] since \fP make groff switch back to the previous (P) font.

Is there a particular "key" -- like `R`
for regular/Roman -- to restrain the eventual use of this font one can provide
during the installation?

1b) Presuming there were two non-proportional fonts at disposition, what can I
add to the document's preamble to let groff know to then use Bera Mono instead
of Courier for snippets of code?

1c) (pdf)LateX allows to activate fonts with an optional scaling of their
glyphs' height, e.g. `\usepackage[scaled]{beramono}`[6].  Does groff provide a
similar functionality?

---

part 2) Compiling the snippet shared below with

```
$ groff -e -ms -Tpdf 2test.ms > 2test.pdf
```

the variation of the font family from the default set of A, BM, H, HN, N, or P,
does not affect the glyph about rho during var.  Using for instance font family
BM depicts the plus signs differently in text and math mode.  With the amended
Libertine font, a

```
.fam Libertine
```

in the document's preamble now picks a different glyph about rho however
breaks the square root into pieces.

Based on these observations, what could be the/a recommended "groff key" during
the installation (as in 1a) and subsequent use (as in 1b) to substitute this
default font?  In the present context, `LibertinusT1Math.pfb` of
LibertinusT1Math[7] appears as suitable pick for that its glyphs are closely
related to the ones of Libertine.  On the other hand, this set simultaneously
contains glyphs which are regular [Roman, Greek, Cyrillic], italic, bold, math
doublestroke -- a blend beyond the scope of Peter Schaffter's present guide.

In EQN you can use gfont, grfont and gbfont to set the fonts you want. (See the man page eqn(1)).

For all your font related questions, some answers can be found in the man pages groff_font(5) and groff(7).

Also it looks like your are using ms so groff_ms(7) is helpful.

For examples you could look at the Unix Text Processing book[1], chapter 4, section Changing Fonts (page 86/527).

Regards,

Norwid


```
.\" name: 2test.ms
.\" compilation: groff -e -ms -Tpdf 2test.ms > 2test.pdf
.\" font family: A, BM, H, HN, N, P, T, ZCM
.fam BM
.EQ
delim @@
.EN
.LP
This is normal text, \f[I]italic\f[R], and \f[B]bold\f[R].
An in\-line equation @E = m c sup 2@ followed by one in display-style
.EQ
x sub {1 , 2} = p over 2 +- sqrt {{p sup 2} over 4 - q}
.EN
.LP
Code snippet: \f[CR]write(fileunit,"(I3,1x,F5.2)") counter, area\f[R].
.PP
.EQ
rho = m over V
.EN
Glyphs about the plus sign appear of different origin, see + vs @+@.
```

[1] https://www.youtube.com/watch?v=CzUHjtGBdZs
[2] https://ctan.org/pkg/libertine
[3] https://www.schaffter.ca/mom/bin/install-font.sh
[4] https://www.schaffter.ca/mom/momdoc/appendices.html#fonts
[5] https://www.ctan.org/pkg/bera
[6] https://tug.org/FontCatalogue/beramono/
[7] https://ctan.org/pkg/libertinust1math

Best regards,
Thomas

[1]: http://chuzzlewit.co.uk/utp_book-1.1.pdf





reply via email to

[Prev in Thread] Current Thread [Next in Thread]