Skip to content

Commit 79ee49b

Browse files
committed
doc: clarified dict shorthand
1 parent e92f4c6 commit 79ee49b

File tree

6 files changed

+212
-81
lines changed

6 files changed

+212
-81
lines changed

.github/copilot-instructions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ This guide provides essential knowledge for AI coding agents to be productive in
5353

5454
## Style Guide
5555

56+
Follow the STYLE_GUIDE.md for documentation style.
57+
5658
### Style guide for Tutorial pages
5759

5860
Tutorial pages are also called "guides".

STYLE_GUIDE.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Documentation Style Guide
2+
3+
This guide ensures that all documentation for the MathLive and Compute Engine libraries remains consistent, clear, and helpful for its target audience of developers, educators, and scientists.
4+
5+
### Tone and Voice
6+
7+
The voice of the documentation should be **professional, yet approachable and encouraging**. It should feel like a knowledgeable colleague guiding the reader through the library.
8+
9+
* **Be Direct and Clear:** Use simple sentence structures and clear language. Avoid jargon where possible, but when technical terms are necessary (e.g., "boxed expression," "lexical scope"), define them or link to their definitions.
10+
* **Use an Inclusive Point of View:**
11+
* Address the reader directly using the second person ("you"). Example: "You can customize the mathfield..."
12+
* Use the first-person plural ("we'll") for tutorials and step-by-step guides to create a collaborative feel. Example: "In this tutorial, we'll create a web-based quiz."
13+
* **Be Action-Oriented:** Use imperative verbs for instructions. Start sentences with "To do X, use Y..." to make steps clear and actionable.
14+
15+
### Formatting and Structure
16+
17+
Consistency in formatting makes the documentation easier to navigate and read.
18+
19+
#### Page Structure
20+
* **`<Intro>`:** Every major guide or reference page should begin with an `<Intro>` block. This block provides a concise, high-level summary of the page's content, setting the context for the reader.
21+
* **`<ReadMore>`:** Use this component to link to related topics. This keeps the current page focused while providing pathways for readers who want to dive deeper into a specific area.
22+
* **Example**: ` <ReadMore path="/compute-engine/guides/simplify/">Read more about **Simplifying Expressions**<Icon name="chevron-right-bold" /></ReadMore>`
23+
24+
#### Headings
25+
Use Markdown headings (`#`, `##`, etc.) to create a clear hierarchical structure. Page titles are automatically generated; start with `##` for the main sections within a page.
26+
27+
#### Emphasis
28+
* **Bold (`**text**`)**: Use for:
29+
* Key terms on their first introduction (e.g., **symbolic structure**, **fill-in-the-blank**).
30+
* UI element labels (e.g., **Copy**, **Undo**).
31+
* Important notes or warnings within a sentence.
32+
* **Code (`<code>text</code>`)**: Use for:
33+
* HTML tags: `<math-field>`
34+
* File names and paths: `/compute-engine/guides/security/`
35+
* Property and method names: `mf.value`, `.simplify()`
36+
* Attribute names: `read-only`
37+
* LaTeX commands in prose: `\placeholder[]{}`
38+
* **Keyboard Keys (`<kbd>key</kbd>`)**: Use for all keyboard key references. Example: <kbd>ALT/OPTION</kbd>+<kbd>SPACE</kbd>.
39+
40+
#### Code Blocks
41+
* **Interactive Demos (`live`)**: Use for live, editable examples that showcase the functionality directly on the page.
42+
````
43+
```live
44+
:::html
45+
<math-field>f(x) = \sin(x+\pi)</math-field>
46+
```
47+
````
48+
* **Static Examples (`js example`, `json example`, etc.)**: Use for non-interactive code snippets that illustrate a concept or API usage.
49+
````
50+
```js example
51+
mf.menuItems = mf.menuItems.filter(item => !item.id.startWith('ce-'));
52+
```
53+
````
54+
* **Line Highlighting**: Use `mark-html-line` or `mark-js-line` to draw attention to specific lines in a code block.
55+
````
56+
```live show-line-numbers mark-line=4
57+
````
58+
59+
#### Alerts and Callouts
60+
Use callouts to highlight important information.
61+
* `:::info[Note]`: For supplementary information, tips, or non-critical notes.
62+
* `:::warning[Caution]`: For important information that, if ignored, could lead to unexpected behavior, errors, or a poor user experience (e.g., deprecated features, browser quirks).
63+
* `:::caution`: For high-risk actions or configurations, especially those with security implications (e.g., modifying Content Security Policy).
64+
65+
#### Tables
66+
Use Markdown tables for structured data. For API references and lists of options, use the `symbols-table` class for consistent styling.
67+
68+
```html
69+
<div class="symbols-table first-column-header">
70+
| CSS Variable | Usage |
71+
|:---|:---|
72+
| `--caret-color` | Color of the insertion point |
73+
</div>
74+
```
75+
76+
#### API Reference Components
77+
When documenting functions and their signatures, use the provided custom components for consistency.
78+
* **`<FunctionDefinition>`**: Wraps the entire documentation for a function.
79+
* **`<Signature>`**: Details a specific function signature, including parameters and return type.
80+
* **`<Latex>`**: Shows a rendered LaTeX example.

TODO.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
## Suggestions for Improvement
3+
4+
The existing documentation is well-structured and comprehensive. The following suggestions aim to enhance its consistency and clarity further.
5+
6+
#### 1. Standardize Reference Page Structure
7+
The `combinatorics` and `number-theory` reference pages are excellent models. They provide a clear, concise summary for each function before showing the signature and code examples.
8+
* **Suggestion:** Adopt this "summary-first" structure for all API reference pages (e.g., `arithmetic`, `collections`). A short, descriptive paragraph explaining what a function like `Sum` or `Product` does and its real-world use case would be very helpful before diving into its signatures.
9+
10+
#### 2. Clarify Distinction Between Callouts
11+
The usage of `:::warning` and `:::caution` is sometimes interchangeable.
12+
* **Suggestion:** Formalize their use cases as defined in the style guide above:
13+
* `warning`: For potential errors, unexpected behavior, or things that might not work as a developer expects (e.g., the `file://` protocol limitations).
14+
* `caution`: Reserve this for higher-stakes issues, especially those related to security (like CSP and Trusted Types) or irreversible actions.
15+
16+
#### 3. Enhance Inter-linking
17+
The use of `<ReadMore>` is effective, but there are opportunities for more granular, in-context linking.
18+
* **Suggestion:** Whenever a technical term from another page is mentioned (e.g., "canonical form," "boxed expression," "MathJSON"), link it directly to its definition page on its first use in an article. This helps readers who may not be reading the documentation sequentially.
19+
20+
#### 4. Expand the Tutorials Section
21+
The "Simple Quiz" tutorial is a fantastic, practical example. Building more of these would significantly improve the learning curve for new users.
22+
* **Suggestion:** Add tutorials covering other common use cases:
23+
* **Building a Scientific Calculator:** A tutorial focused on using `expr.evaluate()` and `expr.N()` with a more complex, customized virtual keyboard.
24+
* **Creating a Dynamic Worksheet:** Showcase how to use `readonly` fields with multiple `\placeholder` prompts and dynamically update the content.
25+
* **Advanced Symbolic Manipulation:** A guide on using `expr.subs()` and `expr.replace()` to build a simple equation solver or expression transformer.
26+
27+
#### 5. Be Explicit About "Mathfield" vs. "MathfieldElement"
28+
The documentation sometimes uses `mathfield` and `MathfieldElement` interchangeably. While context often makes it clear, being explicit can prevent confusion.
29+
* **Suggestion:**
30+
* Use `<math-field>` when referring to the HTML tag.
31+
* Use `MathfieldElement` when referring to the JavaScript class or its static properties/methods (`MathfieldElement.computeEngine`).
32+
* Use "mathfield" (lowercase) as a general term for an instance of the component on a page.
33+
34+

