Formatting Anki: using a cursive font (Hebrew)

All about language programs, courses, websites and other learning resources
User avatar
zenmonkey
Black Belt - 2nd Dan
Posts: 2528
Joined: Sun Jul 26, 2015 7:21 pm
Location: California, Germany and France
Languages: Spanish, English, French trilingual - German (B2/C1) on/off study: Persian, Hebrew, Tibetan, Setswana.
Some knowledge of Italian, Portuguese, Ladino, Yiddish ...
Want to tackle Tzotzil, Nahuatl
Language Log: viewtopic.php?f=15&t=859
x 7030
Contact:

Formatting Anki: using a cursive font (Hebrew)

Postby zenmonkey » Wed Apr 26, 2017 5:41 am

Adding a specific font to Anki isn't too hard and in a few minutes one can set up a rare language or a stylistic font like cursive.

I need to learn Hebrew cursive so after playing around a bit with it, here it an outline (borrowed heavily from the User's Manual) on what I did, hope it helps others. Feel free to ask questions, make comments.

Add font to Anki
To add a font to Anki, it must be in the TrueType format. TrueType fonts have a filename ending in .ttf, such as "Arial.ttf".
I found that not all TrueType fonts work and the first two fonts created errors. For Hebrew cursive I found the Nachlaot font to be ok. (it's a bit small, please share your favourites. It can be found here: http://www.cs.uky.edu/~raphael/yiddish.html)

Take your font file and rename the file, adding an underscore at the start, so it reads "_nachlaot.ttf".

In your computer’s file browser, go to your Anki Folder, and then a folder called "User 1" (or your profile name if you’ve renamed/added profiles). Inside the folder, you should see a folder called collection.media. Drag the renamed file to that folder.

On the Mac - Finder - Go to Folder: "~/Library/Application Support/Anki2" to find this folder.

Update the template

In your deck, click Add at the top of the main screen, and then select the note type you want to change with the top left button.
Click Cards.
In the styling section, add the following text to the bottom (after the last "}" character), replacing "_nachlaot.ttf" with the name of the file you copied into your media folder:

@font-face { font-family: myfont; src: url('_nachlaot.ttff'); }

Only change the url part, not the "myfont" part.
After that, you can either change the font for the entire card, or for individual fields. To change the font for the entire card, simply locate the font-family: line in the .card section and change the font to "myfont".

Make sure the filenames match exactly. If the file is called arial.TTF and you write arial.ttf in your card templates, it will not work.
Fonts on a Mac - Embedded fonts currently do not work on OS X. It is still possible to use custom fonts, but they need to be installed system wide. Install the font in the Mac

You can set up Anki to use the system font on a Mac computer, and an embedded font elsewhere.
On your front or back template, wrap the field you want to style in the following code, replacing "FieldName" with the name of your field.

<span class="mystyle">{{FieldName}}</span>
In the styling section, in addition to the font-face line described above, add the following:

.mystyle { font-size: 40px; font-family: myfont; }
.mac .mystyle { font-size: 40px; font-family:Nachlaot; }

(I use the font sizing because, like I said, Nachlaot is really small)
Replace "Nachlaot" with the name of the font you installed on your system.
Keep "myfont" and "my style" as is, as it references the font you embedded.

Your styling should look a little like this:
Screen Shot 2017-04-26 at 07.31.46.png


You can either keep two different Note Types - one with the cursive formatting and another without cursive and switch your cards between them or set up an extra field in the font you want to use ('Cursive' in my example) so that your card entry looks like this:

Screen Shot 2017-04-26 at 07.35.19.png


You then have two fields (here 'Hebrew' and 'Cursive') which can have the same text (quick copy and paste) when you want both print and cursive, or just use one field for either print OR cursive.

Playing with this should let you use almost any alphabet system in Anki.

If you use Anki, maybe you have a better card format/layout?
You do not have the required permissions to view the files attached to this post.
5 x
I am a leaf on the wind, watch how I soar

Return to “Language Programs and Resources”

Who is online

Users browsing this forum: Tumlare and 2 guests