<!-- DO NOT MODIFY -->
<!-- This file was autogenerated by build-docs.ts -->
<!-- Edit the docstring in index.ts and regenerate -->
<!-- rather than editing this file directly. -->
# unified-latex-util-split

## What is this?

Functions to manipulate `unified-latex` Abstract Syntax Tree (AST).

## When should I use this?

If you want break apart or join an array of nodes based on a condition. For example,
this is used to split on `&` characters in the `align` environment.

## Install

```bash
npm install @unified-latex/unified-latex-util-split
```

This package contains both esm and commonjs exports. To explicitly access the esm export,
import the `.js` file. To explicitly access the commonjs export, import the `.cjs` file.

# Functions

## `arrayJoin(array, sep)`

Joins an array of arrays with the item `sep`

```typescript
function arrayJoin<T>(array: T[][], sep: T | T[]): T[];
```

**Parameters**

| Param | Type       |
| :---- | :--------- |
| array | `T[][]`    |
| sep   | `T \| T[]` |

## `splitOnCondition(nodes, splitFunc, options)`

Split a list of nodes based on whether `splitFunc` returns `true`.
If `onlySplitOnFirstOccurrence` is set to true in the `options` object, then
there will be at most two segments returned.

```typescript
function splitOnCondition(
  nodes: Ast.Node[],
  splitFunc: (node: Ast.Node) => boolean,
  options: { onlySplitOnFirstOccurrence?: boolean }
): { segments: Ast.Node[][]; separators: Ast.Node[] };
```

**Parameters**

| Param     | Type                              |
| :-------- | :-------------------------------- |
| nodes     | `Ast.Node[]`                      |
| splitFunc | `(node: Ast.Node) => boolean`     |
| options   | <span color='gray'>Omitted</span> |

## `splitOnMacro(ast, macroName)`

Split an array of AST nodes based on a macro. An object `{segments: [], macros: []}`
is returned. The original array is reconstructed as
`segments[0] + macros[0] + segments[1] + ...`.

```typescript
function splitOnMacro(
  ast: Ast.Node[],
  macroName: string | string[]
): { segments: Ast.Node[][]; macros: Ast.Macro[] };
```

**Parameters**

| Param     | Type                 |
| :-------- | :------------------- |
| ast       | `Ast.Node[]`         |
| macroName | `string \| string[]` |

`unsplitOnMacro({
    segments,
    macros,
})`
---

Does the reverse of `splitOnMacro`

```typescript
function unsplitOnMacro({
  segments,
  macros,
}: {
  segments: Ast.Node[][];
  macros: Ast.Node[] | Ast.Node[][];
}): Ast.Node[];
```

**Parameters**

| Param                                     | Type                              |
| :---------------------------------------- | :-------------------------------- |
| {&#xA;    segments,&#xA;    macros,&#xA;} | <span color='gray'>Omitted</span> |
