Skip to content

Commit 7501b3a

Browse files
refactor(python): streamline LaTeX notebook content
1 parent 453490d commit 7501b3a

File tree

1 file changed

+26
-42
lines changed

1 file changed

+26
-42
lines changed

python_utilities/python_code_to_latex_jupyter_notebooks.ipynb

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,6 @@
6868
"cell_type": "markdown",
6969
"id": "5",
7070
"metadata": {},
71-
"source": [
72-
"This shows step-by-step substitutions. But writing LaTeX for each step is manual and slow. Wouldn't it be nice if we could have steps and substitutions and latex code automatically generated when writing Python code?\n",
73-
"\n",
74-
"That is where handcalcs comes in."
75-
]
76-
},
77-
{
78-
"cell_type": "markdown",
79-
"id": "6",
80-
"metadata": {},
8171
"source": [
8272
"## handcalcs: Step-by-Step Calculations\n",
8373
"\n",
@@ -91,7 +81,7 @@
9181
{
9282
"cell_type": "code",
9383
"execution_count": null,
94-
"id": "7",
84+
"id": "6",
9585
"metadata": {},
9686
"outputs": [],
9787
"source": [
@@ -104,7 +94,7 @@
10494
},
10595
{
10696
"cell_type": "markdown",
107-
"id": "8",
97+
"id": "7",
10898
"metadata": {},
10999
"source": [
110100
"Now we can use the `%%render` magic command to render the calculation."
@@ -113,7 +103,7 @@
113103
{
114104
"cell_type": "code",
115105
"execution_count": null,
116-
"id": "9",
106+
"id": "8",
117107
"metadata": {},
118108
"outputs": [],
119109
"source": [
@@ -124,11 +114,9 @@
124114
},
125115
{
126116
"cell_type": "markdown",
127-
"id": "10",
117+
"id": "9",
128118
"metadata": {},
129119
"source": [
130-
"This renders as a complete step-by-step calculation showing all substitutions and intermediate results. All without writing a single line of LaTeX code!\n",
131-
"\n",
132120
"### Function Decorator (handcalc)\n",
133121
"\n",
134122
"Use the function decorator to render calculations. Set `jupyter_display=True` to show the LaTeX in Jupyter."
@@ -137,7 +125,7 @@
137125
{
138126
"cell_type": "code",
139127
"execution_count": null,
140-
"id": "11",
128+
"id": "10",
141129
"metadata": {},
142130
"outputs": [],
143131
"source": [
@@ -154,7 +142,7 @@
154142
},
155143
{
156144
"cell_type": "markdown",
157-
"id": "12",
145+
"id": "11",
158146
"metadata": {},
159147
"source": [
160148
"The result is a simple number that can be used for further calculations."
@@ -163,7 +151,7 @@
163151
{
164152
"cell_type": "code",
165153
"execution_count": null,
166-
"id": "13",
154+
"id": "12",
167155
"metadata": {},
168156
"outputs": [],
169157
"source": [
@@ -173,7 +161,7 @@
173161
},
174162
{
175163
"cell_type": "markdown",
176-
"id": "14",
164+
"id": "13",
177165
"metadata": {},
178166
"source": [
179167
"## latexify-py: Automated Function Conversion\n",
@@ -184,7 +172,7 @@
184172
{
185173
"cell_type": "code",
186174
"execution_count": null,
187-
"id": "15",
175+
"id": "14",
188176
"metadata": {},
189177
"outputs": [],
190178
"source": [
@@ -200,7 +188,7 @@
200188
},
201189
{
202190
"cell_type": "markdown",
203-
"id": "16",
191+
"id": "15",
204192
"metadata": {},
205193
"source": [
206194
"The latexify-py function can be used like a normal Python function to compute the result."
@@ -209,7 +197,7 @@
209197
{
210198
"cell_type": "code",
211199
"execution_count": null,
212-
"id": "17",
200+
"id": "16",
213201
"metadata": {},
214202
"outputs": [],
215203
"source": [
@@ -219,7 +207,7 @@
219207
},
220208
{
221209
"cell_type": "markdown",
222-
"id": "18",
210+
"id": "17",
223211
"metadata": {},
224212
"source": [
225213
"## SymPy: Symbolic Mathematics\n",
@@ -232,7 +220,7 @@
232220
{
233221
"cell_type": "code",
234222
"execution_count": null,
235-
"id": "19",
223+
"id": "18",
236224
"metadata": {},
237225
"outputs": [],
238226
"source": [
@@ -248,7 +236,7 @@
248236
},
249237
{
250238
"cell_type": "markdown",
251-
"id": "20",
239+
"id": "19",
252240
"metadata": {},
253241
"source": [
254242
"After setting up the equation, we are ready to perform symbolic calculations.\n",
@@ -261,7 +249,7 @@
261249
{
262250
"cell_type": "code",
263251
"execution_count": null,
264-
"id": "21",
252+
"id": "20",
265253
"metadata": {},
266254
"outputs": [],
267255
"source": [
@@ -275,7 +263,7 @@
275263
},
276264
{
277265
"cell_type": "markdown",
278-
"id": "22",
266+
"id": "21",
279267
"metadata": {},
280268
"source": [
281269
"### Solve for a Variable\n",
@@ -286,7 +274,7 @@
286274
{
287275
"cell_type": "code",
288276
"execution_count": null,
289-
"id": "23",
277+
"id": "22",
290278
"metadata": {},
291279
"outputs": [],
292280
"source": [
@@ -296,18 +284,16 @@
296284
},
297285
{
298286
"cell_type": "markdown",
299-
"id": "24",
287+
"id": "23",
300288
"metadata": {},
301289
"source": [
302-
"The result is the formula to solve for `t`.\n",
303-
"\n",
304-
"Now we can substitute the variables into the equation to answer a more specific question: \"How many years will it take for the investment to reach $5,000 given a principal of $1,000 and an annual interest rate of 8%?\""
290+
"The result is the formula to solve for `t`."
305291
]
306292
},
307293
{
308294
"cell_type": "code",
309295
"execution_count": null,
310-
"id": "25",
296+
"id": "24",
311297
"metadata": {},
312298
"outputs": [],
313299
"source": [
@@ -317,11 +303,9 @@
317303
},
318304
{
319305
"cell_type": "markdown",
320-
"id": "26",
306+
"id": "25",
321307
"metadata": {},
322308
"source": [
323-
"The result shows that it will take approximately 21 years for the investment to reach $5,000.\n",
324-
"\n",
325309
"### Expand and Factor an Expression\n",
326310
"\n",
327311
"We can also use SymPy to expand and factor an expression.\n",
@@ -332,7 +316,7 @@
332316
{
333317
"cell_type": "code",
334318
"execution_count": null,
335-
"id": "27",
319+
"id": "26",
336320
"metadata": {},
337321
"outputs": [],
338322
"source": [
@@ -342,7 +326,7 @@
342326
},
343327
{
344328
"cell_type": "markdown",
345-
"id": "28",
329+
"id": "27",
346330
"metadata": {},
347331
"source": [
348332
"Let's expand the expression using the `expand` function."
@@ -351,7 +335,7 @@
351335
{
352336
"cell_type": "code",
353337
"execution_count": null,
354-
"id": "29",
338+
"id": "28",
355339
"metadata": {},
356340
"outputs": [],
357341
"source": [
@@ -363,7 +347,7 @@
363347
},
364348
{
365349
"cell_type": "markdown",
366-
"id": "30",
350+
"id": "29",
367351
"metadata": {},
368352
"source": [
369353
"We can then turn the expression back into a product of factors using the `factor` function."
@@ -372,7 +356,7 @@
372356
{
373357
"cell_type": "code",
374358
"execution_count": null,
375-
"id": "31",
359+
"id": "30",
376360
"metadata": {},
377361
"outputs": [],
378362
"source": [

0 commit comments

Comments
 (0)