Link Search Menu Expand Document

Creating clozes

Table of contents

  1. Unnumbered Clozes
  2. Numbered Clozes
    1. Zero Clozes
  3. Showing, Hiding, and Revealing Clozes
  4. Hints

Unnumbered Clozes

Clozes are surrounded by c tags. By default, an unnumbered cloze will always be considered inactive.

/** Default cloze */
filterManager.install(
  closet.recipes.cloze.show({ tagname: 'c' }),
  closet.recipes.cloze.hide({ tagname: 'ch' }),
  closet.recipes.cloze.reveal({ tagname: 'cr' }),
)

/** Assign categories */
const baseStylizer = closet.Stylizer.make({
  separator: '・',
  processor: (v) => `《${v}》`,
})

const colorMapper = (v, _i, cat) => {
  if (v === '') {
    return []
  }

  const theColor = cat === 0
    ? 'yellow'
    : cat === 1
    ? 'darkseagreen'
    : 'indianred'

    return `<span style="color: ${theColor};${cat === 0
      ? '-webkit-text-stroke: 0.8px black; text-stroke: 0.8px black;'
      : ''}">${v}</span>`
}

const theBackStylizer = baseStylizer.toStylizer({
  mapper: colorMapper,
})

const theFrontStylizer = baseStylizer.toStylizer({
  mapper: (v) => v === '' ? [] : `<span style="color: lightgrey">${v}</span>`,
})

const theContexter = (tag) => {
  const flattedValues = tag.values.flatMap((vs, i) => vs.map(v => [v, i]))
  return flattedValues.map((v, i) => colorMapper(v[0], i, v[1]))
}

const assignCategorySettings = {
  backStylizer: theBackStylizer,
  frontStylizer: theFrontStylizer,

  inactiveStylizer: baseStylizer,
  contexter: theContexter,
}

filterManager.install(
  closet.recipes.multipleChoice.show({
    tagname: 'mc',
    ...assignCategorySettings,
  }),

  closet.recipes.multipleChoice.hide({
    tagname: 'mch',
    ...assignCategorySettings,
  }),

  closet.recipes.multipleChoice.reveal({
    tagname: 'mcr',
    ...assignCategorySettings,
  }),
)
The capital of Botswana is [[c::Gaborone]].
The capital of Argentina is [[c::Buenos Aires]].

Wow. As you can see, absolutely nothing happens. This is the specified behavior: the tag is inactive, and the default behavior for inactive clozes of this kind is to show their content.

You can make this more interesting by either using numbered clozes, or by using hiding or revealing clozes.


Numbered Clozes

Numbered clozes are go along with the notion of active clozes. Depending on the context, the card will be displayed differently.

In Anki, this context is provided for us in the form of card types. Closet will use this information and render the card accordingly.

/** Default cloze */
filterManager.install(
  closet.recipes.cloze.show({ tagname: 'c' }),
  closet.recipes.cloze.hide({ tagname: 'ch' }),
  closet.recipes.cloze.reveal({ tagname: 'cr' }),
)
The capital of Botswana is [[c1::Gaborone]].
The capital of Argentina is [[c2::Buenos Aires]].

Zero Clozes

Another way to have active clozes is by using zero clozes. The counting for tag indices starts at 1. If you provide a 0 instead, it signals that this cloze is always supposed to be active.

This way you can use clozes even outside of Note Types which are specifically set up to work with clozes.

/** Default cloze */
filterManager.install(
  closet.recipes.cloze.show({ tagname: 'c' }),
  closet.recipes.cloze.hide({ tagname: 'ch' }),
  closet.recipes.cloze.reveal({ tagname: 'cr' }),
)
The capital of Botswana is [[c0::Gaborone]].
# contrast this with the behavior of unnumbered clozes:
The capital of Argentina is [[c::Buenos Aires]].

Showing, Hiding, and Revealing Clozes

In the above examples non-current clozes simply displayed their content. These are called showing clozes.

To avoid interference, you might want to hide the content, or only hide the content on the front and show on the back. For the first case, you’d use hiding clozes, for the second case you’d use revealing clozes.

/** Default cloze */
filterManager.install(
  closet.recipes.cloze.show({ tagname: 'c' }),
  closet.recipes.cloze.hide({ tagname: 'ch' }),
  closet.recipes.cloze.reveal({ tagname: 'cr' }),
)
Catecholamines: [[c1::dopamine, noradrenaline, adrenaline]]
Indolamines: [[ch2::serotonin]]
Imidazoles: [[cr3::histamin]]

In this example you can see how each cloze type acts differently.

You can also this cloze subtypes to generally hide undesirable context on flash cards.

/** Default cloze */
filterManager.install(
  closet.recipes.cloze.show({ tagname: 'c' }),
  closet.recipes.cloze.hide({ tagname: 'ch' }),
  closet.recipes.cloze.reveal({ tagname: 'cr' }),
)
The DNA forms a structure called a [[c0::double helix]].

[[cr::In molecular biology, the term "double helix" refers to the structure formed by double-stranded molecules of nucleic acids such as DNA.
The double helical structure of a nucleic acid complex arises as a consequence of its secondary structure, and is a fundamental component in determining its tertiary structure.]]

Hints

Rather than showing the ellipsis symbol, you can also provide a hint instead. This hint is provided as the second parameter in the tag.

/** Default cloze */
filterManager.install(
  closet.recipes.cloze.show({ tagname: 'c' }),
  closet.recipes.cloze.hide({ tagname: 'ch' }),
  closet.recipes.cloze.reveal({ tagname: 'cr' }),
)
Catecholamines: [[c1::dopamine, noradrenaline, adrenaline::three of them]]
Indolamines: [[ch2::serotonin::starts with s]]
Imidazoles: [[cr3::histamin::h...]]

This is only one of the possible behaviors of how cards can act in the test context. For more examples, see the next chapter.