Abbreviations and Definitions in a Dataview table

What I’m trying to do

I use Obsidian to assemble documents, each with its own folder full of chapters.
Each document needs a table of Terms and Abbreviations, with the columns:

  • Abbreviation
  • Term (1 or more)
  • Definition (1 for each term)

Each item in the table is stored in 2 notes. The above example would have a note for the abbreviation:

---
tags:
  - abbreviation
  - AbbreviationTestDocument
terms:
  - "[[term1]]"
  - "[[term2]]"
---
# Abbreviation with YAML terms

and a note for each term’s definition, e.g.:

# term1
Definition of TERM1

All the abbreviation notes are in a root folder shared by all documents. Each abbreviation is tagged “abbreviation”, and also tagged with the document or documents they need to be included in. In this way, each document can include the abbreviations it needs, and abbreviations can be shared between documents.

I really like the idea of separating the abbreviation from the definition, because there are many cases where an abbreviation has multiple meanings. It feels more (insert the Obsidian equivalent of “pythonic” here).

In each document I have a note called “Terms and Abbreviations” containing a dataview query like this:

TABLE
terms AS "Term(s)"
FROM #AbbreviationTestDocument AND #abbreviation 
SORT file

This returns a table with 2 columns, File and Term(s):

QUESTIONS
How can I include the text of each definition in the third column in the table?

Things I have tried

I’ve got as far as I can with the forum and general web searches.

I think I would like to expand the horizon a little and claim that one day you want to extend the information in your term definition so it wouldn’t be natural to include the entire term file into your table. And anyways, including the file content require javascript.

So my proposal to you is to use an inline field (or property) to define a summary within your term note, and expand your query a little.

```dataview
TABLE termAndSummary as "Term(s)"
FROM #AbbreviationTestDocument AND #abbreviation 
FLATTEN list(map( terms, (t) => t.file.link + " » " + t.summary)) as termAndSummary
SORT file
```

If you’d like the terms to be in separate rows, one way to do so is to FLATTEN terms as term, but it’ll duplicate the abbreviation in front, but it’ll also allow for various other sorting option. This query should do the trick with flattening.

```dataview
TABLE term as "Term", term.summary as "Meaning"
FROM #AbbreviationTestDocument AND #abbreviation 
FLATTEN terms as term
SORT file ASC, string(term) ASC
```

Both queries are untested, but should work… :smiley:

These are both really nice ideas! I can still click on the term link to go to see more details.
I would include the summary field using ‘=this.summary’ in the body of the note, just to make sure it was seen. Then I can also include more details and links in the term definition note.
Thanks very much!

Oh, I forgot to mention one way of defining the summary. If you define it inline like the following example note:

[summary:: This is my summary, which is too long to fit on one line, so really someone should summarise the summary to make it shorter]

And some more descriptive text...

This could be styled into something like:

using CSS like the following:

.inline-field-key[data-dv-key="summary"] {
  display: none;
}

.inline-field-key[data-dv-key="summary"] + .inline-field-value {
  display: block;
  margin-left: 10% !important;
  margin-right: 10% !important;
  background-color: hsl(180, 100%, 8%) !important;
  border-radius: 10px;
  padding: 6px 15px;
  color: var(--text-normal) !important;
}

Then you don’t need to do the `= this.summary `, and you can make it stand out just as much as you want to.

Bonus tip: How to add a custom CSS snippet
  • Goto Settings > Appearance and scroll down to “CSS snippets” section, and hit the folder icon on the far right. This opens up a file explorer window, in the folder vault/.obsidian/snippets, which is were you want to save your css snippet
  • In this new window create a file, like myCss.css, where you copy the CSS into. Make sure this actually is a text file, and that the name ends in .css
  • Back in Obsidian, you should now see your myCss in the list of CSS snippets. If not, hit the refresh button
  • Final step is to click the enable button to the right of your file, and now your new CSS should be in effect
  • If you later on make changes in the CSS snippet file, the effect should be immediate. If not, try disabling and re-enabling the snippet, or in some strange cases, you would need to reload Obsidian. In 99% of the cases, the changes are immediate, though.
2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.