Sunday, August 31, 2025

Tiny/Large Text in Your Xterm: Customizing Font name and size in XTerm

 Tiny/Large Text in Your Xterm: Customizing Fonts in XTerm

If you're a longtime user of terminal emulators, you might have found yourself wanting a smaller font in your xterm. The default font size can feel overwhelming, especially on smaller screens or when you're working with lots of text. While some terminal emulators offer straightforward font size adjustments, xterm can be a bit more... particular.


This post will guide you through the process of customizing your xterm font size using the xfontsel tool.

Why Smaller Fonts in xterm?

More Information on Screen: Smaller fonts allow you to display more lines of text or more columns without scrolling.

Improved Readability (for some): Depending on your eyesight and screen resolution, a smaller, carefully chosen font can actually improve readability.

Aesthetic Preference: Some people just prefer the look of a smaller font.

The Challenge with xterm

xterm's font configuration isn't as user-friendly as some modern terminal emulators. It uses a specific font description string that can seem cryptic. Luckily, xfontsel can help!

Step 1: Finding a Suitable Font with xfontsel

xfontsel is a tool that lets you browse and select X fonts. If you don’t have it, install it:

Debian/Ubuntu: sudo apt-get install xfontsel

Fedora/CentOS/RHEL: sudo dnf install xfontsel

Arch Linux: sudo pacman -S xfontsel

Run xfontsel from your terminal. A window will appear displaying a vast collection of fonts. The key is to find a fixed-width (also called monospaced) font. These are crucial because they ensure all characters take up the same horizontal space, which is essential for terminal output to align correctly.

Experiment! Find a font you like the style of. Note the font's full name. For example, you might settle on something like "Fixed".

Step 2: Constructing the Font Description String

xterm uses a font description string in a specific format. Here's the breakdown:

-fn "-*-fontname-*-*-*-*-pixelsize-*-*-*-*-*-*"

-fn: This is the xterm option that specifies the font name.

-*: This is a wildcard for the face. You can usually leave it as is.

fontname: This is the exact name of the font you selected in xfontsel. This is where the part you wrote down earlier goes.

pixelsize: This is the font size you want. Smaller numbers result in smaller fonts. 18 is used in the example provided.

So, if you found a font named "Fixed" in xfontsel and want a font size of 18, your command would be:

xterm -fn "-*-Fixed-*-*-*-*-18-*-*-*-*-*-*-*" &

Important: Replace "Fixed" with the actual font name you found using xfontsel.

Step 2.5 (Important - Finding the exact font name)


Sometimes the font name shown by xfontsel is not the one that xterm can use. Try running the font description string fc-match -f "-*-Fixed-*-*-*-*-18-*-*-*-*-*-*-*", and replacing Fixed and 18 with your font's name and size to get the font name that xterm can accept.


Step 3: Running xterm with the Font Option

Simply run the command from Step 3 in your terminal. The & at the end runs xterm in the background so you can continue using your terminal.

Making the Change Permanent (Optional)

To have this font setting applied every time you launch xterm, you have a couple of options:

.Xresources File: Create or edit the ~/.Xresources file and add the following line:

XTerm*faceName: "-*-Fixed-*-*-*-*-18-*-*-*-*-*-*-*" (Replace Fixed and 18 with your specific font and size)

Then, run xrdb ~/.Xresources to apply the changes.

Desktop Environment Settings: Some desktop environments (like GNOME, KDE, Xfce) allow you to customize default application settings. Check your desktop environment's settings to see if you can specify a default font for xterm. This is often the most user-friendly approach.

Alias in .bashrc or .zshrc: Add an alias in your shell's configuration file (e.g., ~/.bashrc, ~/.zshrc) to always launch xterm with the font option. For example: alias xterm='xterm -fn "-*-Fixed-*-*-*-*-18-*-*-*-*-*-*-*" &'

Troubleshooting

Font Not Found: Double-check that the font name in the -fn string is exactly what xfontsel shows.

Incorrect Alignment: If the text isn't aligned correctly, you are almost certainly not using a fixed-width font. Go back to xfontsel and make sure you’re selecting a monospaced font.

No Effect: If the font doesn’t change, make sure you've applied any changes made to .Xresources (using xrdb). Also, check your desktop environment's settings.


No comments: