From 740dd9af1ce3b83496f391e0fd4f4e9ae698b76e Mon Sep 17 00:00:00 2001 From: Tim Huegerich Date: Fri, 25 Oct 2024 14:19:20 -0500 Subject: [PATCH] Update Quarto inline code docs --- nbs/user_guide.ipynb | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/nbs/user_guide.ipynb b/nbs/user_guide.ipynb index 7cf79a6..a4c2d19 100644 --- a/nbs/user_guide.ipynb +++ b/nbs/user_guide.ipynb @@ -491,19 +491,32 @@ "\n", "### Inline calculations\n", "\n", - "To embed calculations [inline](https://quarto.org/docs/computations/execution-options.html#inline-code) in Markdown output, the workaround is to use Stata's `display` command to output Markdown, combined with the `*| output: asis` Quarto cell option. For example:\n", + "With nbstata v0.8+, you can use the standard Quarto syntax for [inline code](https://quarto.org/docs/computations/inline-code.html), specifying the Stata expression as '[%*fmt*] *exp*', just as you would for a Stata [`display` command](https://www.stata.com/help.cgi?display). For example:\n", "\n", - "```stata\n", - "*| output: asis\n", - "*| echo : false\n", - "qui:sysuse auto, clear\n", - "qui:regress price mpg\n", - "display \"Based on the model, when a car is *more* fuel efficient, the cost\n", - "*decreases* by \\$\" %5.2f `=abs(_b[mpg])' \".\"\n", + "````qmd\n", + "```{stata}\n", + "*| include: False\n", + "sysuse auto, clear\n", + "regress price mpg\n", "```\n", - "would ultimately result in output like this:\n", + "An *increase* of one mpg is associated with a *decrease* in price of \\$`{stata} %5.2f abs(_b[mpg])`.\n", + "````\n", + "would result in output like this:\n", + "\n", + "> An *increase* of one mpg is associated with a *decrease* in price of \\$238.89.\n", "\n", - "> Based on the model, when a car is *more* fuel efficient, the cost *decreases* by \\$238.89.\n" + "::: {.callout-warning}\n", + "Stata locals cannot be referenced within inline code like \\`x' because the tick (or \"left single quote,\" as Stata's manual calls it) conflicts with Quarto's inline code syntax. You can instead use globals or scalars to pass things to inline code.\n", + "\n", + "For example, this gives the same output as above (whereas defining 'mpg_coef' as a local would not work):\n", + "````qmd\n", + "```{stata}\n", + "*| include: False\n", + "scalar mpg_coef = string(abs(_b[mpg]), \"%5.2f\")\n", + "```\n", + "An *increase* of one mpg is associated with a *decrease* in price of \\$`{stata} mpg_coef`.\n", + "````\n", + ":::" ] } ],