@unified-latex/unified-latex-types 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,6 +24,15 @@ import the `.js` file. To explicitly access the commonjs export, import the `.cj
24
24
 
25
25
  # Types
26
26
 
27
+ ## `ArgumentParser`
28
+
29
+ ```typescript
30
+ export type ArgumentParser = (
31
+ nodes: Ast.Node[],
32
+ startPos: number
33
+ ) => { args: Ast.Argument[]; nodesRemoved: number };
34
+ ```
35
+
27
36
  ## `Ast`
28
37
 
29
38
  ```typescript
@@ -65,6 +74,12 @@ export type EnvInfo = {
65
74
  * @type {((string|null)[])}
66
75
  */
67
76
  namedArguments?: (string | null)[];
77
+ /**
78
+ * Whether the body is tikz-environment like (e.g., a `tikzpicture` or `scope`, etc.)
79
+ *
80
+ * @type {boolean}
81
+ */
82
+ tikzEnvironment?: boolean;
68
83
  };
69
84
  /**
70
85
  * Function to process the body of an environment. The return value of `processContent`
@@ -142,6 +157,12 @@ export type MacroInfo = {
142
157
  * @type {((string|null)[])}
143
158
  */
144
159
  namedArguments?: (string | null)[];
160
+ /**
161
+ * Whether the macro represents a tikz path command (e.g. `\draw (0,0) -- (1,1);`).
162
+ *
163
+ * @type {boolean}
164
+ */
165
+ tikzPathCommand?: boolean;
145
166
  };
146
167
  /**
147
168
  * The macro signature as an xparse argument specification string.
@@ -156,6 +177,22 @@ export type MacroInfo = {
156
177
  * escape token.
157
178
  */
158
179
  escapeToken?: string;
180
+ /**
181
+ * Custom argument parser. If present, function overrides the default argument
182
+ * parsing of `signature`. An array of nodes is passed as well as the position
183
+ * of the first node **after** the macro. This function is expected to _mutate_
184
+ * the input array, removing any nodes that are part of the macro's argument.
185
+ *
186
+ * This function will only be called on a macro if it has no existing `args`.
187
+ *
188
+ * Note: for stability when printing/accessing a node's arguments, this function
189
+ * should always return an argument array of the same length, regardless of
190
+ * whether optional arguments are present. For example, if this function parses
191
+ * a node with signature `o m`, it should ways return a length-two array of arguments.
192
+ * A "blank" argument (one that does not show up during printing) can be created
193
+ * with `args([], { openMark: "", closeMark: "" })`, using the `unified-latex-builder` package.
194
+ */
195
+ argumentParser?: ArgumentParser;
159
196
  };