docs/compute-engine/01-introduction.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ the UMD version will make use of polyfills as necessary.
120120

121121
```html
122122
<script
123-
src="https://cdn.jsdelivr.net/npm/@cortex-js/compute-engine/compute-engine.min.js">
123+
src="https://cdn.jsdelivr.net/npm/@cortex-js/compute-engine/compute-engine.min.umd.js">
124124
</script>
125125
<script>
126126
window.onload = function() {
@@ -137,14 +137,13 @@ Alternatively, use the **unpkg** CDN to load the library:
137137
<script src="//unpkg.com/@cortex-js/compute-engine"></script>
138138
```
139139

140-
The UMD version is also available in the npm package in `/compute-engine.min.js`
140+
The UMD version is also available in the npm package in `/compute-engine.min.umd.js`
141141

142142

143143

144144
### Other Versions
145145

146-
A non-minified module which may be useful for debugging is available in
147-
the npm package as `/compute-engine.esm.js`.
146+
A non-minified module which may be useful for debugging is available as `/compute-engine.esm.js`.
148147

149148
## MathJSON Standard Library
150149

docs/compute-engine/50-math-json.md

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ mathematical notations, and as such is not a replacement for LaTeX or MathML.
122122
## Structure of a MathJSON Expression
123123

124124
A MathJSON expression is a combination of **numbers**, **symbols**, **strings**,
125-
**functions** and **dictionaries**.
125+
**functions**.
126126

127127

