Using system fonts

I don’t know if this is default behaviour, but most of my system fonts are unavailable/invisible inside Texmacs. I searched through this forum for a way to add fonts and found something that I tried but didn’t work. I am trying to use a different font for the code environment. How can I do that ?

I did “Tools->Font->Look for more fonts” in my Windows installation (I think this is the way to find all of the fonts) but after completing the search for more fonts TeXmacs showed an empty error message, then crashed (and the list of fonts remained the same after restart).

I think that you can find the list of directories TeXmacs searches for files in the C++ source file Plugins/Freetype/tt_file.cpp, function tt_font_path.
On which OS are you? Can you link the post you are referring to? Perhaps someone else will be able to help.

Perhaps someone else will be able to help.

I tried what Tools->Font->Look for more fonts. It didn’t crash on my machine (arch linux), but nothing happened.

This is the code snippet I am currently using to add/enable extra fonts. I got it from here.

(delayed (lazy-initialize-force) (menu-bind document-short-font-menu
("Cantarell" (init-font "Cantarell"))
("Kepler" (init-font "Kepler"))
("Garamond" (init-font "Garamond Libre"))
("Montserrat" (init-font "Montserrat"))))

That snippet works for me, if I use a font that exists in my system.
The font shows up in the context menu (right click when in document).

(edit: also in the ribbon font menu)

the Scheme name for the font submenu under “Document” isdocument-font-menu—different from the document-short-font-menu, the one modified in the snippet (I picked it up from the source code, look inside /progs/generic/document-menu.scm); I did not figure out where is the fonts menu under “Format”, perhaps because it is involved (maybe it is not default, but one gets it after setting in the preferences “Complex actions” to “Through the menus”)

Perhaps I have an idea of why it crashed (only perhaps).
TeXmacs, via MikTeX, installed the LaTeX package niceframe instead of bbding because it found in niceframe the font file it looked for (which is also contained in bbding), but what it installed was not what it needed. I installed bbding from the MikTeX console and did again Tools->Font->Look for more fonts; TeXmacs, after installing a few more packages it did not look for in the previous attempts, displayed the following errors:

but it did not crash :slight_smile:

The font menus again did not change. In my case so far in order to add fonts to the menu I have to use the snippet posted above.

For me the font name appears in the context menu, but selecting it doesn’t change anything.

I just realized that in my case selecting the font I installed in Windows and then in TeXmacs causes a substitution font to be used by TeXmacs—I asked TeXmacs to insert in the menu a non-existent font, with

(delayed (lazy-initialize-force) (menu-bind document-short-font-menu
("NewYork" (init-font "NewYork Standard"))
("TestFont" (init-font "Nonexistent font"))))

and I got in the menu the “TestFont”, that when selected turns the whole document in a font which I cannot identify and is as well the same as the one that I get when selecting “NewYork”—which I had not realized it is not the NewYork font when I had written the messages above. I assume it is a substitution font (I was expecting that TeXmacs would issue a warning when substituting fonts).
I will test a bit more but it is possible that I will not be able to help. Perhaps some other forum member will.

@hamorabi Is the font you want to use available via the “Document -> Font” dialog?

No. It is not. I cannot see most or any of my system fonts (such as Hack, Iosevka, etc) using the dialog.

It is likely that your system installs fonts in a place where TeXmacs isn’t looking. Maybe this post can help:

In my attempts (Windows), fonts in $windir/Fonts did not get detected by “Tools->Font->Look for more fonts”; neither new fonts installed in $TEXMACS_PATH/fonts/truetype

I’m on Linux. So system fonts are installed in /usr/share/fonts/ and user fonts are installed in /home/username/.fonts/.

That’s where they are for me as well. TeXmacs doesn’t look in that location, though. A quick fix is to create a symlink to /use/share/fonts under ~/.fonts

Just to be clear that I am doing things right, here’s a recording of what I’m doing.

That looks okay at first glance. Now you probably need to do the “Look for more fonts” again.

While I didn’t do it in the video, I have tried this step previously and it didn’t seem to do anything.

Not sure what’s happening. I see you also have other fonts in ~/.fonts that aren’t being picked up. Perhaps you can clear the font cache (Tools->Fonts->Clear font cache) first and then look for fonts again.

It could be useful to start TeXmacs from the terminal to do this, it may throw some error messages there.

That seems to work! Thanks. Just one more question. When I close and reopen texmacs, the fonts that were loaded before I closed it are not listed under Document->Font. I have to go to Tools->Look up more fonts. Why do I have to do it every time?

That doesn’t seem right. The font cache should be persistent. Perhaps starting from the terminal can give a clue.