Change default font

-----BEGIN PGP SIGNED MESSAGE-----
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](http://www.texmacs.org/tmweb/manual/webman-style.en.html). 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.

baltakatei.com
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEOPlkN8g6yI4ot6lSV9pX2VF+b4YFAl+5fZgACgkQV9pX2VF+
b4YFIg//YrqbA7K6K+8rt0epocsWJbgviB0al4D2rfe+COPS2DD7IARY95zzseet
4bs49J4O6e9qtbT5xJApDlLOwLjO1+UK4sDlNnJGuxTmTUGxWZCRu0FoLWkVX/Wk
9Dw1pgMpbmheHrFZBVcvPVBrOdEcznZRI/zOIRXXMgFJfaBIMsuTja1TqpDeW9Uo
H0WUPs7EQuQxN1mVnLRtGN/TsJKk8ooV9ZVYe4x0ESzlSFD7od2nm5z8ZdF33ezn
O3aHZjDQ1wHP8C+S9r3FvmXSZ2K2kwBIsX4+tYT5bLiAuCUJYCEozWeHngTue7qh
m/jzLHHneQT+UOZvvw199MWEe7vx0YG69lsUO0L/FMSRT3VgD5JRpGhhYjFxSp/b
En3Wr28+ms7wCwPrXbYr1TQ18XwVT9UwTfh1hRkFAq0BMmSltTDVx75FV+iDvPC4
dRM7MsT51/IRA0TrSQZRJO5IEqVorU+9AgCA2YhXK64Mg8J+pn3YWMBIrauYaokA
qhed1IgBcyQbBhz39teh2BijZZHfmB9sUkLVwdmqFIRVQg+es12E4+zEOFatJFrt
uYqhayGY8OiyZ+76jxZF6zQTfJqS7a5+55A/eiag7Bhc0uPf3Vi43ZJHjhsTQG1T
6kW/FPYp/7KOf0rm/ZPxMxMfLo7gh91Wtdm6yC0gQhyKuNnaTCI=
=/ebP
-----END PGP SIGNATURE-----

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)))

HTH.

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:

  1. https://github.com/texmacs/texmacs/commit/788afe2ba2fccea490e21f5e2cf8dbe6c64fb563
  2. https://github.com/texmacs/texmacs/commit/82492080f9e29887bb5b31d02024ddfcdc681d14
  3. https://github.com/texmacs/texmacs/commit/c046e8e4fac4743b0fe9a1ff741ecce9c1d270ea
  4. https://github.com/texmacs/texmacs/commit/0a02093395be7499097e19f70320b9db35c4c139

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.