Using Unicode as icons on tiddlers?

The Google noto fonts (Short for no tofu - the missing symbols) seem to be an answer for multiple language character sets and symbols.

It seems to me however a font that focuses on symbols that are international in nature but not supporting the different languages would be ideal for empowering tiddlywiki to make use of unicode, I say this because if a tiddlywiki needs character’s for different languages then presumably the wiki, browser or device is using these specific language fonts. That is the wiki need not be responsible for the languages, just the extended symbol sets.

  • So far finding a free, good and reliable font to provide symbols but not alternative languages has being difficult.

The alternative code for $:/core/ui/TiddlerIcon as posted by @TW_Tones above works great, but understandably only in tiddler titles, it does not work e.g. in tag pills (and probably many other places e.g. buttons).
I attempted to solve it for tag pills by editing $:/core/macros/tag – similarly to solution above I have added <$list filter="[<tiddlerIcon>has[title]]" emptyMessage="""@@vertical-align:top; {{!!icon}}@@"""></$list> around the code that transcludes the icon tiddler. The edited $:/core/macros/tag looks like follows:

\define tag-pill-styles()
background-color:$(backgroundColor)$;
fill:$(foregroundColor)$;
color:$(foregroundColor)$;
\end

<!-- This has no whitespace trim to avoid modifying $actions$. Closing tags omitted for brevity. -->
\define tag-pill-inner(tag,icon,colour,fallbackTarget,colourA,colourB,element-tag,element-attributes,actions)
<$vars
	foregroundColor=<<contrastcolour target:"""$colour$""" fallbackTarget:"""$fallbackTarget$""" colourA:"""$colourA$""" colourB:"""$colourB$""">>
	backgroundColor="""$colour$"""
><$element-tag$
	$element-attributes$
	class="tc-tag-label tc-btn-invisible"
	style=<<tag-pill-styles>>
>$actions$<$list filter="[<tiddlerIcon>has[title]]" emptyMessage="""@@vertical-align:top; {{!!icon}}@@"""><$transclude tiddler="""$icon$"""/></$list><$view tiddler=<<__tag__>> field="title" format="text" /></$element-tag$>
\end

\define tag-pill-body(tag,icon,colour,palette,element-tag,element-attributes,actions)
<$macrocall $name="tag-pill-inner" tag=<<__tag__>> icon="""$icon$""" colour="""$colour$""" fallbackTarget={{$palette$##tag-background}} colourA={{$palette$##foreground}} colourB={{$palette$##background}} element-tag="""$element-tag$""" element-attributes="""$element-attributes$""" actions="""$actions$"""/>
\end

\define tag-pill(tag,element-tag:"span",element-attributes:"",actions:"")
\whitespace trim
<span class="tc-tag-list-item" data-tag-title=<<__tag__>>>
<$let currentTiddler=<<__tag__>>>
<$macrocall $name="tag-pill-body" tag=<<__tag__>> icon={{{ [<currentTiddler>] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerIconFilter]!is[draft]get[text]] }}} colour={{{ [<currentTiddler>] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerColourFilter]!is[draft]get[text]] }}} palette={{$:/palette}} element-tag="""$element-tag$""" element-attributes="""$element-attributes$""" actions="""$actions$"""/>
</$let>
</span>
\end

\define tag(tag)
{{$tag$||$:/core/ui/TagTemplate}}
\end

There are two problems with this solution however:

  1. If an icon tiddler is linked in the icon field of a tag, a link to the icon tiddler is rendered instead of the icon.
  2. It is not rendered as pretty as in the title. In the tag pill the unicode character (e.g. emoji) is pressed against the tag title with no space in between.

I will try to solve it, but I hope someone with more experience in TW and CSS can help out, so that I won’t be reinventing the wheel here.

You can directly paste UTF-8 icons, e.g this :grinning: directly into a tag pill, if that is what you’re asking about.

Yes, I see the problem, fix below, it was an oversight when considering this, I wonder where else the icon field is referenced and treated as a tiddler title?

  • The $:/core/macros/tag assumes the icon is a tiddler name to transclude.
    • It’s retrieving the icon using the Tiddler Icon cascade
  • The tiddler manager lets you select an icon using $:/core/ui/TagTemplate and all references seem to go back to the tag-pill-body macro, then tag-pill-inner,
    • Thus modifying tag-pill-inner or providing an override fixes this.
    • All that remains is to add the icon edit to the tag manager?

