Skip to content

Instantly share code, notes, and snippets.

@agoose77
Created September 28, 2025 16:32
Show Gist options
  • Save agoose77/cb382d2e4ff6a1a153d3066780590dfb to your computer and use it in GitHub Desktop.
Save agoose77/cb382d2e4ff6a1a153d3066780590dfb to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "92d51256-d7f0-46ba-b758-99637ffc5e7e",
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import Latex"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "2fe24c13-67c3-4df3-93f4-9ba305a5f20f",
"metadata": {},
"outputs": [],
"source": [
"import re\n",
"\n",
"def display_globals():\n",
" for key, value in dict(globals()).items():\n",
" if match:= re.match(r\"(\\w+)_(\\w)_(\\w)\", key):\n",
" name, sup, sub = match.groups()\n",
" display(Latex(rf\"${name}^{sup}_{sub} = {value}$\"))"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "691cabf0-bf65-4148-a990-40e19e3f1b46",
"metadata": {},
"outputs": [],
"source": [
"x_a_T = 12"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f69601d7-4112-4faa-9bbd-18b34e5dbacd",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$x^a_T = 12$"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display_globals()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "95c19c9c-6bc6-4a6c-bfdb-24855777b273",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"12"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x_a_T"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
@agoose77
Copy link
Author

A starting point for naming-convention driven rich maths formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment