Link to definition table

I currently use this method to define words. I’d like to be able to link to these definitions in other notes, and perhaps hover over them to see the definition. I understand that I can do this with individual notes for each term, but that makes it much more annoying to write them down quickly, and see all definitions in a simple table.

Does anyone have any suggestions/experience with this?

Generally adapting to the syntax you presented for writing definitions makes it impossible to query these definitions easily.

You can use this search to query your term:

"| my term

You can use regex to identify your term-definitions pair syntax in scripts:

term (includes header row):
/\| ([A-Za-z0-9]+) \| /

A proper script should process these rows into separate files. To my mind the syntax you presented to write term-definitions makes using page preview extremely difficult.

1 Like

Nice example.
I use something else for definitions.

I’ve created a single note for each “key word” (e.g. “Risk Management”, “BCP”, “Objective”,…). Each note gets the tag definition.
Those notes are quite short, mainly one or two definitions from different sources (e.g. ISO,…). Just a few notes have three different (but similar) definitions.
The fine thing about this is, that you can see the definition in preview mode when you use the “key word” in your text.

And if I want a collection (like your table) then I use Dataview. This creates a table depending on the tags (e.g. “definition” + “Business-Continuity” or something like this). This way I can create easily different glossaries which automatically update.

1 Like

Thanks for explaining how you deal with this. I’ve got a few questions:

  • do you put the definition (that you query in the dataview table) in a specific yaml tag, or just in the body of the note? I can’t find a way for dataview to query the body of the note itself.
  • Not sure if you are aware of how to do this, but dataview tables are very ugly compared to normal markdown tables, is there any way to make them look like markdown tables (I’m hopeless at css)? I’ve included a screenshot of what the dataview table looks like with my theme (border)

There are three different consideration hidden in your request:

  • How to link to the definition
  • How to make the link appear
  • How to define the terms

How to link the definition

The difficult part of this is to get the linkage from a definition term to its definition. You can’t link into a table, to my knowledge at least. You can link to blocks or sections inside a file. But that would require either to tag the definition with a blockId, or placing the term into a section of its own.

Or possibly really tailor a task query to link to one given task. Not sure if that can be done inline with other text, or it requires a dedicated block/paragraph. The output could be tailered into just the word in question using FLATTEN as visual for the task in question.

It’s tricky to say the least in most of the cases, which brings us over to the second part.

How to make the link appear

I’m not sure how, or what trickery using javascript, you’d need to make a word just “pick up the link” itself. The only method I know of, is the unlinked mentions which requires there to be a note with that word as the title (or having that as an alias).

