From 3c31818706163fc685e50f17fb156b8402ae0f94 Mon Sep 17 00:00:00 2001 From: ctarnold <113149895+ctarnold@users.noreply.github.com> Date: Thu, 7 Dec 2023 14:52:03 -0500 Subject: [PATCH] Add print to .tex file example to examples.ipynb (#199) * Update examples.ipynb Duplicating last block to then add a new example * Update examples.ipynb Adding example of printing to a .tex file in solve1, the duplicated solve function. * Update examples.ipynb Changing output data in notebook under solve1 to explain to user the functionality of printing to the .tex file * Update examples.ipynb Modifying print example to align with common python practice by @odashi 's recommendation. * Update examples.ipynb Fixing typo in JSON file representation of examples.ipynb * Update examples.ipynb Previous JSON file worked, fixing display of the code by removing \t from the added printing example. * Update examples.ipynb Removing plain text from output field in JSON description of the .tex output example. --- examples/examples.ipynb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/examples/examples.ipynb b/examples/examples.ipynb index dd1aaf8..86a71d7 100644 --- a/examples/examples.ipynb +++ b/examples/examples.ipynb @@ -165,6 +165,35 @@ "\n", "solve" ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "$$ \\displaystyle \\frac{-b + \\sqrt{b^{{2}} - {4}ac}}{{2}a} $$" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# We can also print the output to a .tex file\n", + "@latexify.expression\n", + "def solve1(a, b, c):\n", + " return (-b + math.sqrt(b**2 - 4*a*c)) / (2*a)\n", + "\n", + "with open('latexifyExample.tex', 'w') as fp: \n", + " print(solve1, file = fp) \n" + ] } ], "metadata": {