Skip to content

Instantly share code, notes, and snippets.

@fomightez
Created November 26, 2024 16:53
Show Gist options
  • Save fomightez/48a6b7f76c7734527a058087a06d8658 to your computer and use it in GitHub Desktop.
Save fomightez/48a6b7f76c7734527a058087a06d8658 to your computer and use it in GitHub Desktop.
MathJax / Latex label test for reply to SO https://stackoverflow.com/q/79226400/8508004
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "b5b95dca-3022-4f7d-85f9-ddac80e65aa6",
"metadata": {},
"source": [
"### FOR SO reply\n",
"\n",
"see https://stackoverflow.com/q/79226400/8508004\n",
"\n",
"additional resources:\n",
"- https://github.com/jupyter-widgets/ipywidgets/issues/3291\n",
"- https://stackoverflow.com/a/23856968/8508004"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "c8babe63-812e-4e5c-b122-453fc7913641",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "53cca21f449945bcbaadabc671756d01",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"IntSlider(value=0, max=1)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e6ced31417554f538d1504cf480f3d8c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Label(value='$\\\\alpha$')"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"slider = widgets.IntSlider(min=0, max=1)\n",
"test = widgets.Label('test')\n",
"test.value= \"$\\\\alpha$\"\n",
"display(slider, test)\n",
"def on_value_change(change):\n",
" if (slider.value == 0):\n",
" test.value = '$\\\\alpha$'\n",
" else:\n",
" test.value = '$\\\\beta$'\n",
"\n",
"slider.observe(on_value_change, names='value')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "74bf5c9b-8768-458e-8c1e-ba17b913ad8e",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "fe568f47b64a44e4a0baa92c430e7ba9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"IntSlider(value=0, max=1)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5dc82f15a57a44a1ba879ed876fa643a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Label(value='$\\\\alpha$')"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"slider = widgets.IntSlider(min=0, max=1)\n",
"test = widgets.Label('test')\n",
"test.value= r\"$\\alpha$\"\n",
"display(slider, test)\n",
"def on_value_change(change):\n",
" if (slider.value == 0):\n",
" test.value = r'$\\alpha$'\n",
" else:\n",
" test.value = r'$\\beta$'\n",
"\n",
"slider.observe(on_value_change, names='value')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a4669610-32e6-4afd-832a-bd540c047577",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment