How to force a field into one line, with a condition

778 views
Skip to first unread message

rudye...@gmail.com

unread,
Oct 29, 2018, 4:19:15 AM10/29/18
to AnkiDroid
I'm studying bits of sentences/words in Japanese, some are short some aren't.
I.e.1:例のようにノート
I.e.2:こちらこそ
I find it that the optimum size for it, when I study it, is 60px (but the answer is 20px). And I have correlated cards. So I change the size to 60px for that field, so it's visualized the same in all cards. For the example n2 it's perfect, but for the example n1 it shows the answer in two lines (usually if it's 7 or more characters), which I don't want. For this case, being usually mostly easier characters, I accept smaller size
So my question is:
How can I force the field into one single line? But at the same time keeping the shorter (6 or less characters per field) fields at the size of 60px.
I.e.n1 forced in a single line (using completely the space in the line)
I.e.n2: at 60px
Please type it because I'm not really good at understanding code. And just call the field {{a}} for simplicity.
Thank you in advance.

Renato Goes

unread,
Oct 29, 2018, 8:17:57 AM10/29/18
to anki-a...@googlegroups.com
How long usually the longer sentences are?

I guess what you can do is create two input fields ("FirstLine" and
"ExtraLine") and control what is input on each manually.
The first one get the 6 or less characters, and the second one get the
rest (you can also create second line and so on for the 12th, 18th
...).
Then you need to change the front text depending on the existence of
some text on the ExtraLine by using a conditonal replacement (check
the manual for more details
https://apps.ankiweb.net/docs/manual.html#conditional-replacement)

In your case the front card would be:
{{#ExtraLine}}
<div class="twolines">{{FirstLine}}{{ExtraLine}}
</div>
{{/ExtraLine}}
{{^ExtraLine}}
<div class="oneline">{{FirstLine}}
</div>
{{/ExtraLine}}

The first block show both fields if there is something on ExtraField
and set the twolines style.
The second one depends on ExtraField being empty and show only the
FirstLine and uses the one line style.

The styling template would be:
.twolines {
font-size:40px;
}
.oneline {
font-size: 60px;
}

You need to check if 40 px is enough for 12 characters.
It is also possible to expand that code to work with three or more fields.

I hope this is enough to help you solve your problem, but if it is
not, do not hesitate to ask,
renato
> --
> You received this message because you are subscribed to the Google Groups "AnkiDroid" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to anki-android...@googlegroups.com.
> To post to this group, send email to anki-a...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/anki-android/1f47921f-737a-4d34-a34e-b0e4abe6a3d2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

rudye...@gmail.com

unread,
Oct 29, 2018, 11:36:25 AM10/29/18
to AnkiDroid
The sentences are mixed with expression and words, anyway most of them are shorter than 6. Just some of them are between 7 and 12. I doubt i created longer than 13.
I read on the manual but still cannot solve it. I think I got something wrong.
I tried, then replaced with my own fields, but still didn't work.
I think you suggested to move the sentences longer than 6 from the old field (that in my case I called Expression) to a newly created field (Expression2) for this purpose, and in this case erase the content of the field Expression.
I post the templates as they are right now:

Front template:
{{#Expression2}} <div class="hrgn">{{Expression}}{{Expression2}} </div> {{/Expression2}}
{{^Expression2}} <div class="knj">{{Expression}} </div> {{/Expression2}}

Styling (shared between cards):
.card { font-family: arial;
font-size: 20px;
text-align: center;
color: black;
background-color: white;}
.knj {font-size: 60px;font-family:"Yu Mincho Demibold"}
.hrgn {font-size: 40px;font-family:"Yu Mincho Demibold"}

Back Template:
{{FrontSide}}<hr id=answer>
<div class=knj>{{Expression}}</div>
<div class=hrgn>{{Reading}}</div><br>
{{Meaning}}<br>
{{2ndDef}}

Actually I would like to do the same for the field called Reading, but one step at the time, and actually I guess if the main one is solved then I should be able to solve this secondary problem.

Thank you Renato

rudye...@gmail.com

unread,
Oct 29, 2018, 11:40:00 AM10/29/18
to AnkiDroid
Eventually is there a way to fit with whichever width is the screen? As big as possible to fit with the with of the screen?

Renato Goes

unread,
Oct 29, 2018, 12:20:07 PM10/29/18
to anki-a...@googlegroups.com
I tried to copy your code, and it worked for me (see the screenshots below).

However, now that I check it again my solution looks stupid.
I was suggesting to split the first 6 chars to Expression and put the rest on Expression2.
If there is a second field, it is easier to just put the whole sentence there as you said.

Can you try:
Front:

<div class="knj">{{Expression}} </div>
<div class="hrgn">{{Expression2}} </div>

In this case both fields are displayed with a different font size, but one of them will be blank.

Screenshot from 2018-10-29 13-06-35.png
Screenshot from 2018-10-29 13-08-18.png

If it still does not work, can you post some screenshots?

For the reading field all you going to need is a new field (Reading2) and a new style .rdng { font-size:20px;}.

> Eventually is there a way to fit with whichever width is the screen? As big as possible to fit with the with of the screen?

I'm not sure if it's possible to do that with ankidroid.
If you use a phone and a tablet with different screen sizes, there is an option to scale all the cards, but I guess this is not what you are looking for.


On Mon, Oct 29, 2018 at 3:40 PM <rudye...@gmail.com> wrote:
Eventually is there a way to fit with whichever width is the screen? As big as possible to fit with the with of the screen?

--
You received this message because you are subscribed to the Google Groups "AnkiDroid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to anki-android...@googlegroups.com.
To post to this group, send email to anki-a...@googlegroups.com.
Message has been deleted

rudye...@gmail.com

unread,
Oct 29, 2018, 1:25:05 PM10/29/18
to AnkiDroid
I post the screenshots. This is just a random easy2find long word. Both solutions/options seem to not work. Please do not mind the language in the 2nddef field.
Screenshot (53).png
Screenshot (54).png
Screenshot (55).png
Screenshot (56).png

Renato Goes

unread,
Oct 29, 2018, 1:51:24 PM10/29/18
to anki-a...@googlegroups.com
Can you create a card with some text on both Expression and Expression2?
Does it have the texts with different size.

Have you experiment with different font-sizes?
It looks like 40px might be enough for 7 chars, but not for more than it.
You probably need to pick a 12 char sentence and change the size to
make it fit just one line.
I suggest doing it directly on your mobile phone, as the screen on the
desktop version can be changed easily.

Are you going to bulk create those cards from a database or are you
going to manually add them as you see them?
On Mon, Oct 29, 2018 at 5:25 PM <rudye...@gmail.com> wrote:
>
> I post the screenshots. This is just a random easy2find long word. Both solutions/options seem to not work. Please do not mind the language in the 2nddef field.
>
> --
> You received this message because you are subscribed to the Google Groups "AnkiDroid" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to anki-android...@googlegroups.com.
> To post to this group, send email to anki-a...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/anki-android/33ca02a4-f35b-42f4-9345-e2b0c7addd8d%40googlegroups.com.

rudye...@gmail.com

unread,
Oct 30, 2018, 10:30:25 AM10/30/18
to AnkiDroid
Attached same word but now both fields Expression and Expression2 are identical and not empty.
Still same problem.
On my phone I cannot do changes (just maybe changing definitions but not changing templates.
How I do the cards: as I see/need them I add them manually, but I use a template of Anki for Japanese that, given a word, automatically fill the empty fields. For sentences I do slightly differently (more manually).
Screenshot (57).png
Screenshot (58).png

Renato Goes

unread,
Oct 30, 2018, 1:45:30 PM10/30/18
to anki-a...@googlegroups.com
Try this template:
Front template:
{{#Expression2}} <div class="hrgn">{{Expression2}} </div> {{/Expression2}}
{{^Expression2}} <div class="knj">{{Expression}} </div> {{/Expression2}}

From your first screenshot I can see that it is using the two different styles.
The second one has the problem to insert both fields when Expression2 exist, and this was my fault because I thought about splitting the sentence.
I thin the only problem now is the font size to fit 6 or 12 characters in one line.

You can edit it on your phone.
Go to the card browser, select on card with that note type and it will open the interface to edit the card.
Click on the bottom field "Cards: Main ....", and it will open the card style editor.
Screenshot_2018-10-30-14-28-10.png

If you imported it from a list (or another anki deck) I would suggest to use a spreadsheet to count the number of chars on the sentence and then attribute the font-size to fill the whole line.



rudye...@gmail.com

unread,
Oct 30, 2018, 3:40:28 PM10/30/18
to AnkiDroid
Now it's working! Thank you very much Renato!
Now I made some little modifications (I made the same thing for the 'Reading' field into Reading2), and manually copied the field (only) for the longer sentences/words.
And thank you also for showing me the editor option (the one under the tag thing, I didn't know it existed), but I still prefer to edit on the desktop: easier with keyboard and mouse. Anyway it's very useful if I see something I want to change without the need of the desktop.
About spreadsheet: I agree but in this case I need to add by piecemeal.
Again: Thank you very much Renato

Renato Goes

unread,
Oct 30, 2018, 5:30:28 PM10/30/18
to anki-a...@googlegroups.com
I'm glad I could help.

I just found that Anki can use javascript to control the cards contents/style.

Front Template:
<div id="varsize" class="front">{{Front}}</div>
<script>
var size = document.getElementById("varsize").innerHTML;
size = Math.min(480/size.length,60)
document.getElementById("varsize").style.fontSize = size + "px";
</script>

It will control the font size depending on the sentence length.
There are two variables that you will need to change to adjust to your
screen size/preference on the line "size = ...."
480 should be slightly smaller than you screen size.
You need to tweak it and see which value fits you.
And 60 is the maximum size the sentence will be shown. For shorter
sentences (less than 5 chars) the calculated font size would be too
big. I guess 60px is enough.
> --
> You received this message because you are subscribed to the Google Groups "AnkiDroid" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to anki-android...@googlegroups.com.
> To post to this group, send email to anki-a...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/anki-android/545ef37d-558b-4f41-8023-4003d1c0f2c1%40googlegroups.com.

rudye...@gmail.com

unread,
Nov 7, 2018, 1:53:55 AM11/7/18
to AnkiDroid
Well, for now, I think it's good with the previous template you show me, so I thank you.
It seems that you too have studied japanese, so I'd like to ask you something else, if I can.
They are just minor problems I have using Anki.
For example: I have 2 cards that have the same Reading field (in the reverse mode), so everytime I see a Reading (doing my reviews) I remember one kanji and one meaning, but often it's the wrong one (maybe because the day before I've seen the other kanji, so in my short memory it's easier to recollect that one). Anyway, this way I make many mistakes, that are not real mistakes, because most of the time I remember correctly the other kanji and meaning, just it shows up first the other meaning; but this way I don't test it. So my question is: how did you solve this problem when you were studying it? Otherwise: is there a way, that for cards (automatically generated from the template I use) that have the same frontside to generate a special backside that shows both cards (like screen divided, on top the reading, on the bottom left one kanji and its meaning, on the bottom right side the other kanji and its meaning).

I'm also exploring the cloze option: is there a way to make the cloze deletion without the need to type the code {{c1: that is a bit troublesome on the phone (especially if you type in non latin alphabets).

Thank you Renato Goes

Renato Goes

unread,
Nov 7, 2018, 11:56:42 AM11/7/18
to anki-a...@googlegroups.com
I don't use the reading field on the front, because I think it lacks
context and there are too much homographs/homophones.
It might help you to understand more what you listen, but I think it
needs more context to make sense, otherwise it become a time sink as
you described.

What I'm doing is creating three cards for each note.
All of them show the kanji on the front side, and one of them ask for
its reading, one of its meaning, and one both.
I still show both answers on each cards to help me remember the other
one (reading or meaning).
I found it good enough to force me remember both, because when I had
just one card showing all the information, I usually just memorized
one of them.

I'm also not interested in using the kanji on the back side, because
I'm not interested into writing them by hand, and when I type them the
suggestions are enough to pick the right one.
If you want to be able to write them by hand or have a stronger grasp
on them, I suggest using a different program/app to force you write
them and check all the details.
Obenkyo (https://play.google.com/store/apps/details?id=com.Obenkyo)
has a test to write the kanji based on the reading/meaning (you can
choose one of them or both) and it has a weighted score to determine
which ones should be tested (as anki it tries to show you the ones you
fail the most more often).
It also allows you to introduce just a few new ones to be tested and
has some bigger categories using both JLPT or school levels.

When I card has two very different reading for the same kanji, or
different kanji for the same reading and meaning, I usually just
create a card for each and add the other reading/kanji below the rest
of the card (I just put it in the meaning field, no extra field
needed).

If you want to keep using the reading on the front side, I recommend
you to use the anki desktop to flag all duplicate cards based on the
reading field, export and merge them using a spreadsheet.
Then I would create a new template for homographs which would show the
reading and one of the kanji/meaning and ask for the other.
It is not ideal, but I think it might be enough as the spacing
algorithm will show you the failed cards more often.

I tried creating some cloze cards for other subjects, but I found even
the Anki desktop interface a little cumbersome when handling more than
one cloze per note.
I ended up using Emacs and created some keybindings to add and
manipulate the {{c1:: and }}.
If you want a simpler solution, I suggest using a simple text editor
and instead of {{c1:: just type XX (or something else that will not
appear on your text, it might even be some Japanese characters that
never appear together, such as '。ー') and after you finished marking
all your cards, you can search and replace them for the correct one.
It works well when creating several cards, but it still too much work
for a single card.
> To view this discussion on the web visit https://groups.google.com/d/msgid/anki-android/26cc127a-32ce-47e4-a64b-b5e972f7cbb7%40googlegroups.com.

rudye...@gmail.com

unread,
Nov 14, 2018, 3:58:48 AM11/14/18
to AnkiDroid
(sorry for the delayed answer)


Well, I need the reading field because I find it useful, even if it is without context. When I practice with other students something I stop the conversation to think which word is the one they say in a sentence (I literally stop my understanding for a single word). Anyway I found useful your solution about flagging the duplicates. Thank you, Renato!
Regarding the kanji on the back side: I need this feature as well. I study at the University and I will be tested on a written level so.. Besides, Jp is only the secondary language of my course (even if now I'm studying it more than the other), the main one is Chinese and since some are different and some are the same I need to have a stronger grasp on them in order to not use/write the wrong one (i.e. the equivalent one of the other language).
I had a look at the app you suggest me, but at the moment I prefer to stick with my own method.
At the moment I'm quite happy with the jp decks I created, but I want to amplify/substitute the old ones I use for chinese. On Anki I found some interesting ones, but often lack one of the feature I want in order to study, so I plan to create a newer deck (input one by one, but with the chinese addon help: I know it's a little time sinking but's ok for me for this since I really want to learn and make a really good one). The problem is that some features (in particular two I've seen in a specific shared deck on Anki) I've seen in other decks I don't know how to replicate, without copying all the cumbersome rest of the code (As you understand I'm not very good at coding, but I'm willing to learn). May I ask you your help to understand it?
Thanks in advance Renato Goes!

Renato Goes

unread,
Nov 14, 2018, 2:59:46 PM11/14/18
to anki-a...@googlegroups.com
> At the moment I'm quite happy with the jp decks I created, but I want to amplify/substitute the old ones I use for chinese. On Anki I found some interesting ones, but often lack one of the feature I want in order to study, so I plan to create a newer deck (input one by one, but with the chinese addon help: I know it's a little time sinking but's ok for me for this since I really want to learn and make a really good one). The problem is that some features (in particular two I've seen in a specific shared deck on Anki) I've seen in other decks I don't know how to replicate, without copying all the cumbersome rest of the code (As you understand I'm not very good at coding, but I'm willing to learn).

Send me a link to those decks and a short description of what you want
to replicate and I can take a look at it.

I guess that the addon is similar to rikaichan/rikaikun, and it works
mostly as a dictionary.
In that case, you can probably use excel or other spreadsheet program
with the original dictionary file to create them automatically.
> --
> You received this message because you are subscribed to the Google Groups "AnkiDroid" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to anki-android...@googlegroups.com.
> To post to this group, send email to anki-a...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/anki-android/e458d7c7-3e1d-418a-a904-5849861cbc65%40googlegroups.com.

rudye...@gmail.com

unread,
Nov 15, 2018, 2:12:21 PM11/15/18
to AnkiDroid
This is the link of the deck: https://ankiweb.net/shared/info/1907668496
It's a complete deck but not exactly what I want, anyway very close.
I use instead this add-on "chinese support": https://ankiweb.net/shared/info/3448800906
So that I create cards also on words that aren't on the list for proficiency tests, but that I need for other reasons (taught in class or specific words that I simply want to know)

Interesting feature n1 I'd like to use: colouring of the kanji field (not only in the simplified version but also in the traditional one: I plan later on to study also the traditional, but not now) and in the reading field. So the tones, instead of being just plain black, change their colour depending on their tone (helps a lot the memorization). So far I understood that the add-on helps me to somehow download a coloured version of the field Simplified (called Color) and the Reading, but not the Traditional (that is always black). But I want to still be able to keep the black one (on the question side). In the downloaded pre-made deck I was able somehow to "color" the traditional hanzi, but with unwanted consequences (like something else becoming black, or the reading becoming in a uglier font: I really don't understand how).

Other features aren't really important at the moment, but they would be useful like this one (n2): somehow the deck has the reading saved as hao4 (4 indicates the tone of the syllable hao), but using the card I see hào (the number disappears and transforms in the properly stressed vowel). Looking at the code I see there is written a conversion table for Zhuyin (not exactly what I want now, but I'm able to read easily that too, and it's better than the hard to read hao4 with the numbers). Since I've created cards with the numbers indicating the tones (it was the faster way to type them but annoying to read), I was wondering how to implement that table to change the aspect of the old cards (old cards are mostly small sentences that help me remember grammatical structures I've learnt in class).

Thanks in advance Renato for all the help in understanding and using the code
Reply all
Reply to author
Forward
0 new messages