Skip to content

Commit

Permalink
Change implementation of `_node_is_proof_immediately_following_a_theo…
Browse files Browse the repository at this point in the history
…rem_like_environment` and `_node_is_nonspecial_following_a_sectionlike_node` in `29_latex.divide.ipynb` to not repeatedly use `get_node_from_simple_text`, which is time consuming
  • Loading branch information
hyunjongkimmath committed May 12, 2024
1 parent 7557e9d commit 8337cfc
Show file tree
Hide file tree
Showing 30 changed files with 3,063 additions and 83 deletions.
12 changes: 6 additions & 6 deletions nbs/16_latex.convert.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@
"output_type": "stream",
"text": [
"The following are the subdirectories of `reference_folder` (relative to `temp_vault`):\n",
"['.', '.obsidian', '.obsidian\\\\plugins', '.obsidian\\\\plugins\\\\fast-link-edit', '.obsidian\\\\plugins\\\\obsidian-vimrc-support', '.obsidian\\\\plugins\\\\trouver_obs', '1_proof_of_theorem~refthmain', '1_proof_of_theorem~refthmain\\\\11_this_is_a_subsection', '1_proof_of_theorem~refthmain\\\\12_this_is_another_subsection', 'test_ref_untitled_section', '_temp']\n"
"['.', '.obsidian', '.obsidian\\\\plugins', '.obsidian\\\\plugins\\\\fast-link-edit', '.obsidian\\\\plugins\\\\obsidian-vimrc-support', '1_proof_of_theorem~refthmain', '1_proof_of_theorem~refthmain\\\\11_this_is_a_subsection', '1_proof_of_theorem~refthmain\\\\12_this_is_another_subsection', 'test_ref_untitled_section', '_temp']\n"
]
}
],
Expand Down Expand Up @@ -639,8 +639,8 @@
"#| hide\n",
"#| notest\n",
"VaultNote.clear_cache()\n",
"reference = 'bruinier_yang_fhCMcdLf'\n",
"latex_file = Path(r'C:\\Users\\hyunj\\Documents\\Math\\latex_image_data\\latex_full') / reference / 'arxiv.tex'\n",
"reference = 'voevodsky_A1'\n",
"latex_file = Path(r'C:\\Users\\hyunj\\Documents\\Math\\latex_image_data\\latex_full') / reference / 'main.tex'\n",
"\n",
"# reference = 'numbering_example_1_consecutive_numbering_scheme'\n",
"# latex_file = Path(r'C:\\Users\\hyunj\\Documents\\Development\\Python\\trouver\\nbs\\_tests\\latex_examples') / reference / 'main.tex'\n",
Expand All @@ -653,15 +653,15 @@
"\n",
"\n",
"location = Path('.') # The path relative to the vault of the directory in which to make the new folder containing the new notes.\n",
"author_names = ['Arinkin', 'Gaitsgory']\n",
"author_names = ['Voevodsky']\n",
"\n",
"setup_reference_from_latex_parts(\n",
" parts, cust_comms, vault, location,\n",
" reference,\n",
" author_names,\n",
" overwrite='w',\n",
" confirm_overwrite=True,\n",
" adjust_common_latex_syntax_to_markdown=True, # For things like adding `$$` around `\\begin{align*}...\\end{align*}`\n",
" adjust_common_latex_syntax_to_markdown=False, # For things like adding `$$` around `\\begin{align*}...\\end{align*}`\n",
" repeat_replacing_custom_commands=-1\n",
" )"
]
Expand All @@ -676,7 +676,7 @@
"output_type": "stream",
"text": [
"\n",
"Identified reference 'poonen_arec' in the vault 'c:\\Users\\hyunj\\Documents\\Development\\Python\\trouver\\nbs\\_tests\\test_vault_5' as the folder 'c:\\Users\\hyunj\\Documents\\Development\\Python\\trouver\\nbs\\_tests\\test_vault_5\\poonen_arec'...\n",
"Identified reference 'voevodsky_A1' in the vault 'c:\\Users\\hyunj\\Documents\\Development\\Python\\trouver\\nbs\\_tests\\test_vault_5' as the folder 'c:\\Users\\hyunj\\Documents\\Development\\Python\\trouver\\nbs\\_tests\\test_vault_5\\voevodsky_A1'...\n",
"Deleting...\n",
"Deleted reference.\n",
"\n"
Expand Down
138 changes: 111 additions & 27 deletions nbs/29_latex.divide.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,20 @@
" r'\\{((?>[^{}]+|\\{(?2)\\})*)\\}'\n",
" r'\\s*'\n",
" r'(\\[\\s*(\\w+)\\s*\\])?',\n",
" regex.MULTILINE)\n"
" regex.MULTILINE)\n",
"\n",
"# matches \\section{title}, \\subsection{title}, \\subsubsection{title}, \\section*{title}, etc.\n",
"SECTION_LIKE_PATTERN = regex.compile(\n",
" r'\\\\(?:section|subsection|subsubsection)\\s*(?:\\[.*\\])?(\\*)?\\s*'\n",
" r'\\{((?>[^{}]+|\\{(?2)\\})*)\\}',\n",
" regex.MULTILINE)\n",
" \n",
"\n",
"# matches \\begin{theorem},\n",
"ENVIRONMENT_PATTERN = regex.compile(\n",
" r'\\\\begin\\s*'\n",
" r'\\{((?>[^{}]+|\\{(?1)\\})*)\\}',\n",
" regex.MULTILINE)\n"
]
},
{
Expand Down Expand Up @@ -1658,12 +1671,12 @@
" # Note that the `section` command has the optional argument `toc-title` which appears\n",
" # in the table of contents, cf.\n",
" # http://latexref.xyz/_005csection.html\n",
" pattern = regex.compile(\n",
" r'\\\\(?:section|subsection|subsubsection)\\s*(?:\\[.*\\])?(\\*)?\\s*'\n",
" r'\\{((?>[^{}]+|\\{(?2)\\})*)\\}',\n",
" regex.MULTILINE\n",
" )\n",
" regex_search = regex.search(pattern, text)\n",
" # pattern = regex.compile(\n",
" # r'\\\\(?:section|subsection|subsubsection)\\s*(?:\\[.*\\])?(\\*)?\\s*'\n",
" # r'\\{((?>[^{}]+|\\{(?2)\\})*)\\}',\n",
" # regex.MULTILINE\n",
" # )\n",
" regex_search = regex.search(SECTION_LIKE_PATTERN, text)\n",
" is_numbered = regex_search.group(1) is None\n",
" title = regex_search.group(2)\n",
" return is_numbered, title\n"
Expand Down Expand Up @@ -1728,20 +1741,54 @@
"outputs": [],
"source": [
"#| export\n",
"def _is_section_node(node):\n",
"def _is_section_node(node: LatexNode):\n",
" return (node.isNodeType(LatexMacroNode)\n",
" and node.macroname == 'section')\n",
"\n",
"def _is_subsection_node(node):\n",
"def _is_subsection_node(node: LatexNode):\n",
" return (node.isNodeType(LatexMacroNode)\n",
" and node.macroname == 'subsection')\n",
"\n",
"def _is_subsubsection_node(node):\n",
"def _is_subsubsection_node(node: LatexNode):\n",
" return (node.isNodeType(LatexMacroNode)\n",
" and node.macroname == 'subsubsection')\n",
"\n",
"def _is_environment_node(node):\n",
" return node.isNodeType(LatexEnvironmentNode)"
"def _is_environment_node(node: LatexNode):\n",
" return node.isNodeType(LatexEnvironmentNode)\n",
"\n",
"def _text_is_of_section_like_node(text: str):\n",
" \"\"\"Return `True` if `text` represents the text for a section node.\n",
"\n",
" In principal, this function should act like \n",
" `_is_section_node or _is_subsection_node or _is_subsubsection_node`\n",
" except that it takes a `str` as its argument instead of a `LatexNode`.\n",
" This function is\n",
" implemented using a regex pattern instead of using\n",
" `_is_section_node` to save time.\n",
" \"\"\"\n",
" return bool(regex.match(SECTION_LIKE_PATTERN, text.lstrip()))\n",
"\n",
"\n",
"def _text_is_of_environment_node(text: str):\n",
" \"\"\"Return `True` if `text` represents an environment node\n",
" (at least at the start).\n",
" \n",
" In principal, this function should act like `_is_environment_node`\n",
" except that it takes a `str` as its argument instead of a `LatexNode`.\n",
" This function is implemented using a regex pattern instead of using\n",
" '_is_environment_node` to save time.\n",
" \"\"\"\n",
" return bool(regex.match(ENVIRONMENT_PATTERN, text.lstrip()))\n",
"\n",
"\n",
"def _environment_name_of_text(text: str):\n",
" \"\"\"Return `True` if `text` represents an environment node\n",
" (at least at the start).\n",
" \n",
" Assumes that `_text_is_of_environment_node(text)` is `True`.\n",
" \"\"\"\n",
" match = regex.match(ENVIRONMENT_PATTERN, text.lstrip())\n",
" return match.group(1)"
]
},
{
Expand Down Expand Up @@ -1790,6 +1837,45 @@
"# print(node.environmentname)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'theorem'"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#| hide\n",
"assert _text_is_of_section_like_node(r\"\\section {Generating series of special divisors}\")\n",
"assert _text_is_of_section_like_node(r\" \\section {Generating series of special divisors}\")\n",
"assert _text_is_of_section_like_node(r\"\\subsection{I am a subsection}\")\n",
"assert _text_is_of_section_like_node(r\"\\section*{I am an unnumbered section}\")\n",
"assert _text_is_of_section_like_node(r\"\\subsection* {I am an unnumbered section and I have extraneous spaces}\")\n",
"assert _text_is_of_section_like_node(r\"\"\"\\section* {I am a section and I have span \n",
" multiple lines}\"\"\")\n",
"assert _text_is_of_section_like_node(r\"\"\"\\section{ Can I talk about the finite field \\mathcal{F}_p in this title?\n",
" Can I also have multiple lines? Yes I can!}\"\"\")\n",
"assert _text_is_of_section_like_node(r\"\"\"\\subsubsection{Hi}\"\"\")\n",
"\n",
"assert not _text_is_of_section_like_node(r\"\"\"Something something\"\"\")\n",
"assert not _text_is_of_section_like_node(r\"\"\"\\begin{theorem}\"\"\")\n",
"assert not _text_is_of_section_like_node(r\"hi \\section{title}\")\n",
"\n",
"assert _text_is_of_environment_node(r\"\"\"\\begin{theorem} blah blah blah\"\"\")\n",
"assert _text_is_of_environment_node(r\"\"\"\\begin{theorem} blah blah blah \\end{theorem}\"\"\")\n",
"assert not _text_is_of_environment_node(r\"\"\"hi\"\"\")\n",
"_environment_name_of_text(r\"\"\"\\begin{theorem} blah blah blah\"\"\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -2759,10 +2845,13 @@
" return False\n",
" if accumulation.strip() != '':\n",
" return False\n",
" previous_node = get_node_from_simple_text(parts[-1][1])\n",
" if not _is_environment_node(previous_node):\n",
" if not _text_is_of_environment_node(parts[-1][1]):\n",
" return False\n",
" return previous_node.environmentname in display_names\n",
" return _environment_name_of_text(parts[-1][1]) in display_names\n",
" # previous_node = get_node_from_simple_text(parts[-1][1])\n",
" # if not _is_environment_node(previous_node):\n",
" # return False\n",
" # return previous_node.environmentname in display_names\n",
"\n",
"\n",
"def _node_is_nonspecial_following_a_sectionlike_node(\n",
Expand All @@ -2773,18 +2862,18 @@
" \n",
" This is a helper function for `_process_node`.\n",
" \"\"\"\n",
" # TODO: write tests\n",
" if ((_is_environment_node(node) and node.environmentname not in environments_to_not_divide_along)\n",
" or _is_section_node(node)\n",
" or _is_subsection_node(node)\n",
" or _is_subsubsection_node(node)):\n",
" return False\n",
" if not len(parts) > 0:\n",
" if len(parts) == 0:\n",
" return False\n",
" if accumulation.strip() != '':\n",
" return False\n",
" previous_node = get_node_from_simple_text(parts[-1][1])\n",
" return _is_section_node(previous_node) or _is_subsection_node(previous_node) or _is_subsubsection_node(previous_node)\n",
" # previous_node = get_node_from_simple_text(parts[-1][1])\n",
" # return _is_section_node(previous_node) or _is_subsection_node(previous_node) or _is_subsubsection_node(previous_node)\n",
" return _text_is_of_section_like_node(parts[-1][1])\n",
" "
]
},
Expand Down Expand Up @@ -2878,7 +2967,7 @@
"DEFAULT_ENVIRONMENTS_TO_NOT_DIVIDE_ALONG = [\n",
" 'align', 'align*', 'diagram', 'displaymath', 'displaymath*', 'enumerate', 'eqnarray', 'eqnarray*',\n",
" 'equation', 'equation*', 'gather', 'gather*', 'itemize', 'label',\n",
" 'multiline', 'multiline*',\n",
" 'multiline', 'multiline*', 'multline', 'multline*',\n",
" 'proof', 'quote', 'tabular', 'table', ]\n",
"def divide_latex_text(\n",
" document: str, \n",
Expand Down Expand Up @@ -3334,6 +3423,8 @@
" 'label',\n",
" 'multiline',\n",
" 'multiline*',\n",
" 'multline',\n",
" 'multline*',\n",
" 'proof',\n",
" 'quote',\n",
" 'tabular',\n",
Expand Down Expand Up @@ -4181,13 +4272,6 @@
"print(parts)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
37 changes: 18 additions & 19 deletions nbs/_tests/test_vault_5/.obsidian/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"type": "split",
"children": [
{
"id": "38ee778b7f30a004",
"id": "abee6198b82f053c",
"type": "tabs",
"children": [
{
"id": "71dfae262b9a2adb",
"id": "ff13bff50f381407",
"type": "leaf",
"state": {
"type": "empty",
Expand Down Expand Up @@ -69,8 +69,7 @@
"state": {}
}
}
],
"currentTab": 1
]
}
],
"direction": "horizontal",
Expand Down Expand Up @@ -147,8 +146,21 @@
"command-palette:Open command palette": false
}
},
"active": "71dfae262b9a2adb",
"active": "ff13bff50f381407",
"lastOpenFiles": [
"voevodsky_A1/_temp/_index_temp_voevodsky_A1.md",
"voevodsky_A1/_temp",
"voevodsky_A1/_glossary_voevodsky_A1.md",
"voevodsky_A1/_notation_voevodsky_A1.md",
"voevodsky_A1/_template_voevodsky_A1_2.md",
"_templates/U-Z/V/_template_voevodsky_A1.md",
"_references/U-Z/V/_reference_voevodsky_A1.md",
"voevodsky_A1/voevodsky_a1_untitled_section/_index_voevodsky_a1_untitled_section.md",
"voevodsky_A1/_index_voevodsky_A1.md",
"voevodsky_A1/voevodsky_a1_untitled_section",
"voevodsky_A1",
"voevodsky_A1/voevodsky_a1_untitled_section/voevodsky_A1_abstract.md",
"_index.md",
"bruinier_yang_fhCMcdLf/_index_bruinier_yang_fhCMcdLf.md",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/_index_7_height_pairings_on_modular_curves.md",
"bruinier_yang_fhCMcdLf/8_the_case_n2/83_integral_model/bruinier_yang_fhCMcdLf_Theorem 8.2.md",
Expand All @@ -168,22 +180,9 @@
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/74_pull_back_of_heegner_divisors/bruinier_yang_fhCMcdLf_Theorem 7.20.md",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/74_pull_back_of_heegner_divisors/bruinier_yang_fhCMcdLf_Proposition 7.23.md",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/74_pull_back_of_heegner_divisors/bruinier_yang_fhCMcdLf_Lemma 7.24.md",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/74_pull_back_of_heegner_divisors/bruinier_yang_fhCMcdLf_Lemma 7.21.md",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/74_pull_back_of_heegner_divisors/bruinier_yang_fhCMcdLf_comment_50.md",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/74_pull_back_of_heegner_divisors/bruinier_yang_fhCMcdLf_comment_49.md",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/74_pull_back_of_heegner_divisors/bruinier_yang_fhCMcdLf_comment_48.md",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/74_pull_back_of_heegner_divisors/bruinier_yang_fhCMcdLf_7.4. Pull-back of Heegner divisors.md",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/74_pull_back_of_heegner_divisors/bruinier_yang_fhCMcdLf_64.md",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/74_pull_back_of_heegner_divisors/bruinier_yang_fhCMcdLf_63.md",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/74_pull_back_of_heegner_divisors/bruinier_yang_fhCMcdLf_62.md",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/74_pull_back_of_heegner_divisors/bruinier_yang_fhCMcdLf_61.md",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/74_pull_back_of_heegner_divisors/bruinier_yang_fhCMcdLf_60.md",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/74_pull_back_of_heegner_divisors",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/73_the_gross_zagier_formula",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/72_the_shimura_lifting_and_hecke_eigenforms",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/71_the_modular_curve_x_0n",
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves",
"bruinier_yang_fhCMcdLf/6_the_n0_case",
"bruinier_yang_fhCMcdLf/5_faltings_heights_of_cm_cycles"
"bruinier_yang_fhCMcdLf/7_height_pairings_on_modular_curves/71_the_modular_curve_x_0n"
]
}
Empty file.
16 changes: 16 additions & 0 deletions nbs/_tests/test_vault_5/_templates/U-Z/V/_template_voevodsky_A1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
cssclass: clean-embeds
aliases: []
tags: [_reference/voevodsky_A1, _meta/literature_note]
---
# Topic[^1]

# See Also

# Meta
## References
![[_reference_voevodsky_A1]]


## Citations and Footnotes
[^1]: Voevodsky,
5 changes: 5 additions & 0 deletions nbs/_tests/test_vault_5/voevodsky_A1/.obsidian/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"vimMode": true,
"showLineNumber": true,
"livePreview": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"accentColor": "",
"theme": "obsidian"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"trouver-obs",
"obsidian-vimrc-support"
]
Loading

0 comments on commit 8337cfc

Please sign in to comment.