from fastcore.test import *
from trouver.helper.tests import _test_directorymarkdown.obsidian.personal.notation.parse
Parse notation note
For the purposes of trouver, a notation note most usually starts in the format <Notation> [[<link_to_note>|denotes]] <explanation of what that notation denotes/is defined as> <optional paragraphs discussing aspects about the notation>. For example, “\(\deg D\) [[note_link|denotes]] the degree of the divisor \(D\)” would be an example of such a note.
If the word denotes is not given in a link to a note, then the note to which the first link points is considered the main note of the notation note. Alternatively, a notation note might also sometimes have a comment citing the source of the notation instead of links. Nevertheless, it is preferred that denotes is given in a link.
A notation note may have YAML frontmatter meta as well.
test_eq(['hi'], ['hi'])parse_notation_note
parse_notation_note (notation_note:Union[str,trouver.markdown.obsidian.v ault.VaultNote], vault:Optional[os.PathLike]=None)
*Parse information from the notation note.
Returns
- tuple[Union[dict, None], str, ObsidianLink, MarkdownFile, list[tuple[str, str]]]
- The first entry is the YAML frontmatter meta, if available.
- The second entry is the notation string
- The third entry is the name of the “main note” of the notation note. This is usual the linked note in the link
[[<linked_note>|denotes]]. If no such main note exists, then this isNone. - The fourth entry is the MarkdownFile consisting of the “main” content of the note, which excludes the information given by all of the other entries.
- The fifth entry is a list of tuples of two
str’s representing a bulleted list of notation notes to whichnotation_notelinks to. Each tuple is of the form(latex_str, notation_note_name)and the corresponding entry in the bulleted list is of the form- [<latex_str>](<notation_note_name).
Raises
- UserWarning
- If the (non-YAML frontmatter meta) contents of the note do not start inn the form
<Notation> [[<link_to_note>|denotes]]; the name of the notation note is included in the warning message.
- If the (non-YAML frontmatter meta) contents of the note do not start inn the form
- ValueError
- If the notation note is not formatted correctly by starting with the notation with dollar signs
$.
- If the notation note is not formatted correctly by starting with the notation with dollar signs
- AssertionError
- If
notation_noteis not determined to be a notation note.*
- If
| Type | Default | Details | |
|---|---|---|---|
| notation_note | Union | ||
| vault | Optional | None | The vault If None, then uses notation_note.vault |
| Returns | tuple |
parse_notation_note gets information about the notation note. Note that the MarkdownFile object main_mf that has the main content/description of the notation does not start with the pharse of the form <notation> [[<link>|denotes]].
vault = _test_directory() / 'test_vault_7'
notation_note = VaultNote(vault, name='some_reference_name_notation_Spec_A')
metadata, notation_str, main_of_notation, main_mf, linked_notat_notes = parse_notation_note(notation_note, vault)
test_eq(metadata, {'detect_regex': [], 'latex_in_original': ['\\operatorname{Spec} A']})
test_eq(notation_str, '$\\operatorname{Spec} A$')
test_eq(main_of_notation, 'spectrum_of_a_ring')
test_eq(str(main_mf), 'the spectrum of the ring $A$.')
test_eq(linked_notat_notes, []) # There is not a bulleted list at the end, so the last output is `None`.vault = _test_directory() / 'test_vault_7'
notation_note = VaultNote(vault, name='poonen_curves_notation_zeta_X_s_zeta_function_of_variety')
metadata, notation_str, main_of_notation, main_mf, linked_notat_notes = parse_notation_note(notation_note, vault)
test_eq(metadata, None)
test_eq(notation_str, r'$\zeta_{X}(s)$')
test_eq(main_of_notation, 'poonen_curves_3.4.1 DEFINITION')
test_eq(str(main_mf), 'the zeta function of the [[poonen_curves_1.0.2 DEFINITION|variety]] $X$ over $\\mathbb{F}_q$.\n\nIt is defined as\n\n$$\\zeta_X(s) = Z_X(q^{-s}).$$\n\nA priori, it is a formal series, but in fact [[poonen_curves_ 3.6_page_56|it converges]] for $\\operatorname{Re} s > \\dim X$.')
test_eq(linked_notat_notes, [('$Z_X$', 'poonen_curves_notation_Z_X_T')]) # There is a bulleted list at the end, so the last output is `None`.notation_in_note
notation_in_note (notation_note:Union[str,trouver.markdown.obsidian.vaul t.VaultNote], vault:Optional[os.PathLike]=None)
*Return the name of the note from which the notation comes from.
Parameters
notation_note- Union[str, VaultNote]Either
- The name of the notation note or
- The
VaultNoteobject of the notation note.
vault. This is expected to contain'notation'as a substring. Usually, this is expected to be formatted in one of the following forms: -'<reference_name>_notation_<rest_of_note_name>'- `‘notation.’ vault- Pathlike orNone- Defaults to
None
- Defaults to
Returns
- str
- The notation in LaTeX, including the dollar signs
$.
- The notation in LaTeX, including the dollar signs
Raises*
notation_in_note identifies the notation LaTeX str that a notation note presents. Its output starts and ends with dollar signs.
vault = _test_directory() / 'test_vault_7'
notation_note = VaultNote(vault, name='some_reference_name_notation_Spec_A')
notation = notation_in_note(notation_note)
assert notation == r'$\operatorname{Spec} A$'main_of_notation
main_of_notation (notation_note:trouver.markdown.obsidian.vault.VaultNot e, as_note:bool=False)
*Return the name of the note from which the notation comes from.
Raises
- ValueError
- If the notation note is not formatted correctly by starting with the notation with dollar signs
$.*
- If the notation note is not formatted correctly by starting with the notation with dollar signs
| Type | Default | Details | |
|---|---|---|---|
| notation_note | VaultNote | The VaultNote object representing the notation note. | |
| as_note | bool | False | If False, then returns the name of the note, and returns a VaultNote object with the same vault as notation_note otherwise. The vault used to get the VaultNote is the vault of notation_note. |
| Returns | Union | The (name of the) main information note that notation_note comes from. Returns None if notation_note does not come from such a note. |
We can identify the “main note” of a notation note with the main_of_notation method:
vault = _test_directory() / 'test_vault_7'
notation_note = VaultNote(vault, name='some_reference_name_notation_Spec_A')
test_eq(main_of_notation(notation_note), 'spectrum_of_a_ring')We can also return this main note as a VaultNote object:
vault = _test_directory() / 'test_vault_7'
notation_note = VaultNote(vault, name='some_reference_name_notation_Spec_A')
main_note = main_of_notation(notation_note, as_note=True)
assert isinstance(main_note, VaultNote)
test_eq(main_note.name, 'spectrum_of_a_ring')If the notation note has no links, then main_of_notation returns None:
vault = _test_directory() / 'test_vault_7'
notation_note = VaultNote(vault, name='some_reference_name_notation_O_X_this_file_has_no_links')
main_note = main_of_notation(notation_note)
assert main_note is None
main_note = main_of_notation(notation_note, as_note=True)
assert main_note is None