Can I make ReText use a different font type for displaying code?
I'm using ReText 3.1.4 (Lubuntu 12.10) to make notes for myself. I want to know if it's possible to use a different font for displaying text that is marked as code in preview mode:
In the image, Sort
and ~/.config/pcmanfm/lubuntu/desktop-items-0.conf
appear faded. I feel that's an issue with Courier (not just in ReText). I would like to use Ubuntu Mono or DejaVu Sans Mono instead of Courier. Is that possible? How?
I installed all the recommended software suggested at the time of installing Retext from the Lubuntu Software Center and that included Qt Configuration 4.8.3
which allows a lot of customization. I can use the Fonts tab of this application to change the default font but not that of the font responsible for text in depicting code:
We can use Cascading Style Sheets (CSS) to achieve this.
If you are new to CSS and want some help/tutorial, see this Stack Overflow question:
- The best CSS tutorial/site/blog/book
Also refer to the ReText Wiki for Configuration File:
- ReText Wiki for Configuration File
Follow these steps to create and modify the CSS File:
ReText stores its configuration files at
~/.config/ReText project/ReText.conf
. Open your File Manager (Nautilus if you are using Ubuntu). Press Ctrl + H to show all the hidden files. Now, navigate to the directory.config
→ReText project
. Here you would findReText.conf
. We would need to edit it to point to ourcss
file. But let's first create thecss
file.In this same directory create a file called
myconfig.css
(you can name it whatever you want). Now open it in a Text Editor.-
Edit the file as below:
code { font-family: Ubuntu Mono, DejaVu Sans Mono; background-color: #D3D3D3; } pre { background-color: #D3D3D3; }
Obviously, what you want is to only set the
font-family
property tocode
tag. However, I recommend to setbackground-color
property as well to bothcode
andpre
tags. I have set thebackground-color
toLightGrey
(its Hex Value is#D3D3D3
). You may modify the color to your tastes and preferences. The following link should help you in this regard.- Popular Colors and their Hex Values
-
Now modify ReText's Configuration file to point it to the newly created stylesheet. Open
~/.config/ReText project/ReText.conf
in your Text Editor and add thestyleSheet
setting at the end and point it to its location. For me it is:styleSheet=/home/aditya/.config/ReText project/myconfig.css
Note:
- Ensure that you provide the full path to the file. It cannot expand
~
as your$HOME
. - Furthermore, if you named your css file as something other than
myconfig.css
or placed it in some other directory, ensure that you provide the correct file name and path.
- Ensure that you provide the full path to the file. It cannot expand
If you already had ReText running, close and restart it again for changes to take effect.
How to know what HTML <tag>
to modify
If you are unsure about the tag names, you can view the HTML code of your markdown and then make your preferred changes to CSS.
Edit Menu → View HTML code would show the markup of your markdown text.