Emacs: customize fonts (generic method and 'fontaine' package)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone my name is pilos also known as prot in this video I want to show you how to set fonts in emx I will use a generic method and then I will also show you how to do basically the same thing with the help of a package this package is called Fontan and is one of my uh many packages let's start with the generic method and uh we will take it from there there is a function called called set face attribute there are functions uh that are in the same family such as set face foreground set face background Etc but set face attribute is the one I normally use is it's the most generic and it just works set face attribute allows us to modify what Emax calls a face faces are constructs of the display engine of emx that not uh cover a set of typographic and color attributes uh meaning that they specify the font family the font height the font weight whether there is a slant or not uh the foreground color the background color and so on there are uh several um attributes that pertain to faces in other words what we see over here this is a face this is another face the mode line here has different faces there are many faces on display over there and basically whenever you see text in emox you can have a face applied there this is the general idea what we want to do now is configure faces that are specific to typography and there are three such faces of course every face can have its own type of graphic settings but you normally wouldn't want every single phase to have them you would probably want to specify only a few of them and then the rest will take it from there we have the default phase and I will explain what each of these uh does what it applies to we have the fixed pitch and the variable pitch just like that fixed pitch means monospaced and variable pitch means uh proportion ately spaced and this two apply only to cases where the font family has to be mono or proportionately spaced the default phase on the other hand is the face that applies by default everywhere and it is the face that not just specifies the font family it also specifies the background and the foreground and basically everything we see in other words every face will fall back to the default faces attributes unless it overrides them uh for example here there is a face that applies to comments it uses the same font family as this pH even though I did not specify a font family for this one meaning that this phase doesn't have its own font family it is unspecified so it falls back to the default and this is the general principle that you need to consider put simply if we modify the font family of the default phas we are most likely changing uh the vast majority of faces in emx the F the font family they are using uh let's see now this in action set face attribute accepts a face argument we can see the lower part of the screen over here there is in the Echo area the set face attribute the function that I am now calling and next to it it has a list of the arguments that it accepts and it highlights the argument that I am right now uh supplying this uh interface is built into emx it is called ldoc mode and I believe it is enabled by default for programming modes H now what I want to do is set the face as a symbol and meaning I want to uh provide a single quote and just like that then it accepts a frame argument for this purpose I will set it to nil there are other uh options of course and you can learn about them by reading the documentation of this function Control HF with the default key bindings or MX describe function and then you select set face attribute if you are over it it defaults to that so so you just type enter and it will tell you uh in a help buffer all about this function it will tell you what frame is what sort of arguments it accepts and what sort of values rather it accepts and that sort of thing further down if we keep searching we will find a list and an explanation of all the face attributes one such attribute is the family another one is the weight another one is the height and there are many others but these are the ones we are interested in right now uh let me then set a nil value for the frame and then provide in the ARs as you can see in the lower part of ldoc it highlights the args meaning a list of arguments rest ARS so any number of arguments here I will uh provide a family and and I will set it to source code Pro which is a different font than the one I am using right now let's uh evaluate I am at the end of the expression and I am typing crl X control e and this has now changed the font family that I am using by default okay again remember that the default takes effect but can be overridden by other faces such as for example my mode line over here you will notice that it is not using source code Pro it is using a different font family which we will get to uh just like that I was able to change my uh font family uh let's say change back to what I was using eosa comfy is the font uh that I am using this is a design that I have made it is um a heavily modified version of the iosevka font uh so here we have it I am back to the default uh let's go and change the height and I will just set it to 200 but uh let me also provide an explanation here that height is equal to the point size that you may be used to from other applications times 10 so if in your you know application web browser or whatever you are setting the font size to 10 in Max you set the height to 100 this is the idea uh let me set the height to 200 like this and just like that I am able to increase it let me set it back to 180 this is fine if you if all you want to do is just change the height you don't need to specify the family so you can remove the family completely and just set this to a number and just like that you have changed the default font family uh but let's keep that for now over there and let's have this again at 180 this is basically it when it comes to setting the attributes you can do the same for the weight and the weight accepts symbols and these symbols must be supported by the given font family for example bold and if I do that it makes everything bold in this case or light and this is the idea uh of course depending on your uh font family you may have other values like semi light or regular there are there are many depending on what you are uh using what font you are using right now I will set it to semi light just like that so here is the idea let's see now what we can do with this because of course we can set the default phas but we can do do more we can set the other faces as well to have a more pleasant reading experience let me switch to my emox uh this is my literate emix configuration I did a video about it recently it's an advanced emix configuration and I explain my reasoning there as well as in the frequently asked questions that I document here not to worry what we are interested in here is to see see that here I have different uh fonts in effect uh this is not a monospaced font maybe we can actually go to a section that has a code as well and since I will be showing you font 10 later let's have it here already you can see here that this is monospaced and this one here is a different font this one is proportionately spaced or because I am using my own font quasi proportionately spaced so it's not entirely proportionately spaced uh but uh let's change the font first and then I will tell you how I am getting this effect uh let's go back to here and do H set pH attribute and let's say the variable pitch we will change it to a family that is um quite different from what I am now using for demo purposes I will do theja Vu uh siif this is the thing Deja Vu serif is probably installed by default in your Linux distribution if not no worries you can easily get it uh crl xrl e and now I see the effect right away in the window below this is a serif font family the deja vu um super family and we can see here that we have uh Deja Vu shif and Below we still have my monospaced font uh and this is the fixed pitch uh so let's also change the fixed pitch fixed pitch and let's use source code Pro over there uh just so that you see the effect just like that and I am able to see the effect live and so I can easily Tinker with this and get the font family and the font configurations that like the most H personally I don't like deja vu shif and source code Pro uh so I will just go back to uh what I was using uh and we will see what I just did we will see it a bit later but let me tell you about this uh configuration over here which combines proportionately spaced fonts with monospaced fonts in any buffer in IMX we can do MX variable. d pitch Das mode to H toggle the display of proportionately spaced fonts in the current buffer this is a built-in feature the variable pitch mode now I have disabled it normally uh I enable it for text mode buffers like org mode markdown Etc but now I have disabled it and we see that everything has changed to complete mono spacing so I will do MX variable pitch mode again and now now I am using proportionately spaced fonts just like that and I think um proportional spacing is better for pros just like that as you can see over here you will notice however that uh not everything in this buffer is proportionately spaced the text is the paragraphs are but the code blocks are not the code blocks are still monospaced uh and this is achieved at the theme level uh which has so this is the modus vendi tinted theme it is part of the modu themes collection uh all my themes have a mixed fonts uh setting uh which I set to true but I will set to nil now and all my themes okay so it's the modu themes one second let's write it here the modus themes the F themes it's F not EF and the standard themes all these have a mixed fonts setting and uh I will set it to nil right now just for you to see the effect and then I will reload the font the theme rather uh for CH for changes to take effect uh so modus vendi tinted is the font I am the the theme rather I am using right now and let's see what happened now we notice that now everything is proportionately spaced and I can do Deja Vu serif to see this you see the paragraphs are proportionately spaced and the uh code blocks are proportionately spaced so everything is using the same font the problem with this H is that if you type something that is um sensitive to spacing for example if we have a table uh let's see it in action over here uh we have um a table like this and it has some values uh test and hello and we see that we get a mess out of this this is uh not useful I wouldn't be using tables if they were being spaced like this the reason the spacing is like this is because the implementation relies on fixed uh uh spacing So Physical spaces uh at the font level have to be of equal length whereas with a proportionately space based fonts uh font uh spaces are not the same the the size of each cell is not the same uh what we then do oops sorry what we then do is that we want to set mixed fonts at the level of the theme and then we will reload the theme for changes to take effect and now we see that uh we get back what we wanted and let's see this so Deja Vu serif is for something that is not spacing sensitive and everything that is spacing sensitive in this mixed fonts configuration will use mono spacing it will use fixed pitch so I will evaluate source code Pro and you see now that this is source code Pro over there this is the idea let's disable this and let me just revert uh to the fonts that I use this is the idea and then once we have set the mixed font we just do MX variable pitch mode uh to apply that personally because I do variable pitch mode all the time for text modes I make it the default so I have something like this in my configuration it's not exactly this but this is the spirit of it variable pitch uh and mode this is the idea and what this means is that when you enter a mode a major mode that is text mode or derived from text mode activate variable pitch mode and this applies to org mode markdown plain text and others like them this is the idea and of course if you don't like it you just disable it with MX variable pitch mode this is all basically it for fonts you can have something like this in your configuration and uh minus the part that is for the themes of course unless you are using one of my themes and uh if you have something like this in your configuration you are good to go the problem with this setup is that it is hard to change the values on the fly to quickly change to something else uh in my case when I am uh writing I write with this let me show you you don't have to see it it will be very small relative to this this is actually the font size that I am using when I am writing this is my default font size but when I do a presentation I cannot possibly use this right for this case I want to switch quickly to presentation mode and this means that I want to use a preset configuration that I have optimized for the purposes of doing presentations such as this one and so the presentation will set quickly basically it will do this under the hood it is a bit more sophisticated but this is fundamentally the idea it sets the sizes and the families to the ones that we specified this ability to quickly change between preset configurations is where my font 10 package comes into play this is you can get this by default but then if you want to quickly switch between them Fontan is the way to go so let's go to my um Pro .org and this is my font 10 and of course as with everything that I do uh the manual is comprehensive you can take a look at it uh here I have just the code parts and we are interested in the Fontan presets user option this user option defines preset uh configurations for fonts and and it does that by setting an A-list it is a list of lists an association list and this a list includes a symbol which is like an arbitrary word which is for us to identify the specific preset and then a list or or rather uh as it follows over here pairs of an a property and a value and uh the T which is the default the fallback preset defines uh the fallback values meaning that if a preset like small does not specify fixed pitch family or whatever then or rather let's say variable pitch family since I have it over here H if it doesn't specify then it uses the one from T like in the case of regular it's just empty so it is using all of the defaults but I do it like this just to illustrate the point these over here you will notice that they are for the faces that I showed earlier we have the default face the fixed pitch face and the variable pitch face there also are the bold face and the italic face and these are very useful if you are using any of my themes because none of my themes hard codes a a bold weight or an italic uh an italic slant so you can change it from here as well and have it take effect everywhere H the thing with font 10 now is that these presets are uh can be specified like this to also inherit from each other let's see this in action I am defining a medium uh preset and this medium preset deviates from the fallback in terms of these three attributes over here these three properties so the weight the default weight the default height and the Bal weight and the Bold weight I want it to be extra bold which is of course supported by my font family and then in the presentation uh preset I am inheriting medium and then what I say is well I like what medium does but I still want to override something and here I want to override the default weight to be even lighter and then I want to change the default height to be uh higher this is the idea uh let's see this in action now I will Define a demo preset uh for now I will uh not inherit from anything I don't need to inherit from something so I will do the default height uh let's set it to 200 and the default weight the default weight uh let's set it to uh regular uh like this this is all I want so I will evaluate this and what I will do now is call my command uh for changing uh presets this is a font 10 command you can see what I typed in uh the mode line on the mod line and you can see Fontan set preset is the name of the command and this produces a list of the preset configurations and then we have demo over there and I switch to the demo and you see just like that I am able to uh switch to it uh let's see now let me switch back to the presentation and let's see now what we can do with this uh here remember that I have the mixed fonts setup so let's uh see it like this here on the upper window I am showing a a paragraph that will will be using variable pitch and on the bottom window where I am moving the cursor right now I will be making the configurations so uh the fixed uh pitch family I want it to be source code Pro and like this and then the variable pitch family the variable pitch family I want it to be Deja Vu uh serif uh please do not take this as a suggestion for a combination of font I think these don't combine at all but I am just doing it for demo purposes uh we will evaluate this but I need to be because I'm not in the code block I need to do that and uh I will now switch to the demo and you will see uh how this uh looks just like that it uses um source code Pro here and it uses uh the uh Deja Vu siif font over there and this is the idea uh let's uh do now the other thing uh fixed pitch weight because this is too heavy for me and I will set it to I don't even remember what s code Pro accepts does it has a light weight I don't even remember uh I don't even know o sorry um let's keep it like that uh let's see let's see does it have uh let's use the demo again yeah it seems to have a lightweight and just like that I am changing to this and now I will change back to my other preset the presentation uh preset that I have over there so this is the idea very quickly you define the preset with uh the parameters that you want over there and you switch between your preset configurations just like this for me this is very useful because I I have a presentation preset and a large prese preset above and depending on what I am doing I switch to those otherwise I use regular or even small if I am on the laptop I always use a small uh on the desktop I normally use regular and the others are special purpose depending on what I am doing but usually it's some presentation and uh I set the font to what it needs to be uh this is the idea folks uh and this is the font 10 package of mine just to find the variable pitch mode so further down in my configuration I also set this up as I told you I am doing it for text mode hook but it is a bit more elaborate I tweak a few more things and then I set it just like that you can find all my configurations uh on my website as well as by checking my DOT files and I will include links to my configuration uh in the description of this video but of course you can always check my website brill.com and you will find everything I do about emac there so my emx configuration and all my emac packages are there this is the idea folks uh configuring fonts in emo I really like this approach it's just working and uh you can easily adapt as you go to evolving circumstances and always have something that looks pretty uh the font that I am using as I said it's iosa comy yfa comfy because I get asked this in practically every video what font are you using this is the my own custom uh build of iosevka and uh it is comprehensive and uh you can check more about it it's I also documented in my emx so you can find it there and you can also find its uh G repository and uh take it from there that's all for now folks thank you very much for your attention take care and goodbye for now
Info
Channel: Protesilaos Stavrou
Views: 3,712
Rating: undefined out of 5
Keywords: gnu, emacs, fonts, faces
Id: qR8JRYr4BKE
Channel Id: undefined
Length: 27min 15sec (1635 seconds)
Published: Tue Jan 16 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.