Change default font

Hash: SHA512

The default font is "Roman". I want to change that to something else
like "Linux Libertine".

Before investing major time in figuring out how to do this I want to
know if there is a simple way to do this without diving into learning
[how to edit style
files]( I
understand that once I learn how to edit style files I will be able to
do many more things in TeXmacs, but honestly, I just want to save
repetitive clicking each time I create a new document to set the font
to one I prefer.

TeXmacs 1.99.14.


I imagine that this is hardcoded in some of the standard style files. So just find it, redefine that style file and put your copy in .TeXmacs/styles (or something like this, see the docs).

I investigated a bit. Using grep you can find all the occurrences of the string ‘roman’ in the source code, e.g.

mgubi@Ulrike svn-src % grep -r "\"roman\"" src                
src/Style/Evaluate/evaluate_textual.cpp:  if (s2 == "roman")  return roman_nr  (nr);
src/Texmacs/Window/tm_button.cpp:  string family  = "roman";
src/Typeset/Env/env_exec.cpp:  if (s2 == "roman") return roman_nr (nr);
src/Typeset/Env/env_default.cpp:  env (FONT)             = "roman";     // the font name in text mode
src/Typeset/Env/env_default.cpp:  env (MATH_FONT)        = "roman";     // the font name in math mode
src/Typeset/Env/env_default.cpp:  env (PROG_FONT)        = "roman";     // the font name in prog mode
src/Graphics/Fonts/font.cpp:  return "roman";
src/Graphics/Fonts/font.cpp:  return "roman";  
src/Graphics/Fonts/font.cpp:  return "roman";
src/Graphics/Fonts/smart_font.cpp:    f == "roman" ||
src/Graphics/Fonts/smart_font.cpp:    if (fam == "roman" && get_unicode_range (c) == "greek") {
src/Graphics/Fonts/smart_font.cpp:    if (fam == "roman" && N(c) > 1) {
src/Graphics/Fonts/smart_font.cpp:  if (mfam == "roman" && shape == "mathupright" && variant == "rm" &&
src/Graphics/Fonts/smart_font.cpp:    int nvdpi= adjusted_dpi ("roman", variant, series, "mathitalic", 1);
src/Graphics/Fonts/smart_font.cpp:    fn[nr]= smart_font_bis ("roman", variant, series, "mathitalic", sz,
src/Graphics/Fonts/smart_font.cpp:  font sec_fn= closest_font ("roman", "ss", "medium", "right", sz, vdpi);
src/Graphics/Fonts/smart_font.cpp:  if (tfam == "roman") tfam= family;
src/Graphics/Fonts/font_translate.cpp:  if (N(v) == 0) return "roman";
src/Graphics/Fonts/font_translate.cpp:    t ("modern")= "roman";
src/Graphics/Fonts/font_translate.cpp:    t ("cyrillic")= "roman";
src/Graphics/Fonts/font_translate.cpp:    t ("sys-chinese")= "roman";
src/Graphics/Fonts/font_translate.cpp:    t ("sys-japanese")= "roman";
src/Graphics/Fonts/font_translate.cpp:    t ("sys-korean")= "roman";
src/Data/Convert/Tex/fromtex.cpp:  if (!is_atomic (t)) return "roman";
src/Data/Convert/Tex/fromtex.cpp:  return "roman";
src/Data/Convert/Tex/fromtex.cpp:    return tree (NUMBER, tree(APPLY, u->label*"-nr"), "roman");

here you see that the relevant entry could be that in env_default.cpp which sets the default typesetting environment. One possibility is to change it in scheme every time the buffer is opened, see the Help->Manual->Customizing TeXmacs and in particular the section ‘Writing your own initialization files’. For example you can create a style file with your own customizations and then add the following code in $TEXMACS_HOME_PATH/progs/my-init-buffer.scm:

(when (buffer-newly-created? (current-buffer))
  (set-style-list (append (get-style-list) '("CustomStyle")))
  (buffer-pretend-saved (current-buffer)))


1 Like

Default font is a big topic:

  • default font for text
  • default font for a specific language
  • default prog mode font
  • default math mode font
  • default font substitution for sansserif

In TeXmacs, most of them are hard coded and scattered in styles/C++/Scheme. It is a bit complicated. Here is how I trying to provide a better built-in deafault Chinese font for macOS.

For CJK, default font is hard coded in TeXmacs.

Recently, I am trying to hard code a better default font for Chinese users on macOS:


With these 4 commits, I tried to set Songti as the default Chinese font for macOS. Songti is not sansserif, as a result, I need to set PingFang as the substitution font for Songti.

The first one is committed in a hurry, Because I wanted to make it available in TeXmacs v1.99.18. I made a mistake. The first one does not work as expected. The second one fixes the first one. And the third one added the missing unit test for the changes.