So here is a fix with the updated tag macro as well and seems to be working;

unicode-image-wikitext-icons.json (2.7 KB) updated

  • Please test and comment
  • Let me know if it needs fixing elsewhere?
    • Existing button transclude Icon tiddlers, to change these to unicode replace the transclusion with unicode, and they are typically not using, if ever, the icon field
1 Like

Thanks a lot @TW_Tones , as far as I have tested it works as expected, that is, the unicode content of icon field is displayed in titles and tag pills. This all I needed.

As far as proposing core change is concerned, it seams reasonable to me, but obviously I have not much expertise in how TW works, and if such a change is a good one. But now it is at least a complete solution, rendering the unicode icons everywhere where expected.

1 Like

Thanks for the review @vilc lets see if some of out developers have a look and comment or propose improvements to the methods used.

The proposed core change alters the existing semantics. Specifically, using the existing core code, if the icon field contains a title that does not exist, then nothing is displayed. In contrast, with your proposed change, if the icon tiddler doesn’t exist, then the text contained in the icon field is shown in place of the icon.

In addition, the desired effect (showing a Unicode character instead of an image) can be currently be accomplished without any core changes, just by entering the Unicode character or character entity (e.g., &#x1F5BC;) in the tiddler referenced in the icon field.

-e

2 Likes

Yes, certainly,

  • However
    • The desired effect is not all the proposed solution offers, it allows any wikitext that is not the same as a tiddler title to be used.
    • this does require the creation of a new tiddler
      • and sometimes more than one for dual or multiple state buttons
      • This interferes with the value of having single tiddler buttons and the reduced bytes required, only one in an icon field, less that currently.
  • On the positive side, with both methods, you can then wrap it in color css etc… because they are transcludes.
    • Although when used in the toolbar this CSS is likely defeated with core toolbar classes
  • Actually the code form &#x1F5BC; is not necessary, you can paste directly the character.

Never the less I agree the package I made is fine as an installable (for now), but installable become a dependency when the feature is used in another package, undermining the single tiddler advantage, we would have if it were in the core.

However its done, the reason we need new icons is because we need more and SVG is often excessive.

I observe now we have a cascade for Tiddler Icon the idea that the “icon field contains a tiddler title” for the icon, is now unfortunately cemented into tiddlywiki core functionality.

  • In some ways this forces the use of a seperate icon tiddler.
  • unfortunately such tiddlers, using unicode must also contain the css @@vertical-align:top; {{!!icon}}@@ Thanks @EricShulman for that tip.

I am now working on a cascade to set the icon conditionally for a given fieldvalue, but I cant introduce the unicode version without a icon tiddler :frowning_face: .

One could just use the unicode character as the first character of the title, like
:wave: HelloThere
It would automatically also show up in tag pills and whatnot and would require no changes in any system tiddler. Also, you could search for it, e.g. find all tiddlers starting with a :skull:, because you use that to identify a certain category (those describing problems) of tiddlers. Changing the icon later is gracefully taken care of by our favorite plugin, Relink.
However, using this probably would mess up alphabetic sorting, if you need that sort of thing.

Have a nice day
Yaisog

2 Likes

That is a useful tip, however its different when creating buttons or using the cascade.

But a good point anyway.

Useful tip. Thank you @Yaisog

After some more testing I have found two small issues relating to $:/core/macros/tag and tag pills:

One: The &nbsp; between the icon and tag title is displayed, as the filter [[$icon$]has[title]] implies, only if the icon field is not a title of an existing tiddler, so also when it is empty. As a result the &nbsp; shows also when there is no icon specified at all.

I was able to fix it (somehow) by adding the &nbsp; inside a separate list widget with filter [[$icon$]!has[title]!compare:string:eq[]], see attached version of $:/core/macro/tag
It doesn’t solve the second issue however.

Two: There is a whitespace character rendered at the beginning of the tag pill if either:

  • icon field is empty
  • icon field contains unicode but not a title of existing tiddler
    If the icon field contains title of existing icon tiddler, it is rendered correctly, same as in unmodified TW, without any unnecessary whitespaces.

I was not able to solve this one. It is much more cosmetic than the first issue however, as the &nbsp; sometimes stayed in a line above the tag title (as it doesn’t break), so the tag pill would take two lines with the first one empty.

Somehow it doesn’t feel right that the &nbsp; is needed at all for spacing, as the default tag pill icons and title icons (also the unicode tiddler icons per your solution) do need any whitespace characters for proper spacing.

$ _core_macros_tag.json (2.2 KB)

1 Like
  • Thanks for that, half the problem is identifying the problem

The cause

  • The original method was simply to transclude
    <$transclude tiddler="""$icon$"""/>
    • This was even when icon was blank but had no side effect.
  • I relied on emptyMessage when [[$icon$]has[title]] was not true, which is also the case when $icon$ is blank, ie icon field is empty.

The solution

  • Just transclude the “icon”, even when the icon is empty
    [[$icon$]has[title]] [[$icon$]is[blank]] +[limit[1]]
    The limit ensures we only attempt transclude once although the two conditions should never be true at the same time.
  • Now the emptyMessage only occurs if icon contains something that is not a tiddler title.

Updated package here and in all above
unicode-image-wikitext-icons.json (2.7 KB)

1 Like

This works much better, as it now does not mess at all with tiddler icons or no icons.

There remains however the problem of the whitespace character in front of the unicode icons.
Here how it looks when using tag-pill macro (looks the same using tag macro, but then it is not possible to select text to show it):
modsel
When inspecting the unicode icon it looks like this:
insp
The icon field of the tag “Icon in unicode” contains just the “:eight_spoked_asterisk:” character, no space in front of it. Displaying of the space before the unicode icon seems to come from some properties of the html span perhaps? It is not specific to emoji, it happens for any character in the icon field.

@vilc thanks for looking closely, in @@vertical-align:top;$icon$&nbsp;@@ there was a stray space before $icon$ I removed, can you do this and see if the fault still occurring if you remove that?

1 Like

Yes, that was it, it displays correctly now.

As it is now, I think I will continue to use it, as it renders correctly and doesn’t break the default functionality.

But it is definitely more a hack now than something ready for including in core code. Works good for single characters (other than ") and that was the whole purpose of this, but since it is interpreted as both potential tiddler reference and html, all sorts of things happen when the icon field is set to e.g. [[]], {{}}, @@, ", color:red;X, <br>.

Hi

Here is the workflow I use for unicode tiddler icons. For sake of brevity let’s say the unicode character we want to add to our tag is “:boom:”.

  1. Create a new tiddler, change its title to :boom:, its body text to :boom:, and add tag $:/tags/Image
  2. Open the tag manager, select the tag you want to add :boom: as an icon, open the dropdown list and choose :boom:
  3. That’s it.

Notes:

  • The $:/tags/Image system tag makes your new icon appear in the icons list in tag manager
  • Creating a new tiddler for the icon can feel tedious, but it’s already the case for every other icon…
  • If you don’t want your unicode icon tiddlers to appear in Recent tab or standard searches, you can prefix their title with $:/myicons/ like this: $:/myicons/💥 but then they will be listed with system icons in the dropdown list of tags manager.
  • Unicode icons tiddler can also be used as icons for tiddlers, through their icon field.

Hope this helps,

Fred

Fred I am sure this workflow will prove useful to some. It is however the way we currently would do it.

  • just to be clear however we made a solution that allows the icon field itself contain unicode, wiki text or named icon tiddlers. It is compatible with your instructions but adds a little more.
  • if modifying core buttons its best still to use icon tiddlers but custom buttons need not.

Thanhs for your contribution.

I was just reviewing this with a view to deciding if we would ask for a core change.

  • My conclusion is no, but a plugin/json package would be good.

Extending @EricShulman and @tw-FRed ideas and taking it a bit further to make the effort of creating a new image tiddler worth while. And avoid changing the core I thought of the following;

  • Provide a tool in which you give a Unicode icon and click to create;
    • Create a tiddler with the title and body set to the Unicode icon, add a field indicating it is a Unicode icon eg object-type=unicode-icon, and/or perhaps give it a unicode tag?
  • You can now use the Unicode character as an icon because it is also a tiddler.
    • It will not come up in search without you searching for the character itself and at least two spaces (by default)
  • Now add a view template for all tiddlers object-type=unicode-icon that lists all tiddlers and fields where the icon is “mentioned”, so if you open such a tiddler you can see where it is in use.
  • perhaps a feature on the edit of the icon field, if the content is not a tiddler title eg new unicode icon, present the button to create it, or select from existing images.

This approach adds value to the effort of creating a separate tiddler. You could also provide a tooltip, description and usage guidelines.

  • The only gap from my original proposal is we can’t give wikitext as the icon without editing the unicode icon tiddler body.