160
197
  ```
161
198
 
@@ -1,5 +1,5 @@
1
1
  import { EnvInfo, MacroInfo } from "./info-specs";
2
- export declare type GenericAst = GenericNode | GenericNode[];
2
+ export type GenericAst = GenericNode | GenericNode[];
3
3
  export interface GenericNode {
4
4
  [x: string]: any;
5
5
  type: string;
@@ -80,7 +80,7 @@ export interface Argument extends ContentNode {
80
80
  openMark: string;
81
81
  closeMark: string;
82
82
  }
83
- export declare type Node = Root | String | Whitespace | Parbreak | Comment | Macro | Environment | VerbatimEnvironment | InlineMath | DisplayMath | Group | Verb;
84
- export declare type Ast = Node | Argument | Node[];
83
+ export type Node = Root | String | Whitespace | Parbreak | Comment | Macro | Environment | VerbatimEnvironment | InlineMath | DisplayMath | Group | Verb;
84
+ export type Ast = Node | Argument | Node[];
85
85
  export {};
86
86
  //# sourceMappingURL=ast-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ast-types.d.ts","sourceRoot":"","sources":["../../libs/ast-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAElD,oBAAY,UAAU,GAAG,WAAW,GAAG,WAAW,EAAE,CAAC;AAErD,MAAM,WAAW,WAAW;IACxB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAGD,UAAU,QAAQ;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,GAC3D,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5B,QAAQ,CAA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C;CACrB;AAED,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC5C,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,mBAAoB,SAAQ,QAAQ;IACjD,IAAI,EAAE,UAAU,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC5C,IAAI,EAAE,aAAa,CAAC;CACvB;AAED,MAAM,WAAW,KAAM,SAAQ,WAAW;IACtC,IAAI,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,UAAW,SAAQ,WAAW;IAC3C,IAAI,EAAE,YAAY,CAAC;CACtB;AAED,MAAM,WAAW,IAAK,SAAQ,QAAQ;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,QAAS,SAAQ,WAAW;IACzC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,IAAI,GACV,IAAI,GACJ,MAAM,GACN,UAAU,GACV,QAAQ,GACR,OAAO,GACP,KAAK,GACL,WAAW,GACX,mBAAmB,GACnB,UAAU,GACV,WAAW,GACX,KAAK,GACL,IAAI,CAAC;AAEX,MAAM,MAAM,GAAG,GAAG,IAAI,GAAG,QAAQ,GAAG,IAAI,EAAE,CAAC"}
@@ -1,5 +1,9 @@
1
1
  import * as Ast from "./ast-types";
2
- export declare type EnvInfo = {
2
+ export type ArgumentParser = (nodes: Ast.Node[], startPos: number) => {
3
+ args: Ast.Argument[];
4
+ nodesRemoved: number;
5
+ };
6
+ export type EnvInfo = {
3
7
  renderInfo?: {
4
8
  /**
5
9
  * Whether the body of the environment should be treated as math mode
@@ -31,6 +35,12 @@ export declare type EnvInfo = {
31
35
  * @type {((string|null)[])}
32
36
  */
33
37
  namedArguments?: (string | null)[];
38
+ /**
39
+ * Whether the body is tikz-environment like (e.g., a `tikzpicture` or `scope`, etc.)
40
+ *
41
+ * @type {boolean}
42
+ */
43
+ tikzEnvironment?: boolean;
34
44
  };
35
45
  /**
36
46
  * Function to process the body of an environment. The return value of `processContent`
@@ -45,7 +55,7 @@ export declare type EnvInfo = {
45
55
  */
46
56
  signature?: string;
47
57
  };
48
- export declare type MacroInfo = {
58
+ export type MacroInfo = {
49
59
  renderInfo?: {
50
60
  /**
51
61
  * Whether the macro's contents wraps along with the current
@@ -91,6 +101,12 @@ export declare type MacroInfo = {
91
101
  * @type {((string|null)[])}
92
102
  */
93
103
  namedArguments?: (string | null)[];
104
+ /**
105
+ * Whether the macro represents a tikz path command (e.g. `\draw (0,0) -- (1,1);`).
106
+ *
107
+ * @type {boolean}
108
+ */
109
+ tikzPathCommand?: boolean;
94
110
  };
95
111
  /**
96
112
  * The macro signature as an xparse argument specification string.
@@ -105,7 +121,23 @@ export declare type MacroInfo = {
105
121
  * escape token.
106
122
  */
107
123
  escapeToken?: string;
124
+ /**
125
+ * Custom argument parser. If present, function overrides the default argument
126
+ * parsing of `signature`. An array of nodes is passed as well as the position
127
+ * of the first node **after** the macro. This function is expected to _mutate_
128
+ * the input array, removing any nodes that are part of the macro's argument.
129
+ *
130
+ * This function will only be called on a macro if it has no existing `args`.
131
+ *
132
+ * Note: for stability when printing/accessing a node's arguments, this function
133
+ * should always return an argument array of the same length, regardless of
134
+ * whether optional arguments are present. For example, if this function parses
135
+ * a node with signature `o m`, it should ways return a length-two array of arguments.
136
+ * A "blank" argument (one that does not show up during printing) can be created
137
+ * with `args([], { openMark: "", closeMark: "" })`, using the `unified-latex-builder` package.
138
+ */
139
+ argumentParser?: ArgumentParser;
108
140
  };
109
- export declare type EnvInfoRecord = Record<string, EnvInfo>;
110
- export declare type MacroInfoRecord = Record<string, MacroInfo>;
141
+ export type EnvInfoRecord = Record<string, EnvInfo>;
142
+ export type MacroInfoRecord = Record<string, MacroInfo>;
111
143
  //# sourceMappingURL=info-specs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"info-specs.d.ts","sourceRoot":"","sources":["../../libs/info-specs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAEnC,oBAAY,OAAO,GAAG;IAClB,UAAU,CAAC,EAAE;QACT;;;;WAIG;QACH,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB;;;;;WAKG;QACH,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB;;;;WAIG;QACH,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB;;;;;;;;;WASG;QACH,cAAc,CAAC,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;KACtC,CAAC;IACF;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,IAAI,EAAE,CAAC;IACjD;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,oBAAY,SAAS,GAAG;IACpB,UAAU,CAAC,EAAE;QACT;;;;;WAKG;QACH,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB;;;;WAIG;QACH,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB;;;;;WAKG;QACH,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB;;;;WAIG;QACH,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB;;;;;WAKG;QACH,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB;;;;;;;;;WASG;QACH,cAAc,CAAC,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;KACtC,CAAC;IACF;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;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,OAAO,CAAC;QACtB;;;;WAIG;QACH,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB;;;;;WAKG;QACH,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB;;;;;;;;;WASG;QACH,cAAc,CAAC,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;QACnC;;;;WAIG;QACH,eAAe,CAAC,EAAE,OAAO,CAAC;KAC7B,CAAC;IACF;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;;;;;;;;OAcG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACpD,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unified-latex/unified-latex-types",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "type definitions for unified-latex",
5
5
  "main": "index.js",
6
6
  "type": "module",