Other than that, I’m not sure how I would create the link. One way, if you had section links could be to do [[definition#Inherited Characteristics | Inherited Characteristics]. If using blockIds you’d need to sanitise the words for them to become a proper link, so maybe you could use [[definitions#^inheritedcharacteristics | Inherited Characteristics]] . In either case, you could use a template to transform the selected word into the link of your desire. In both of these cases, the link would provide you with the possibilities of previewing the link, so no tooltip would be required.

Using a task link, if at all possible, would require a link similar to `$= await dv.view(“_js/def”, “Inherited Characteristics”) `. I don’t know of a shorter way to write a custom call to a function using dataview. The advantage of this approach could be that it would be easier to include a tooltip for the presented result.

How to define the terms

Using a table doesn’t give you any proper link targets, so I don’t suggest that if you really want to get links to your definitions.

Using headings or section is most likely the better way to go, and then you’ll use either of the following variants:

## DNA

Deoxyribonucleic Acid

... or ...

DNA » Deoxyribonucleic Acid

These could be linked to or embedded. Theoretically you could possibly change the stylings for this document into more table or list like. At least with the headings…

I would love to say there is an easy way to use tasks, and this is indeed my preferred way of styling definitions:

- [=] (term:: DNA) Deoxyribonucleic Acid ^dna

But to make a task query display this easily, is just horrible. If you dare to do so, I challenge you to look at the beast in the details below. However, after thinking a little more, adding the blockId to this task, makes for a much better solution…

Ugly fugly task query to become inline

With a note containing this:

Hi there, this is text before 
WHERE term = "DNA"
FLATTEN "<span class='defTerm' title='My tooltip on DNA'>DNA</span>" as visual
And this is text after...

Next paragraph

And this CSS enabled through a snippet:

div:has(+ div.el-lang-dataview .defTerm ),
div.el-lang-dataview:has( .defTerm) + div {
    background-color: grey; 
    display: inline-block;
    float: left;

div.el-lang-dataview:has( .defTerm ) { 
    /* background-color: green; /* */
    display: inline-block; 
    float: left;
    & > div.block-language-dataview,
    & > div.block-language-dataview > div,
    & > div.block-language-dataview > div > ul,
    & > div.block-language-dataview > div > ul > li
        display: inline-block;
        & span.defTerm::after {
            content: "\00a0"; 

div.el-lang-dataview:has( .defTerm) + div + div {
    background-color: blue;
    clear: both; 

You could get it to display as:

Ignore the colors, but pay attention to how this CSS joins together the div before and after the query, and almost aligns them on the same line. But have some strangeness happening on the whitespace before and after.

This could possibly be corrected, but then again to use something like this in your text would mean to insert that query in the middle of the text, and it’ll look ugly in source mode, even if you managed to make it look nicer. But it’d link back to the definition…

… which also the much simpler blockId link to this task would do. :smiley:

After all that messy stuff in the previous post, I’m ready to present my best solution to your issue:

  • Use decorated tasks or lists to define your terms with a blockId on the task
  • Use block links in your notes, possibly using a template to generate the link

Term definitions

If you use a given file, like definitions, you could have tasks defined as:

- [=] (term:: DNA) Deoxyribonucleic Acid ^dna
- [=] (term:: genotype) Genetic information carried by an individual ^genotype

Which, when an annoying bug in dataview is fixed, and some styling applied could be displayed as:

Due to the bug, you might want to consider just doing:

- DNA » Deoxyribonucleic Acid ^dna
- genotype » Genetic information carried by an individual ^genotype

Which doesn’t get the icon, but could display as:

This latter markup would still allow for linking, but it wouldn’t allow for querying as easily, as you would need to manipulate file.lists and use something like startswith(item.text, "DNA") or similar shenanigans.

To build the blockId I simply just keep the letters and lowercase everything. Strip away any non-letters or spaces and so on.

Linking to the definitions

Given one file with definitions, you’d then simply do the [[definitions#^dna | DNA ]] variant to link to it. This could be automated using a template like the following:

const selected = tp.file.selection()

const blockId = selected.replace(/[^0-9a-z]/gi, '').toLowerCase()
tR = `[[definitions#^${ blockId } | ${ selected }]]`

To use it connect the template to a hotkey, and when in your file with a word having a definition (or you wanting it to have a definition), select the word and hit the hotkey and it’ll generate the link for you. (To ensure the same block id, you could hit the template within your definitions file and strip away the other stuff… )

I personally use individual notes, and Dataview for aggregation. It isn’t as much of an annoyance as you may think.

Using plugins like QuickAdd and Templater you can very quickly enter a note with prompts and have it filed wherever you want with whatever predefined YAML you like.

Then a simple Dataview aggregator like below. Hover shows you the definition.

I have this as an “index” in my Glossary folder.

TABLE file.folder as "Folder"
WHERE contains(file.path, this.file.folder) AND != AND != "Attachments" AND != "_attachments"

I second holroy’s suggestion to use a list instead of a table if you want to link to individual entries.

To preserve a table-like layout while using a list, there are (at least) 2 options to explore (neither of them especially smooth):

  • Between a term and its definition put 2 or more tabs wrapped in HTML pre tags. (You can’t type tabs in Obsidian so it would be best to make a template; or you could use spaces instead, but you’d probably still want a template).
  • Put the list in a custom callout type, mark the term and definition to distinguish them (for example using bold for one and italic for the other), and use a CSS snippet to set their widths to behave like a table’s cells (the snippet could also remove the boldness etc. if desired).