128128
**Number**
@@ -158,13 +158,6 @@ A MathJSON expression is a combination of **numbers**, **symbols**, **strings**,
158158
{"fn": ["Add", {"num": "1"}, {"sym": "x"}]}
159159
```
160160

161-
**Dictionary**
162-
163-
```json example
164-
{"dict": {"x": 2, "y": 3}}
165-
["Dictionary", ["Tuple", "'x'", 2], ["Tuple", "'y'", 3]]
166-
```
167-
168161
**Numbers**, **symbols**, **strings** and **functions** are expressed either as
169162
object literals with a `"num"` `"str"` `"sym"` or `"fn"` key, respectively, or
170163
using a shorthand notation as a a JSON number, string or array.
@@ -431,23 +424,6 @@ The expression corresponding to $ \sin^{-1}(x) $ is:
431424
The operator of this expression is `"Apply"` and its argument are the expressions
432425
`["InverseFunction", "Sin"]` and `"x"`.
433426

434-
### Shorthands
435-
436-
The following shorthands are allowed:
437-
438-
- A `["Dictionary"]` expression may be represented as a string starting with
439-
**U+007B `{` LEFT CURLY BRACKET** and ending with **U+007D `}` RIGHT CURLY BRACKET**. The string must be a valid JSON object literal.
440-
- A `["List"]` expression may be represented as a string starting with
441-
**U+005B `[` LEFT SQUARE BRACKET** and ending with
442-
**U+005D `]` RIGHT SQUARE BRACKET**. The string must be a valid JSON array.
443-
444-
```json example
445-
"{\"x\": 2, \"y\": 3}"
446-
// ➔ ["Dictionary", ["Tuple", "x", 2], ["Tuple", "y", 3]]
447-
448-
"[1, 2, 3]"
449-
// ➔ ["List", 1, 2, 3]
450-
```
451427

452428
## Symbols
453429

@@ -769,49 +745,66 @@ Modifiers include:
769745

770746
## Dictionaries
771747

772-
MathJSON supports the concept of **dictionaries**, which are collections of
773-
key-value pairs.
774-
775-
Dictionaries can be represented as a `["Dictionary"]` expression, with
776-
its arguments being tuples of key-value pairs.
748+
**Dictionaries** are collections of key-value pairs. They are represented as a
749+
`["Dictionary", ["Tuple", key, value], ...]` expression.
777750

778751
```json example
779752
["Dictionary",
780-
["Tuple", "'x'", 120],
781-
["Tuple", "'y'", 36]
753+
["Tuple", {str: "x"}, 120],
754+
["Tuple", {str: "y"}, 36]
782755
]
783756
```
784757

758+
The keys of a dictionary are Unicode strings. They are compared using the
759+
[Unicode Normalization Form C (NFC)](https://unicode.org/reports/tr15/).
760+
Keys must be unique within a dictionary.
761+
785762
The value of the key-value tuples can be any valid MathJSON expression, including
786-
numbers, strings, functions, lists, or other dictionaries.
763+
numbers, strings and functions.
787764

788765
For example, the following dictionary contains an expression and a list as values:
789766

790767
```json example
791768
["Dictionary",
792-
["Tuple", "'expression'", ["Add", "x", 1]],
793-
["Tuple", "'list'", ["List", 1, 2, 3]]
769+
["Tuple", {str: "expression"}, {fn: ["Add", "x", 1]}],
770+
["Tuple", {str: "list"}, [1, 2, 3]]
794771
]
795772
```
796773

774+
As a shorthand, dictionaries can be represented as a JSON object literal with a
775+
`"dict"` property. The keys are strings and the values are interpreted as
776+
follow:
797777

798-
Dictionaries can also be represented as a JSON object literal with a `"dict"` key,
799-
which is an object with string keys and values that can be any valid MathJSON
800-
expression.
778+
| Value Type | MathJSON Representation |
779+
| :------------ | :-------------------------------------------- |
780+
| boolean | `{symbol: "True"}` or `{symbol: "False"}` |
781+
| string | `{str: "value"}` |
782+
| array | `["List", ...]` |
783+
| `{sym: }` | `{sym: "name"}` |
784+
| `{fn: }` | `{fn: "name", args: [...]}` |
801785

786+
The values are *not* interpreted as a MathJSON expression, but as a JSON value,
787+
which is then transformed into a MathJSON expression.
802788

803-
```js
789+
```json
804790
{
805791
"dict": {
806-
"expression": ["Add", "x", 1] ,
807-
"list": ["List", 1, 2, 3]
792+
"title": "My Dictionary",
793+
"enabled": true,
794+
"list": [1, 2, 3]
808795
}
809796
}
810797
```
811798

812-
The keys of a dictionary are Unicode strings. They are compared using the
813-
[Unicode Normalization Form C (NFC)](https://unicode.org/reports/tr15/).
814-
Keys must be unique within a dictionary.
799+
which is interpreted as:
800+
801+
```json example
802+
["Dictionary",
803+
["Tuple", {sym: "title"}, {str: "My Dictionary"}],
804+
["Tuple", {sym: "enabled"}, {sym: "True"}],
805+
["Tuple", {sym: "list"}, ["List", 1, 2, 3]]
806+
]
807+
```
815808

816809

817810
## Metadata

0 commit comments

Comments
 (0)