{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ccc41aa0",
   "metadata": {},
   "source": [
    "(glue/main)=\n",
    "\n",
    "# Saving variables to embed (glue)\n",
    "\n",
    "The `glue` submodule allows you to store variables in the notebooks outputs, by keys,\n",
    "then reference those keys to embed the outputs inline of your text content.[^download]\n",
    "\n",
    "[^download]: This notebook can be downloaded as **{nb-download}`glue.ipynb`** and {download}`glue.md`\n",
    "\n",
    ":::{versionchanged} 0.14.0\n",
    "The `glue` roles and directives now only identify keys in the same notebook, by default.\n",
    "To glue keys from other notebooks, see {ref}`glue/crossdoc`.\n",
    ":::"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "448365fa",
   "metadata": {},
   "source": [
    "(glue/gluing)=\n",
    "\n",
    "## Save variables in code cells\n",
    "\n",
    "You can use `myst_nb.glue()` to assign the output of a variable to a key of your choice.\n",
    "`glue` will store all of the information that is normally used to display that variable (ie, whatever happens when you display the variable by putting it at the end of a cell).\n",
    "Choose a key that you will remember, as you will use it later.\n",
    "\n",
    "The following code glues a variable inside the notebook:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4b07d837",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'my variable!'"
      ]
     },
     "metadata": {
      "scrapbook": {
       "mime_prefix": "",
       "name": "my_variable"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from myst_nb import glue\n",
    "a = \"my variable!\"\n",
    "glue(\"my_variable\", a)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0f6571ae",
   "metadata": {},
   "source": [
    "You can then insert it into your text like so: {glue}`my_variable`.\n",
    "\n",
    "That was accomplished with the following code: `` {glue}`my_variable` ``.\n",
    "\n",
    "### Saving different variable types\n",
    "\n",
    "You can glue anything in your notebook and display it later with `{glue}`.\n",
    "Here we'll show how to glue and paste **numbers and images**.\n",
    "We'll simulate some data and run a simple bootstrap on it.\n",
    "We'll hide most of this process below, to focus on the glueing part."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "52b4b3c4",
   "metadata": {
    "tags": [
     "hide-cell"
    ]
   },
   "outputs": [],
   "source": [
    "# Simulate some data and bootstrap the mean of the data\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "n_points = 10000\n",
    "n_boots = 1000\n",
    "mean, sd = (3, .2)\n",
    "data = sd*np.random.randn(n_points) + mean\n",
    "bootstrap_indices = np.random.randint(0, n_points, n_points*n_boots).reshape((n_boots, n_points))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1e2fcee6",
   "metadata": {},
   "source": [
    "In the cell below, `data` contains our data, and `bootstrap_indices` is a collection of sample indices in each bootstrap.\n",
    "Below we'll calculate a few statistics of interest, and `glue()` them into the notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a68a726e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.9993212063402397"
      ]
     },
     "metadata": {
      "scrapbook": {
       "mime_prefix": "",
       "name": "boot_mean"
      }
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "2.9868794316852276"
      ]
     },
     "metadata": {
      "scrapbook": {
       "mime_prefix": "",
       "name": "boot_clo"
      }
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3.0116286876911933"
      ]
     },
     "metadata": {
      "scrapbook": {
       "mime_prefix": "",
       "name": "boot_chi"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Calculate the mean of a bunch of random samples\n",
    "means = data[bootstrap_indices].mean(0)\n",
    "# Calcualte the 95% confidence interval for the mean\n",
    "clo, chi = np.percentile(means, [2.5, 97.5])\n",
    "\n",
    "# Store the values in our notebook\n",
    "glue(\"boot_mean\", means.mean())\n",
    "glue(\"boot_clo\", clo)\n",
    "glue(\"boot_chi\", chi)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "047c9b95",
   "metadata": {},
   "source": [
    "By default, `glue` will display the value of the variable you are gluing.\n",
    "This is useful for sanity-checking its value at glue-time.\n",
    "If you'd like to **prevent display**, use the `display=False` option.\n",
    "Note that below, we also *overwrite* the value of `boot_chi` (but using the same value):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "251eff69",
   "metadata": {},
   "outputs": [],
   "source": [
    "glue(\"boot_chi_notdisplayed\", chi, display=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b865eb45",
   "metadata": {},
   "source": [
    "You can also glue visualizations, such as matplotlib figures (here we use `display=False` to ensure that the figure isn't plotted twice):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0eb0ab9f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAEICAYAAACzliQjAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAAsTAAALEwEAmpwYAAAcg0lEQVR4nO3debQcZZ3/8fdHYFgESYCIQAJBjWj0NwYnso3jRAOyT3RkBD1AcPQXZHHAwSUwKMgmMyJwHBWJY4ZNBAQ8BogiASI6IBAwLCFGMmFJYoCwyKr+BL+/P57nSnG76251b1eH+rzOqdPVT1VXfav6e7/99FOVjiICMzNrhtfUHYCZmXWOi76ZWYO46JuZNYiLvplZg7jom5k1iIu+mVmDuOjbGkdSSHpznv+2pC8O03a3lvScpLXy8/mSPjkc287b+7Gk6cO1vZEgaYqkFXXHYSPHRX8NIelBSb/PRekpSddIGjcM2x2fi+jaA1z/LwW3G0TEpyLi5P7Wy+dv13629XBEbBgRL1WNS9KJki7qtf09I+L8qtuuk6RdJN0m6VlJd0t6T2HZFEl/zjnaM00vLD875+4tksYW2j8m6esD2PcOkuZK+p2kJ3McHy/s2x9WA+Civ2bZNyI2BLYAHgX+s+Z4Wgz0w6PbrKlxd5KkTYCrgK8Co4D/AK6S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A+2HYrXMJrG5+KVqp4PSW8n/c0cOth9u+hXJGkdUpH7XkRc2Xt5RDwTER/Pb/DBwBhgGbAr8EBErI6IPwFXArt0LvLhV+FcEBHfjYi/iYj3Ak+Rrgm8KkTE74AbgT16LfrLz5LkIb6NgSd4Ff9cyRDOxavaUM6HpLHAD4GDI+J/B7tPF/0K8vjrd4HFEXFmyTqj8k9OAHwSuCn3gB8GdpK0Qd7OVNI4+Bqp4rlA0uvz49akIaCLRz7qkSNpjKRReX59YDfg171WmwNMz/P7ATdEukI3Bzgg38GxLTABuK0jgY+AiufiVafK+civuwaYGRH/M6QA6rqC/WqYSHcVBHA3aUhiIWk8+lPAp/I6O5N6rUtIvfnRhdd/Ob/Z9wIXAuvWfUw1noufk/5fhbuAqXUfzzCcj78mDV/dnd/fL+X2k4B/yPPrAT8gXai9DXhj4fX/RrprZwmwZ93HU/O5eBB4EniOdH1jYqePoVvOB3A88Hzhb2wh8PrB7N8/w2Bm1iAe3jEzaxAXfTOzBnHRNzNrEBd9M7MGcdE3M2sQF30zswZx0Tcza5D/D2NRBIHHQttBAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAV0AAAB7CAYAAADXClMoAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKgUlEQVR4nO3daYydVR3H8e8pa9nKVpAudqZALQVEVqGRJTEKL1BRISQCbnF7qTEx8ZX6Ct4ZE2L0jQajYjAaEiBBSBSXsLWsLQXaQgvdWNtSWtpCy/HF/948z5QZmLlzzzP3zv1+kpN75pk7zzlJm1/Oc57nOSflnJEkNWPGVHdAkgaJoStJDTJ0JalBhq4kNcjQlaQGGbqS1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JWkBhm6ktSgJkJ3T6E2JKnvdH/Bm1jsZn/tyAxfA5akUGKke3itvsfAlaRKidB1akGSxlA6dL2JJkk1Bxc45zbgOiJ89xU4vyT1rXK7AUuSPqDkHmmSpAMYupLUIENXkhpk6EpSgwxdSWqQoStJDTJ0JalBhq4kNcjQlaQG/R8h5I5EOxaCLwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x144 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Visualize the historgram with the intervals\n",
    "fig, ax = plt.subplots()\n",
    "ax.hist(means)\n",
    "for ln in [clo, chi]:\n",
    "    ax.axvline(ln, ls='--', c='r')\n",
    "ax.set_title(\"Bootstrap distribution and 95% CI\")\n",
    "\n",
    "# And a wider figure to show a timeseries\n",
    "fig2, ax = plt.subplots(figsize=(6, 2))\n",
    "ax.plot(np.sort(means), lw=3, c='r')\n",
    "ax.set_axis_off()\n",
    "\n",
    "glue(\"boot_fig\", fig, display=False)\n",
    "glue(\"sorted_means_fig\", fig2, display=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e37ec07f",
   "metadata": {},
   "source": [
    "The same can be done for DataFrames (or other table-like objects) as well."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "362fb21a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>first</th>\n",
       "      <th>second</th>\n",
       "      <th>third</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3.065406</td>\n",
       "      <td>3.240605</td>\n",
       "      <td>3.177796</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3.215878</td>\n",
       "      <td>3.111188</td>\n",
       "      <td>2.947871</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2.808455</td>\n",
       "      <td>3.456495</td>\n",
       "      <td>3.179014</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3.304537</td>\n",
       "      <td>2.768594</td>\n",
       "      <td>3.156621</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3.052652</td>\n",
       "      <td>3.033242</td>\n",
       "      <td>3.178106</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      first    second     third\n",
       "0  3.065406  3.240605  3.177796\n",
       "1  3.215878  3.111188  2.947871\n",
       "2  2.808455  3.456495  3.179014\n",
       "3  3.304537  2.768594  3.156621\n",
       "4  3.052652  3.033242  3.178106"
      ]
     },
     "metadata": {
      "scrapbook": {
       "mime_prefix": "",
       "name": "df_tbl"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "bootstrap_subsets = data[bootstrap_indices][:3, :5].T\n",
    "df = pd.DataFrame(bootstrap_subsets, columns=[\"first\", \"second\", \"third\"])\n",
    "glue(\"df_tbl\", df)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a47270a",
   "metadata": {},
   "source": [
    "```{tip}\n",
    "Since we are going to paste this figure into our document at a later point,\n",
    "you may wish to remove the output here, using the `remove-output` tag\n",
    "(see {ref}`use/removing`).\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac3e972a",
   "metadata": {},
   "source": [
    "(glue/pasting)=\n",
    "\n",
    "## Embedding variables in the page\n",
    "\n",
    "Once you have glued variables into a notebook, you can then **paste**\n",
    "those variables into your text in your book anywhere you like (even on other pages).\n",
    "These variables can be pasted using one of the roles or directives in the `glue:` *family*."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1167e479",
   "metadata": {},
   "source": [
    "### The `glue` role/directive\n",
    "\n",
    "The simplest role and directive are `glue` (a.k.a. `glue:any`),\n",
    "which paste the glued output inline or as a block respectively,\n",
    "with no additional formatting.\n",
    "Simply add:\n",
    "\n",
    "````\n",
    "```{glue} your-key\n",
    "```\n",
    "````\n",
    "\n",
    "For example, we'll paste the plot we generated above with the following text:\n",
    "\n",
    "````md\n",
    "```{glue} boot_fig\n",
    "```\n",
    "````\n",
    "\n",
    "Here's how it looks:\n",
    "\n",
    "```{glue} boot_fig\n",
    "```\n",
    "\n",
    "Or we can paste inline objects like so:\n",
    "\n",
    "```md\n",
    "Inline text; {glue}`boot_mean`, and figure; {glue}`boot_fig`.\n",
    "```\n",
    "\n",
    "Inline text; {glue}`boot_mean`, and figure; {glue}`boot_fig`.\n",
    "\n",
    "```{tip}\n",
    "We recommend using wider, shorter figures when plotting in-line, with a ratio\n",
    "around 6x2. For example, here's is an in-line figure of sorted means\n",
    "from our bootstrap: {glue}`sorted_means_fig`.\n",
    "It can be used to make a visual point that isn't too complex! For more\n",
    "ideas, check out [how sparklines are used](https://en.wikipedia.org/wiki/Sparkline).\n",
    "```\n",
    "\n",
    "Next we'll cover some more specific pasting functionality, which gives you more\n",
    "control over how the outputs look in your pages."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8bacaa34",
   "metadata": {},
   "source": [
    "## Controlling the output format\n",
    "\n",
    "You can control the pasted outputs by using a sub-command of `{glue}`.\n",
    "These are called like so: `` {glue:subcommand}`key` ``.\n",
    "These subcommands allow you to control more of the look, feel, and content of the pasted output.\n",
    "\n",
    "```{tip}\n",
    "When you use `{glue}` you are actually using a short-hand for `{glue:any}`. This is a\n",
    "generic command that doesn't make many assumptions about what you are gluing.\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cc230148",
   "metadata": {},
   "source": [
    "### The `glue:text` role\n",
    "\n",
    "The `glue:text` role, is specific to `text/plain` outputs.\n",
    "For example, the following text:\n",
    "\n",
    "```md\n",
    "The mean of the bootstrapped distribution was {glue:text}`boot_mean` (95% confidence interval {glue:text}`boot_clo`/{glue:text}`boot_chi`).\n",
    "```\n",
    "\n",
    "Is rendered as:\n",
    "\n",
    "The mean of the bootstrapped distribution was {glue:text}`boot_mean` (95% confidence interval {glue:text}`boot_clo`/{glue:text}`boot_chi`)\n",
    "\n",
    "```{note}\n",
    "`glue:text` only works with glued variables that contain a `text/plain` output.\n",
    "```\n",
    "\n",
    "With `glue:text` we can add formatting to the output, by specifying a format spec string after a `:`: `` {glue:text}`mykey:<format_spec>` ``\n",
    "\n",
    "The `<format_spec>` should be a valid [Python format specifier](https://docs.python.org/3/library/string.html#format-specification-mini-language).\n",
    "\n",
    "This is particularly useful if you are displaying numbers and want to round the results.\n",
    "For example, the following: ``My rounded mean: {glue:text}`boot_mean:.2f` `` will be rendered like this:\n",
    "\n",
    "My rounded mean: {glue:text}`boot_mean:.2f` (95% CI: {glue:text}`boot_clo:.2f`/{glue:text}`boot_chi:.2f`)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "856ee412",
   "metadata": {},
   "source": [
    "### The `glue:figure` directive\n",
    "\n",
    "With `glue:figure` you can apply more formatting to figure like objects,\n",
    "such as giving them a caption and referenceable label:\n",
    "\n",
    ":::{table} `glue:figure` directive options\n",
    "| Option | Type | Description |\n",
    "| ------ | ---- | ----------- |\n",
    "| alt | text | Alternate text of an image |\n",
    "| height | length | The desired height of an image |\n",
    "| width | length or percentage | The width of an image |\n",
    "| scale | percentage | The uniform scaling factor of an image |\n",
    "| class | text | A space-separated list of class names for the image |\n",
    "| figwidth | length or percentage | The width of the figure |\n",
    "| figclass | text | A space-separated list of class names for the figure |\n",
    "| align | text | left, center, or right |\n",
    "| name | text | referenceable label for the figure |\n",
    ":::\n",
    "\n",
    "````md\n",
    "```{glue:figure} boot_fig\n",
    ":alt: \"Alternative title\"\n",
    ":figwidth: 300px\n",
    ":name: \"fig-boot\"\n",
    "\n",
    "This is a **caption**, with an embedded `{glue:text}` element: {glue:text}`boot_mean:.2f`!\n",
    "```\n",
    "````\n",
    "\n",
    "```{glue:figure} boot_fig\n",
    ":alt: \"Alternative title\"\n",
    ":figwidth: 300px\n",
    ":name: \"fig-boot\"\n",
    "\n",
    "This is a **caption**, with an embedded `{glue:text}` element: {glue:text}`boot_mean:.2f`!\n",
    "```\n",
    "\n",
    "```md\n",
    "Here is a {ref}`reference to the figure <fig-boot>`\n",
    "```\n",
    "\n",
    "Here is a {ref}`reference to the figure <fig-boot>`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e54e831d",
   "metadata": {},
   "source": [
    "Here's a table:\n",
    "\n",
    "````md\n",
    "```{glue:figure} df_tbl\n",
    ":figwidth: 300px\n",
    ":name: \"tbl:df\"\n",
    "\n",
    "A caption for a pandas table.\n",
    "```\n",
    "\n",
    "````\n",
    "```{glue:figure} df_tbl\n",
    ":figwidth: 300px\n",
    ":name: \"tbl:df\"\n",
    "\n",
    "A caption for a pandas table.\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0ff72df7",
   "metadata": {},
   "source": [
    "### The `glue:math` directive\n",
    "\n",
    "The `glue:math` directive, is specific to latex math outputs\n",
    "(glued variables that contain a `text/latex` mimetype),\n",
    "and works similarly to the [sphinx math directive](https://www.sphinx-doc.org/en/1.8/usage/restructuredtext/directives.html#math).\n",
    "\n",
    ":::{table} `glue:math` directive options\n",
    "| Option | Type | Description |\n",
    "| ------ | ---- | ----------- |\n",
    "| nowrap | flag | Prevent any wrapping of the given math in a math environment |\n",
    "| class | text | A space-separated list of class names |\n",
    "| label or name | text | referenceable label for the figure |\n",
    ":::"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8e6e9b03",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left(\\sqrt{5} i\\right)^{\\alpha} \\left(\\frac{1}{2} - \\frac{2 \\sqrt{5} i}{5}\\right) + \\left(- \\sqrt{5} i\\right)^{\\alpha} \\left(\\frac{1}{2} + \\frac{2 \\sqrt{5} i}{5}\\right)$"
      ],
      "text/plain": [
       "(sqrt(5)*I)**\\alpha*(1/2 - 2*sqrt(5)*I/5) + (-sqrt(5)*I)**\\alpha*(1/2 + 2*sqrt(5)*I/5)"
      ]
     },
     "metadata": {
      "scrapbook": {
       "mime_prefix": "",
       "name": "sym_eq"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import sympy as sym\n",
    "f = sym.Function('f')\n",
    "y = sym.Function('y')\n",
    "n = sym.symbols(r'\\alpha')\n",
    "f = y(n)-2*y(n-1/sym.pi)-5*y(n-2)\n",
    "glue(\"sym_eq\", sym.rsolve(f,y(n),[1,4]))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1fad3b65",
   "metadata": {},
   "source": [
    "````md\n",
    "Insert the equation here:\n",
    "\n",
    "```{glue:math} sym_eq\n",
    ":label: eq-sym\n",
    "```\n",
    "\n",
    "Which we reference as Equation {eq}`eq-sym`\n",
    "````\n",
    "\n",
    "Insert the equation here:\n",
    "\n",
    "```{glue:math} sym_eq\n",
    ":label: eq-sym\n",
    "```\n",
    "\n",
    "Which we reference as Equation {eq}`eq-sym`.\n",
    "\n",
    "```{note}\n",
    "`glue:math` only works with glued variables that contain a `text/latex` output.\n",
    "```\n",
    "\n",
    "### The `glue:md` role/directive\n",
    "\n",
    "With `glue:md`, you can output `text/markdown`, that will be integrated into your page."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "28f73f32",
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import Markdown\n",
    "glue(\"inline_md\", Markdown(\n",
    "  \"inline **markdown** with a [link](glue/main), \"\n",
    "  \"and a nested glue value: {glue}`boot_mean`\"\n",
    "), display=False)\n",
    "glue(\"block_md\", Markdown(\"\"\"\n",
    "#### A heading\n",
    "\n",
    "Then some text, and anything nested.\n",
    "\n",
    "```python\n",
    "print(\"Hello world!\")\n",
    "```\n",
    "\"\"\"\n",
    "), display=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7ba0021",
   "metadata": {},
   "source": [
    "The format of the markdown can be specified as:\n",
    "\n",
    "- `commonmark` (default): Restricted to the [CommonMark specification](https://commonmark.org/).\n",
    "- `gfm`: Restricted to the [GitHub-flavored markdown](https://github.github.com/gfm/).\n",
    "  - Note, this requires the installation of the [linkify-it-py package](https://pypi.org/project/linkify-it-py)\n",
    "- `myst`: The MyST parser configuration for the the current document.\n",
    "\n",
    "For example, the following role/directive will glue inline/block MyST Markdown, as if it was part of the original document.\n",
    "\n",
    "````md\n",
    "Here is some {glue:md}`inline_md:myst`!\n",
    "\n",
    "```{glue:md} block_md\n",
    ":format: myst\n",
    "```\n",
    "````\n",
    "\n",
    "Here is some {glue:md}`inline_md:myst`!\n",
    "\n",
    "```{glue:md} block_md\n",
    ":format: myst\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "52a6abc0",
   "metadata": {},
   "source": [
    "(glue/crossdoc)=\n",
    "## Embedding outputs from other pages\n",
    "\n",
    "Certain `glue` roles and directives can be used to paste content from other notebooks,\n",
    "by specifying the (relative) path to them.\n",
    "\n",
    ":::{tip}\n",
    "Sometimes you'd like to use variables from notebooks that are not meant to be shown to users.\n",
    "In this case, you should bundle the notebook with the rest of your content pages, but include `orphan: true` in the metadata of the notebook.\n",
    ":::\n",
    "\n",
    "For example, the following example pastes glue variables from {ref}`orphaned-nb`:\n",
    "\n",
    "````markdown\n",
    "- A cross-pasted `any` role: {glue}`orphaned_nb.ipynb::var_text`\n",
    "- A cross-pasted `text` role: {glue:text}`orphaned_nb.ipynb::var_float:.2E`\n",
    "\n",
    "A cross-pasted `any` directive:\n",
    "\n",
    "```{glue} var_text\n",
    ":doc: orphaned_nb.ipynb\n",
    "```\n",
    "````\n",
    "\n",
    "- A cross-pasted `any` role: {glue}`orphaned_nb.ipynb::var_text`\n",
    "- A cross-pasted `text` role: {glue:text}`orphaned_nb.ipynb::var_float:.2E`\n",
    "\n",
    "A cross-pasted `any` directive:\n",
    "\n",
    "```{glue} var_text\n",
    ":doc: orphaned_nb.ipynb\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d4a5692f",
   "metadata": {},
   "source": [
    "## Advanced use-cases\n",
    "\n",
    "Here are a few more specific and advanced uses of the `glue` submodule.\n",
    "\n",
    "### Embedding into tables\n",
    "\n",
    "In addition to pasting blocks of outputs, or in-line with text, you can also paste directly\n",
    "into tables. This allows you to compose complex collections of structured data using outputs\n",
    "that were generated in other notebooks. For example the following table:\n",
    "\n",
    "````md\n",
    "| name                            |       plot                  | mean                      | ci                                                 |\n",
    "|:-------------------------------:|:---------------------------:|---------------------------|----------------------------------------------------|\n",
    "| histogram and raw text          | {glue}`boot_fig`           | {glue}`boot_mean`        | {glue}`boot_clo`-{glue}`boot_chi`                |\n",
    "| sorted means and formatted text | {glue}`sorted_means_fig`   | {glue:text}`boot_mean:.3f`| {glue:text}`boot_clo:.3f`-{glue:text}`boot_chi:.3f`|\n",
    "````\n",
    "\n",
    "Results in:\n",
    "\n",
    "| name                            |       plot                  | mean                      | ci                                                |\n",
    "|:-------------------------------:|:---------------------------:|---------------------------|---------------------------------------------------|\n",
    "| histogram and raw text          | {glue}`boot_fig`             | {glue}`boot_mean`          | {glue}`boot_clo`-{glue}`boot_chi`                   |\n",
    "| sorted means and formatted text | {glue}`sorted_means_fig`     | {glue:text}`boot_mean:.3f` | {glue:text}`boot_clo:.3f`-{glue:text}`boot_chi:.3f` |"
   ]
  }
 ],
 "metadata": {
  "file_format": "mystnb",
  "kernelspec": {
   "display_name": "python3",
   "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.8.6"
  },
  "source_map": [
   5,
   21,
   33,
   37,
   52,
   65,
   70,
   80,
   87,
   89,
   93,
   108,
   112,
   116,
   124,
   134,
   179,
   192,
   220,
   265,
   285,
   301,
   308,
   336,
   352,
   377,
   412
  ]
 },
 "nbformat": 4,
 "nbformat_minor": 5
}