Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 42 additions & 27 deletions docs/examples/latex/latex_to_word.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,59 @@
},
{
"cell_type": "markdown",
"id": "c056bb81",
"id": "5f5259f8",
"metadata": {},
"source": [
"Example 2 shows how to convert multiple LaTeX lines, each containing either text or a formula, into a Word document. Each entry in the list will appear on a separate line in the output."
"Example 1b demonstrates the same LaTeX-to-Word conversion as Example 1, but also shows how to use the `TranslateLatex` module to translate the LaTeX text before converting it to Word. This is useful if you want to localize the text in your formulas before document generation."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "81ab7a39",
"execution_count": 5,
"id": "705119d0",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Word document created: example_2_latex_to_word.docx\n"
"Translated LaTeX: \n",
" \\text{Met formule 6.83:} \\newline E = mc^2 = 5,3 \\cdot 299792458^{2} J\n",
"Word document created: example_1b_latex_to_word_translated.docx\n"
]
}
],
"source": [
"from blueprints.language.translate import TranslateLatex\n",
"\n",
"# Use the same LaTeX as Example 1\n",
"example_latex = r\"\\text{With formula 6.83:} \\newline E = mc^2 = 5.3 \\cdot 299792458^{2} J\"\n",
"\n",
"# Translate the LaTeX text to Dutch (or any supported language)\n",
"translated_latex = str(TranslateLatex(example_latex, dest_language=\"nl\"))\n",
"\n",
"print(\"Translated LaTeX: \\n\", translated_latex)\n",
"\n",
"# Now convert the translated LaTeX to Word\n",
"doc_translated = LatexToWordConverter().convert_to_word(translated_latex)\n",
"doc_translated.save(\"example_1b_latex_to_word_translated.docx\")\n",
"print(\"Word document created: example_1b_latex_to_word_translated.docx\")"
]
},
{
"cell_type": "markdown",
"id": "c056bb81",
"metadata": {},
"source": [
"Example 2 shows how to convert multiple LaTeX lines, each containing either text or a formula, into a Word document. Each entry in the list will appear on a separate line in the output."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "81ab7a39",
"metadata": {},
"outputs": [],
"source": [
"example_formulas = [\n",
" r\"\\text{Einstein's mass-energy equivalence:} \\newline E = mc^2\",\n",
Expand Down Expand Up @@ -113,19 +146,10 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "1ffca25a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CHECK \\to \\left( \\frac{N_{Ed}}{N_{t,Rd}} \\leq 1 \\right) \\to \\left( \\frac{123.0}{683.0} \\leq 1 \\right) \\to OK\n",
"Word document created: example_3_formula_6_5.docx\n"
]
}
],
"outputs": [],
"source": [
"from blueprints.codes.eurocode.en_1993_1_1_2005.chapter_6_ultimate_limit_state.formula_6_5 import Form6Dot5UnityCheckTensileStrength\n",
"\n",
Expand All @@ -148,19 +172,10 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "6167260b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\text{Nominal concrete cover according to art. 4.4.1 from EN 1992-1-1:2004:}\\newline \\text{max(Nominal concrete cover according to art. 4.4.1 } (c_{nom}) \\text{, Minimum cover with regard to casting surface according to art. 4.4.1.3 (4) ) } \\newline= \\max \\left\\{42.0; 60.0\\right\\} = 60.0 mm\\newline \\newline \\text{Where:}\\newline c_{nom} = c_{min,total}+\\Delta c_{dev} = 32.0+10 = 42.0 mm\\newline \\Delta c_{dev} \\text{ is determined according to art. 4.4.1.3 (1)}\\newline c_{min,total} = c_{min} + \\Delta c_{uneven surface} + \\Delta c_{abrasion class} = 32.0 + 0 + 0 = 32.0 mm\\newline \\Delta c_{uneven surface} \\text{ and } \\Delta c_{abrasion class} \\text{ are determined according to art. 4.4.1.2 (11) and (13)}\\newline c_{min} = \\max \\left\\{c_{min,b}; c_{min,dur}+\\Delta c_{dur,\\gamma}-\\Delta c_{dur,st}-\\Delta c_{dur,add}; 10 \\ mm\\right\\} \\newline = \\max \\left\\{32.0; 20.0+10-0-0; 10\\right\\} = 32.0 mm\\newline \\Delta c_{dur,\\gamma} , \\Delta c_{dur,st} \\text{ and } \\Delta c_{dur,add} \\text{ are determined according to art. 4.4.1.2 (6), (7) and (8)}\\newline c_{min,b} \\text{ is determined according to table 4.2 based on (equivalent) rebar diameter} = 32 = 32 mm\\newline c_{min,dur} \\text{ is determined according to table 4.4 based on structural class S5 & exposure classes (XC1)} = 20 mm\\newline \\text{Minimum cover with regard to casting surface according to art. 4.4.1.3 (4) = }k1 \\ge c_{min,dur} + 40 mm for Prepared ground (including blinding)\\newline \n",
"Word document created: example_4_nominal_concrete_cover.docx\n"
]
}
],
"outputs": [],
"source": [
"from blueprints.checks.nominal_concrete_cover.nominal_concrete_cover import NominalConcreteCover\n",
"from blueprints.codes.eurocode.en_1992_1_1_2004.chapter_4_durability_and_cover.constants import (\n",
Expand Down